1. 程式人生 > >Linux搭建流媒體技術

Linux搭建流媒體技術

1. 確定JDK的版本:

rpm -qa | grep jdk

rpm -qa | grep gcj

可能的結果是:

libgcj-4.1.2-42.el5 

java-1.4.2-gcj-compat-1.4.2.0-40jpp.115 

2.然後解除安裝:

 yum -y remove java-1.4.2-gcj-compat-1.4.2.0-40jpp.115

如果這中方法不行,可以使用如下的方法解除安裝:

1)解除安裝系統自帶的jdk版本: 

   檢視自帶的jdk: 

   #rpm -qa|grep gcj 

   可能看到如下類似的資訊: 

   libgcj-4.1.2-44.el5 

   java-1.4.2-gcj-compat-1.4.2.0-40jpp.115 

   使用rpm -e --nodeps 命令刪除上面查詢的內容: 

   #rpm -e –nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115 

2)解除安裝rpm安裝的jkd版本 

   檢視安裝的jdk: 

   #rpm -qa|grep jdk 

   可能看到如下類似的資訊: 

   jdk-1.6.0_22-fcs 

   解除安裝: 

   #rpm -e --nodeps jdk-1.6.0_22-fcs   

3)找到jdk安裝目錄的_uninst子目錄

·在shell終端執行命令./uninstall.sh即可解除安裝jdk

一、安裝

0、安裝java

yum install java-1.7.0-openjdk

1、下載

選擇red5-server-1.0.6-RELEASE-server.tar.gz,解壓到 /usr/local/red5

2、設定為可執行

  1. cd /usr/local/red5
  2. chmod +x *.sh

3、安裝

./red5.sh

4、編輯配置檔案

找到:/usr/local/red5/conf/red5.properties

編輯內容:修改IP地址和埠號

# Socket policy

policy.host=192.168.1.32

policy.port=8085

# HTTP

http.host=192.168.1.32

http.port=8080

https.port=5443

http.URIEncoding=UTF-8

http.max_keep_alive_requests=-1

http.max_threads=20

http.acceptor_thread_count=10

http.processor_cache=20

# RTMP

rtmp.host=192.168.1.32

rtmp.port=8081

rtmp.io_threads=16

rtmp.send_buffer_size=65536

rtmp.receive_buffer_size=65536

rtmp.ping_interval=1000

rtmp.max_inactivity=60000

rtmp.max_handshake_time=5000

rtmp.tcp_nodelay=true

rtmp.tcp_keepalive=false

rtmp.default_server_bandwidth=10000000

rtmp.default_client_bandwidth=10000000

rtmp.client_bandwidth_limit_type=2

rtmp.bandwidth_detection=false

rtmp.encoder_base_tolerance=5000

rtmp.encoder_drop_live_future=false

# traffic optimization hinting. to disable set traffic class set to -1

# low delay + high throughput == 24 (0x18)

rtmp.traffic_class=-1

# requested maximum length of the queue of incoming connections

rtmp.backlog=32

# the interval (seconds) between each throughput calculation

rtmp.thoughput_calc_interval=15

# enable use of the default mina acceptor

rtmp.default_acceptor=true

# socket i/o pool sizes used when default acceptor is disabled

rtmp.initial_pool_size=0

rtmp.max_pool_size=2

rtmp.max_processor_pool_size=16

rtmp.executor_keepalive_time=60000

mina.logfilter.enable=false

# scheduler configs (per application)

rtmp.scheduler.pool_size=16

# message executor configs (per application)

# adjust this as needed if you get tasks rejected

rtmp.executor.core_pool_size=4

rtmp.executor.max_pool_size=32

rtmp.executor.queue_capacity=64

# drop audio packets when queue is almost full, to disable this, set to 0

rtmp.executor.queue_size_to_drop_audio_packets=60

# deadlock guard configs

rtmp.deadlockguard.sheduler.pool_size=32

# maximum amount of time allotted to process a single rtmp message / packet in milliseconds, set it as 0 to disable timeout (default 1000)

rtmp.deadlockguard.max_handling_time=1000

# RTMPS

rtmps.host=192.168.1.32

rtmps.port=8082

rtmps.ping_interval=5000

rtmps.max_inactivity=60000

rtmps.max_keep_alive_requests=-1

rtmps.max_threads=20

rtmps.acceptor_thread_count=2

rtmps.processor_cache=20

# RTMPS Key and Trust store parameters

rtmps.keystorepass=password

rtmps.keystorefile=conf/keystore.jks

rtmps.truststorepass=password

rtmps.truststorefile=conf/truststore.jks

# RTMPT

