개발/자바 | Posted by 은우 아빠 2008. 10. 14. 16:50

RED5


(주)웹호스트 http://www.webhost.co.kr

이 문서는 rhel4에서 테스트되었다.

1. red5란 무엇인가?

flash player 중간스트리밍이 가능하도록
리눅스서버에 설치하는 스트리밍 프로그램이다.

2. 설치과정

Installing Red5, version 0.4.1 takes 4 steps
  1. Installing the Java 1.5 JDK
  2. Installing Apache Ant.
  3. Setting the wright Path Variables
  4. Installing Red 5


First of all, you will need to be logged in as root. Were using bash as shell


Step 1. Installing the Java 1.5 JDK

jdk-1_5_0_14-linux-i586.bin

최신버전을 받는다. 리눅스용중에서 rpm자동설치버전을 받아라.

./jdk-1_5_0_14-linux-i586-rpm.bin
자동설치된다.

주의) 설치전
rpm -qa|grep jdk
rpm -qa|grep java
등 해서 모두 제거한다.

기본설치가 되면, rpm 으로 설치된다.

jdk-1.5.0_14-fcs

/usr/java/jdk1.5.0_14


#vi /etc/profile


맨 밑에

JAVA_HOME=/usr/java/jdk1.5.0_14  #자바가 설치된 위치입니다.
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=$CLASSPATH:$JAVA_HOME/lib


이런식으로 저장

#source /etc/profile

설치 끝
텔넷사용시, 로그아웃하고나서 다시로그인할 것
java -version
으로 버전확인할 것


Now let's check the Java version:

[root@hostname ~]# java -version
It should read something like this:
java version "1.5.0_14"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)

Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
OK 설치성공

That was step 1. Still here? let's go to step 2

Step 2. Installing Apache Ant.

드디어, 2장으로 돌입한다.

[root@hostname ~]# cd /usr/local/
wget wget http://archive.apache.org/dist/ant/binaries/apache-ant-1.6.2-bin.tar.gz


[root@hostname ~]# tar xvzf apache-ant-1.6.2-bin.tar.gz
rename the dir to ant
[root@hostname ~]# ln -s apache-ant-1.6.2 ant














압축풀고, 이름바꾼후에 /usr/local/ant 로 링크시킨다.

1.7.0 에 문제가 있는 것 같음. ant는 버전을 테스트해보고 설치할 것.


















ant의 문제는 ant server & 로 할경우 데먼이 올라오지만,
ant 만 실행하면 에러가 남. 1.7.x대역은 데먼이 제대로 실행안됨.
이 부분은 좀 더 연구해 봐야 할 문제













Step 3. Setting the wright Path Variables.





3장 진입


If you'll be running Red5 as root (which you shouldn't) you can add the paths to /root/.bash_profile
otherwise you can add them to /etc/profile add these two lines:

 
즉,
vi /etc/profile
한 다음,

export ANT_HOME=/usr/local/ant
export PATH=$ANT_HOME/bin:$PATH


이렇게 2줄 추가하고
저장한 후
#source /etc/profile





ant 설치 끝





 






Step 4. Installing Red5.




red5 설치하기  http://osflash.org/red5 -> wget http://dl.fancycode.com/red5/0.6.3/src/red5-0.6.3.tar.gz







download Red5




[root@hostname ~]# adduser red5

새 사용자 계정을 만든다. 예를들어 red5라고 하자. 이 아이디로는 flv동영상을 올리게 된다.
cd ~red5
[root@hostname ~]# tar zxf ~/red5/red5-0.6.3.tar.gz

이제 최신버전 다운로드한 것을 푼다.


red5-0.6.3
[root@www red5]#

[root@www red5-0.6.3]# ls
build.properties  doc            ivy.xml      Makefile        red5_debug.sh      red5-shutdown.bat  swf
build.xml         dumps          lib          red5.bat        red5-highperf.bat  red5-shutdown.sh   test
conf              ivyconfig.xml  license.txt  red5_debug.bat  red5.sh            src                webapps
[root@www red5-0.6.3]#




이제 설치하자

ant server &

이 명령으로 red5가 있는 위치를 기본으로 설치가 시작됨
약 15분간 진행됨.


/etc/rc.d/init.d/red5 스크립트 작성

#! /bin/sh
#
# Author: Jake Hilton <red5@jakehilton.com>
# /etc/init.d/red5
#
# Check for missing file
RED5_DIR=/home/red5/red5-0.6.3/
test -x $RED5_DIR/red5.sh || exit 5


case "$1" in
    start)
        echo -n "Starting Red5 Service"
        echo -n " "
        cd $RED5_DIR
        su -s /bin/bash -c "$RED5_DIR/red5.sh &" root
        sleep 2
        ;;
    stop)
        echo -n "Shutting down red5"
        echo -n " "
        su -s /bin/bash -c "killall -q -u red5 java" root
        sleep 2
        ;;
    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start
        ;;
esac

---------------------------------------------

굵은 부분은 중요하니 알아서 수정할 것



스크립트 구동

/etc/rc.d/init.d/red5 stop
/etc/rc.d/init.d/red5 start





테스트해보기


[root@www red5-0.6.3]# telnet localhost 1935
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
[WARN] 39168 mina-1:( org.red5.server.net.rtmp.RTMPMinaIoHandler.sessionOpened ) Is tcp delay enabled: false

접속성공함

