基于OpenBSD的流媒体服务器icecast2.3.2

在OpenBSD环境下搭建各种服务器的相关讨论。

版主: lionuxchenjun天地乾坤

回复
头像
leo
帖子: 2465
注册时间: 2010-01-21 3:27

基于OpenBSD的流媒体服务器icecast2.3.2

帖子 leo » 2010-01-21 12:51

先简单说一下我的安装环境,i386平台,OpenBSD 4.6稳定版,什么也没有安装。

代码: 全选

# [color=darkorange]pkg_info[/color]
#
# [color=darkorange]export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.6/packaegs/i386/[/color]
# [color=darkorange]pkg_add icecast[/color]
libogg-1.1.3: complete
libvorbis-1.2.0p1: complete
speex-1.2rc1: complete
libiconv-1.13: complete
gettext-0.17p0: complete
libtheora-1.0: complete
curl-7.19.5:libidn-1.11: complete
curl-7.19.5: complete
libxslt-1.1.24p2:bzip2-1.0.5: complete
libxslt-1.1.24p2:sqlite3-3.6.13p0: complete
libxslt-1.1.24p2:python-2.5.4p1: complete
libxslt-1.1.24p2:libgpg-error-1.5p0: complete
libxslt-1.1.24p2:libgcrypt-1.4.4p0: complete
libxslt-1.1.24p2:libxml-2.6.32p2: complete
libxslt-1.1.24p2: complete
icecast-2.3.2: complete
--- icecast-2.3.2 -------------------
Please see /usr/local/share/doc/icecast/README.OpenBSD for
a brief intro to using icecast on OpenBSD.
--- python-2.5.4p1 -------------------
If you want to use this package as your default system python, as root
create symbolic links like so (overwriting any previous default):
ln -sf /usr/local/bin/python2.5 /usr/local/bin/python
ln -sf /usr/local/bin/python2.5-config /usr/local/bin/python-config
ln -sf /usr/local/bin/pydoc2.5 /usr/local/bin/pydoc
#
安装的东西不少,我们先看说明文件中的一些提示

代码: 全选