rtmpt.host=192.168.1.32

rtmpt.port=8083

rtmpt.ping_interval=5000

rtmpt.max_inactivity=60000

rtmpt.max_handshake_time=5000

rtmpt.max_keep_alive_requests=-1

rtmpt.max_threads=20

rtmpt.acceptor_thread_count=2

rtmpt.processor_cache=20

rtmpt.encoder_base_tolerance=5000

rtmpt.encoder_drop_live_future=true

# better setting for streaming media

rtmpt.target_reponse_size=32768

# best setting for small messages or shared objects

#rtmpt.target_reponse_size=8192

# max incoming messages to process at a time. the most that FP appears to send is 166

rtmpt.max_in_msg_process=166

# max time in millis that we will wait when offering data to the in or out queue

rtmpt.max_queue_offer_time=125

# max offer attempts

rtmpt.max_queue_offer_attempts=4

# WebSocket

ws.host=192.168.1.32

ws.port=8084

# Debug proxy (needs to be activated in red5-core.xml)

proxy.source_host=127.0.0.1

proxy.source_port=1936

proxy.destination_host=127.0.0.1

proxy.destination_port=1935

# JMX

jmx.rmi.host=localhost

jmx.rmi.port=8085

jmx.rmi.sport=8086

jmx.rmi.port.remoteobjects=

jmx.keystorepass=password

jmx.mina.monitor.enable=false

jmx.mina.poll.interval=1000

jmx.registry.create=true

jmx.reuse.existing.server=true

# Server properties

# max events to send in a single update

so.max.events.per.update=64

so.scheduler.pool_size=4

keyframe.cache.entry.max=500

war.deploy.server.check.interval=600000

fileconsumer.delayed.write=true

fileconsumer.queue.size=120

subscriberstream.buffer.check.interval=5000

subscriberstream.underrun.trigger=100

broadcaststream.auto.record=false

找到/usr/local/red5/webapps/live/WEB-INF/red5-web.properties檔案,增加IP地址。

如:

webapp.contextPath=/live

webapp.virtualHosts=192.168.1.160

二、新增服務啟動項

1、編輯啟動指令碼

vi /etc/init.d/red5

  1. #!/bin/bash
  2. # For RedHat and cousins:
  3. # chkconfig: 2345 85 85
  4. # description: Red5 flash streaming server
  5. # processname: red5
  6. # Created By: Sohail Riaz ([email protected])
  7. PROG=red5
  8. RED5_HOME=/usr/local/red5
  9. DAEMON=$RED5_HOME/$PROG.sh
  10. PIDFILE=/var/run/$PROG.pid
  11. # Source function library
  12. . /etc/rc.d/init.d/functions
  13. [ -r /etc/sysconfig/red5 ] && . /etc/sysconfig/red5
  14. RETVAL=0
  15. case "$1" in
  16. start)
  17. echo -n $"Starting $PROG: "
  18. cd $RED5_HOME
  19. $DAEMON >/dev/null 2>/dev/null &
  20. RETVAL=$?
  21. if [ $RETVAL -eq 0 ]; then
  22. echo $! > $PIDFILE
  23. touch /var/lock/subsys/$PROG
  24. fi
  25. [ $RETVAL -eq 0 ] && success $"$PROG startup" || failure $"$PROG startup"
  26. echo
  27. ;;
  28. stop)
  29. echo -n $"Shutting down $PROG: "
  30. killproc -p $PIDFILE
  31. RETVAL=$?
  32. echo
  33. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$PROG
  34. ;;
  35. restart)
  36. $0 stop
  37. $0 start
  38. ;;
  39. status)
  40. status $PROG -p $PIDFILE
  41. RETVAL=$?
  42. ;;
  43. *)
  44. echo $"Usage: $0 {start|stop|restart|status}"
  45. RETVAL=1
  46. esac
  47. exit $RETVAL

2.將啟動指令碼新增到服務

  1. chmod +x /etc/rc.d/init.d/red5
  2. chkconfig --add red5
  3. chkconfig red5 on

3.設定CentOS防火牆

開啟5080、1935等埠

4.啟動red5

/etc/init.d/red5 start

5.測試Red5

在瀏覽器中訪問 http://yourip:5080

這裡我們訪問Red5自帶的幾個demo來測試Red5是否好用

Red5 多媒體服務佔用埠 5080,RTMP 佔用埠 1935,如果不能訪問,請檢查防火牆是否允許這兩個埠。

6.直播地址

rtmp://yourip/live/流地址

在配置檔案中按內網ip設定,在頁面檔案中按公網ip設定或相對路徑設定即可