^] 키보드 Ctrl+] 입력
telnet> quit
Connection closed.
[root@www red5-0.6.3]# [DEBUG] 64717 mina-4:( org.red5.server.BaseConnection.close ) Close, not connected nothing to do.


[root@www red5-0.6.3]#

[root@www red5-0.6.3]# ps -ax|grep red5
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.3/FAQ
18535 pts/0    Sl     0:01 /usr/bin/java -cp red5.jar:conf: org.red5.server.Standalone
18596 pts/0    S+     0:00 grep red5
[root@www red5-0.6.3]#

[root@www red5-0.6.3]# netstat -an|more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State     
tcp        0      0 0.0.0.0:8001                0.0.0.0:*                   LISTEN     
tcp        0      0 0.0.0.0:995                 0.0.0.0:*                   LISTEN     
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN     
tcp        0      0 0.0.0.0:110                 0.0.0.0:*                   LISTEN     
tcp        0      0 0.0.0.0:1935                0.0.0.0:*                   LISTEN     
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN     
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN     
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN     
tcp        0      0 0.0.0.0:5080                0.0.0.0:*                   LISTEN     
tcp        0      0 0.0.0.0:8088                0.0.0.0:*                   LISTEN     
tcp        0    104 116.197.138.27:22           211.187.59.252:4231         ESTABLISHED
tcp        0      0 127.0.0.1:35137             127.0.0.1:5080              FIN_WAIT2  
tcp        0      0 127.0.0.1:5080              127.0.0.1:35137             CLOSE_WAIT 



1935포트가 정상적으로 LISTEN중이다.







이제 플레이어를 설치하자.


flash_media_player.zip 첨부한 파일 참고

파일을 풀어서 서버에 올림


drwxrwxrwx  2 root root   4096 Jul 30 18:48 extras
-rwxrwxrwx  1 root root  20920 Apr  8  2005 image.jpg
-rwxr-xr-x  1 root root    754 Jan  5 04:08 mediaplayer.html
-rw-r--r--  1 root root  35041 Dec 18 06:56 mediaplayer.swf
-rwxrwxrwx  1 root root  81222 Dec 27  2006 movie.swf
-rwxrwxrwx  1 root root    343 Jan  5 04:35 playlist.xml
-rwxrwxrwx  1 root root  10055 Feb 10  2007 preview.jpg
drwxrwxrwx  2 root root   4096 Apr 18  2007 readme
-rwxrwxrwx  1 root root  47024 Aug 11  2005 song.mp3
drwxrwxrwx  3 root root   4096 Dec 18 06:58 source
-rwxrwxrwx  1 root root   6880 Mar  1  2007 swfobject.js
-rw-r--r--  1 root root    305 Jan  5 04:37 test.html
-rwxrwxrwx  1 root root 282797 Aug 11  2005 video.flv
[root@www public_html]# pwd
/home/red5/public_html
[root@www public_html]#


/home/red5/public_html 이라고 가정함.

풀어서 올린결과

이 플레이어는 rtmp://를 지원한다.

mv mediaplayer.html index.html


아파치 virtual 셋팅
<VirtualHost *:80>
    DocumentRoot /home/red5/public_html
    ServerName red5.도메인.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /home/red5/red5-0.6.3
    ServerName red5rtmp.도메인.com
</VirtualHost>


2개를 동시에 만든다.

왜냐? 해당폴더에 접근이 가능해야 하기때문이다.
아래것은 rtmp://도메인명:1935/oflaDemo/file.flv 형태로 접근하기 위한 것



vi index.html 수정

------------------------------------------
<html>
<head>



<script type="text/javascript" src="swfobject.js"></script>



</head>
<body>



<h3>single file, with preview image:</h3>



<p id="player2"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</p>
<script type="text/javascript">
        var s2 = new SWFObject("mediaplayer.swf","playlist","640","480","1");
        s2.addParam("allowfullscreen","true");
        s2.addVariable("file","playlist.xml");
        s2.addVariable("displayheight","380");
        s2.addVariable("backcolor","0x000000");
        s2.addVariable("frontcolor","0xCCCCCC");
        s2.addVariable("lightcolor","0x996600");
        s2.addVariable("width","640");
        s2.addVariable("height","480");
        s2.write("player2");
</script>




</body>
</html>
-----------------------------------------------------------



vi playlist.xml수정
------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
        <trackList>


                <track>
                        <title>FLV Test 2</title>
                        <creator>Postman</creator>
                        <location>rtmp://red5rtmp.도메인.com:1935/oflaDemo/</location>
<identifier>Transformers.flv</identifier>
<meta rel="type">rtmp</meta>
                </track>


        </trackList>
</playlist>
------------------------------------------------

여기가 중요함


[root@www streams]# ll
total 19980
-rw-r--r--  1 root root 4546420 Sep 11 14:31 IronMan.flv
-rw-r--r--  1 root root 8446642 Mar 15  2007 on2_flash8_w_audio.flv
-rw-r--r--  1 root root 7405850 May 19  2007 Transformers.flv
[root@www streams]# pwd
/home/red5/red5-0.6.3/webapps/oflaDemo/streams
[root@www streams]#


이 속에 존재하는 파일중에 연결한다.


rtmp://주소는 oflaDemo/폴더까지만 적어준다.



이제 테스트해보자

http://red5.도메인.com

했을때, 플레이가 되면 끝남





(주)웹호스트 작성 http://www.webhost.co.kr

작성 : 2008년 1월4일