$OpenBSD: README.OpenBSD,v 1.4 2008/11/18 21:22:02 pea Exp $
Icecast v2 is very versatile and can be used in many different
envionrments. A streaming service provider has different requirements
than someone who wants to set up a jukebox at home.
To get a better understanding of streaming with Icecast,
[URL]http://liveice.sourceforge.net/understanding.html[/URL] may be of use.
This is a small step-by-step guide to get Icecast v2 running in a basic
setup, using its chrooting feature, dropping privileges to an
unprivileged account.
1. Complete the chroot environment with additional system files.
While this is optional, it allows YP directory listings (DNS
lookups are required for those) to work and the log files to
contain correct timestamps.
# cp -p /etc/{hosts,localtime,resolv.conf} /var/icecast/etc
2. Adjust /var/icecast/icecast.xml. Consult the documentation and
comments about the various options.
* CHANGE THE DEFAULT PASSWORDS FOR SOURCE CLIENTS, RELAYS AND
THE ADMIN INTERFACE.
Mode 600 is highly recommended, for icecast.xml contains plain-text
passwords.
3. Start Icecast and monitor the logs in /var/icecast/log and resolve
any errors.
# icecast -c /var/icecast/icecast.xml
Add the command line parameter `-b' to daemonize.
4. Test your server. Use a source client to create a stream and
listen to it with your favorite player that supports streaming.
Also test Icecast's web interface. Be aware that Icecast sends
everything located in <webroot> to those who request it like a
regular (basic) web server. You can restrict this behavior to
serve only .xsl files by setting <fileserve> to 0 in your
icecast.xml; however, you should definitely take a closer look at
what you actually want to show the world here. There is no reason
for paranoia, it's all safe, but you should spend some time
thinking about it. Note that disabling <fileserve> will also
prevent CSS stylesheets and images from being sent, making the web
interface less pleasant to look at.
5. Add the following to your /etc/rc.local:
if [ -x /usr/local/bin/icecast ] ; then
echo -n ' icecast'
/usr/local/bin/icecast -b -c /var/icecast/icecast.xml
fi
Random hints:
* Remember to give your mountpoint a proper name -- MP3 streams
should use no extension, Ogg Vorbis streams should use .ogg, so
that dumb or broken players can send the stream to the appropriate
decoder.
* The default "bind to any address" only opens an IPv6 socket. 
Specify a specific address or use 0.0.0.0 to accept any IPv4 address.
说明文件里讲的很详细了,我们参照说明文件一步一步执行:
1. 准备chroot环境
因为icecast是对外服务的,所以需要将其与其它系统文件分离,实现完全的chroot。
运行如下命令,将/etc下的hosts,localtime,resolv.conf 复制到 /var/icecast/etc:

代码: 全选

# cp -p /etc/{hosts,localtime,resolv.conf} /var/icecast/etc
2.设置 /var/icecast/icecast.xml 文件,参考它的提示信息以配置各种参数,为了方便读者阅读,我们把文件列在下面:

代码: 全选

<icecast>
<limits>
<clients>100</clients>
<sources>2</sources>
<threadpool>5</threadpool>
<queue-size>524288</queue-size>
<client-timeout>30</client-timeout>
<header-timeout>15</header-timeout>
<source-timeout>10</source-timeout>
<!-- If enabled, this will provide a burst of data when a client 
first connects, thereby significantly reducing the startup 
time for listeners that do substantial buffering. However,
it also significantly increases latency between the source
client and listening client. For low-latency setups, you
might want to disable this. -->
<burst-on-connect>1</burst-on-connect>
<!-- same as burst-on-connect, but this allows for being more
specific on how much to burst. Most people won't need to
change from the default 64k. Applies to all mountpoints -->
<burst-size>65535</burst-size>
</limits>
<authentication>
<!-- Sources log in with username 'source' -->
<source-password>9971</source-password> [color=darkorange]这里是source的密码,请将这里的原密码hackme改为自己的密码,我们在这里改为9971[/color]
<!-- Relays log in username 'relay' -->
<relay-password>9971</relay-password> [color=darkorange]这里是relay的密码,请将这里的原密码hackme改为自己的密码,我们在这里改为9971[/color] 
<!-- Admin logs in with the username given below -->
<admin-user>admin</admin-user> 
<admin-password>9971us</admin-password> [color=darkorange]这里是admin用户的密码,请将这里的原密码hackme改为自己的密码,我们在这里改为9971us[/color]
</authentication>
<!-- set the mountpoint for a shoutcast source to use, the default if not
specified is /stream but you can change it here if an alternative is
wanted or an extension is required
<shoutcast-mount>/9971</shoutcast-mount> [color=darkorange]为shoutcast设置的挂载点我们这里改为9971,注意不改则默认是/stream,但是与后面安装的ices的不一致,所以这里要改,我们改成9971。[/color]
-->
<!-- Uncomment this if you want directory listings --> 
<!--
<directory>
<yp-url-timeout>15</yp-url-timeout>
<yp-url>http://dir.xiph.org/cgi-bin/yp-cgi</yp-url>
</directory>
-->
<!-- This is the hostname other people will use to connect to your server.
It affects mainly the urls generated by Icecast for playlists and yp
listings. -->
<hostname>localhost</hostname> [color=darkorange]你可以在这里设置你的域名[/color]
<!-- You may have multiple <listener> elements -->
<listen-socket>
<port>8000</port>
<bind-address>0.0.0.0</bind-address> [color=darkorange]这里改成0.0.0.0才能接受IPV4地址[/color]
<shoutcast-mount>/9971</shoutcast-mount> [color=darkorange]这要改成/9971[/color]
</listen-socket>
<!--
<listen-socket>
<port>8001</port>
</listen-socket>
-->
<!--<master-server>127.0.0.1</master-server>--> [color=darkorange]这个就不改成0.0.0.0了,我们还是通过OpenSSH在本地维护吧[/color]
<!--<master-server-port>8001</master-server-port>-->
<!--<master-update-interval>120</master-update-interval>-->
<!--<master-password>hackme</master-password>-->
<!-- setting this makes all relays on-demand unless overridden, this is
useful for master relays which do not have <relay> definitions here.
The default is 0 -->
<!--<relays-on-demand>1</relays-on-demand>-->
<!--
<relay>
<server>0.0.0.0</server> [color=darkorange]此处也改为0.0.0.0接受IPV4地址[/color]
<port>8001</port>
<mount>/example.ogg</mount>
<local-mount>/different.ogg</local-mount>
<on-demand>0</on-demand>
<relay-shoutcast-metadata>0</relay-shoutcast-metadata>
</relay>
-->
<!-- Only define a <mount> section if you want to use advanced options,
like alternative usernames or passwords
<mount>
<mount-name>/example-complex.ogg</mount-name>
<username>othersource</username>
<password>hackmemore</password>
<max-listeners>1</max-listeners>
<dump-file>/tmp/dump-example1.ogg</dump-file>
<burst-size>65536</burst-size>
<fallback-mount>/example2.ogg</fallback-mount>
<fallback-override>1</fallback-override>
<fallback-when-full>1</fallback-when-full>
<intro>/example_intro.ogg</intro>
<hidden>1</hidden>
<no-yp>1</no-yp>
<authentication type="htpasswd">
<option name="filename" value="myauth"/>
<option name="allow_duplicate_users" value="0"/>
</authentication>
<on-connect>/home/icecast/bin/stream-start</on-connect>
<on-disconnect>/home/icecast/bin/stream-stop</on-disconnect>
</mount>
<mount>
<mount-name>/auth_example.ogg</mount-name>
<authentication type="url">
<option name="mount_add" value="[url=http://myauthserver.net/notify_mount.php%22/]http://myauthserver.net/notify_mount.php"/[/URL]>
<option name="mount_remove" value="[url=http://myauthserver.net/notify_mount.php%22/]http://myauthserver.net/notify_mount.php"/[/URL]>
<option name="listener_add" value="[url=http://myauthserver.net/notify_listener.php%22/]http://myauthserver.net/notify_listener.php"/[/URL]>
<option name="listener_remove" value="[url=http://myauthserver.net/notify_listener.php%22/]http://myauthserver.net/notify_listener.php"/[/URL]>
</authentication>
</mount>
-->
<fileserve>1</fileserve>
<paths>
<!-- basedir is only used if chroot is enabled -->
<basedir>/var/icecast</basedir>
<!-- Note that if <chroot> is turned on below, these paths must both
be relative to the new root, not the original root -->
<logdir>/log</logdir>
<webroot>/web</webroot>
<adminroot>/admin</adminroot>
<!-- <pidfile>/var/run/icecast.pid</pidfile> -->
<!-- Aliases: treat requests for 'source' path as being for 'dest' path
May be made specific to a port or bound address using the "port"
and "bind-address" attributes.
-->
<!--
<alias source="/foo" dest="/bar"/>
-->
<!-- Aliases: can also be used for simple redirections as well,
this example will redirect all requests for [URL]http://server:port/[/URL] to
the status page
-->
<alias source="/" dest="/status.xsl"/> 这里改不改看你自己了,我没动。
</paths>
<logging>
<accesslog>access.log</accesslog>
<errorlog>error.log</errorlog>
<!-- <playlistlog>playlist.log</playlistlog> -->
<loglevel>3</loglevel> <!-- 4 Debug, 3 Info, 2 Warn, 1 Error -->
<logsize>10000</logsize> <!-- Max size of a logfile -->
<!-- If logarchive is enabled (1), then when logsize is reached
the logfile will be moved to [error|access|playlist].log.DATESTAMP,
otherwise it will be moved to [error|access|playlist].log.old.
Default is non-archive mode (i.e. overwrite)
-->
<!-- <logarchive>1</logarchive> -->
</logging>
<security>
<chroot>1</chroot> 
<changeowner>
<user>_icecast</user> [color=darkorange]这里安装时已经设置为_icecast了,如果你的是nobody,自己改过来。[/color]
<group>_icecast</group> [color=darkorange]这里安装时已经设置为_icecast了,如果你的是nobody,自己改过来。[/color]
</changeowner> 
</security>
</icecast>
根据上面README.OpenBSD文件的提示,我们还应该将icecast.xml文件的权限设置为600,我这里不用自己设置,已经是600了。

代码: 全选

-rw------- 1 _icecast _icecast 6489 Dec 19 15:41 icecast.xml
3.运行提示的命令:

代码: 全选

 
#ln -sf /usr/local/bin/python2.5 /usr/local/bin/python
#ln -sf /usr/local/bin/python2.5-config /usr/local/bin/python-config
#ln -sf /usr/local/bin/pydoc2.5 /usr/local/bin/pydoc
4.启动icecast,并关注一下日志文件 /var/icecast/log,如果有问题需要重新设置。

代码: 全选

# icecast -c /var/icecast/icecast.xml
我们看一下 /var/icecast/log文件的内容

代码: 全选

[2009-12-19 15:42:52] INFO main/main Icecast 2.3.2 server started
[2009-12-19 15:42:52] INFO connection/get_ssl_certificate No SSL capability on any configured ports
[2009-12-19 15:42:52] INFO fserve/fserv_thread_function file serving thread started
[2009-12-19 15:42:52] INFO yp/yp_update_thread YP update thread started
似乎一切正常。
如果你想后台运行,在上面的命令中加上 -b 参数。
5.安装ices

代码: 全选

# pkg_add ices-0.4p6
修改/etc/ices.conf的配置并运行:
我的内容如下:

代码: 全选

<?xml version="1.0"?>
<ices:Configuration xmlns:ices="[URL]http://www.icecast.org/projects/ices[/URL]">
<Playlist>
<!-- This is the filename used as a playlist when using the builtin 
playlist handler. -->
<File>/var/icecast/web/playlist</File>
<!-- Set this to 0 if you don't want to randomize your playlist, and to
1 if you do. -->
<Randomize>1</Randomize>
<!-- One of builtin, perl, or python. -->
<Type>builtin</Type>
<!-- Module name to pass to the playlist handler if using perl or python.
If you use the builtin playlist handler then this is ignored -->
<Module>ices</Module>
<!-- Set this to the number of seconds to crossfade between tracks.
Leave out or set to zero to disable crossfading (the default).
<Crossfade>5</Crossfade>
-->
</Playlist>
<Execution>
<!-- Set this to 1 if you want ices to launch in the background as a
daemon -->
<Background>1</Background>
<!-- Set this to 1 if you want to see more verbose output from ices -->
<Verbose>0</Verbose>
<!-- This directory specifies where ices should put the logfile, cue file
and pid file (if daemonizing). Don't use /tmp if you have l33t h4x0rz
on your server. -->
<BaseDirectory>/var/icecast/log/</BaseDirectory>
</Execution>
<Stream>
<Server>
<!-- Hostname or ip of the icecast server you want to connect to -->
<Hostname>localhost</Hostname>
<!-- Port of the same -->
<Port>8000</Port>
<!-- Encoder password on the icecast server -->
<Password>9971</Password>
<!-- Header protocol to use when communicating with the server.
Shoutcast servers need "icy", icecast 1.x needs "xaudiocast", and
icecast 2.x needs "http". -->
<Protocol>http</Protocol>
</Server>
<!-- The name of the mountpoint on the icecast server -->
<Mountpoint>/ices</Mountpoint>
<!-- The name of the dumpfile on the server for your stream. DO NOT set
this unless you know what you're doing.
<Dumpfile>ices.dump</Dumpfile>
-->
<!-- The name of you stream, not the name of the song! -->
<Name>Default stream</Name>
<!-- Genre of your stream, be it rock or pop or whatever -->
<Genre>Default genre</Genre>
<!-- Longer description of your stream -->
<Description>Default description</Description>
<!-- URL to a page describing your stream -->
<URL>http://localhost/</URL>
<!-- 0 if you don't want the icecast server to publish your stream on
the yp server, 1 if you do -->
<Public>1</Public>
<!-- Stream bitrate, used to specify bitrate if reencoding, otherwise
just used for display on YP and on the server. Try to keep it
accurate -->
<Bitrate>128</Bitrate>
<!-- If this is set to 1, and ices is compiled with liblame support,
ices will reencode the stream on the fly to the stream bitrate. -->
<Reencode>0</Reencode>
<!-- Number of channels to reencode to, 1 for mono or 2 for stereo -->
<!-- Sampe rate to reencode to in Hz. Leave out for LAME's best choice
<Samplerate>44100</Samplerate>
-->
<Channels>2</Channels>
</Stream>
</ices:Configuration>
先将几个mp3文件上传到服务器的 /var/icecast/web目录,这个是默认目录,我在上面没有改动。
然后制作播放列表:

代码: 全选

# find / -name "*.mp3" > /var/icescast/web/playlist
运行ices

代码: 全选

# ices -c /etc/ices.conf -F /var/icescast/web/playlist

6.测试服务器
在浏览器窗口输入:[url=http://%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%9c%b0%e5%9d%80:8000/%EF%BC%8C%E5%A6%82%E4%B8%8B%E5%9B%BE%E6%89%80%E7%A4%BA:]http://服务器地址:8000/,如下图所示:[/url]
图片
客户在浏览器里点击m3u按钮就可以播放Mp3了,另外你也可以在icescast.xml里设置是否为随机播放,具体参看上面的说明。
7.如果你想每次自动启用icecast
在rc.local里加入如下的内容

代码: 全选

if [ -x /usr/local/bin/icecast ] ; then
 echo -n ' icecast'
 /usr/local/bin/icecast -b -c /var/icecast/icecast.xml
fi
ices -c /etc/ices.conf -F /var/icescast/web/playlist
附录:
这是我的icecast.xml和ice.conf的源文件,需要的朋友可以下载。
附件
111.tar.gz
(3.53 KiB) 下载 945 次

头像
crzyfish
镍 Ni
帖子: 195
注册时间: 2010-02-05 20:11

帖子 crzyfish » 2010-06-13 14:39

leo~
这个好像只能支持音频?

头像
leo
帖子: 2465
注册时间: 2010-01-21 3:27

帖子 leo » 2010-06-13 15:46

crzyfish 写了:leo~
这个好像只能支持音频?
试试这个:
http://gobsd.org/showthread.php?t=138

回复

在线用户

正浏览此版面之用户: 没有注册用户 和 0 访客