Linux 上安装 Django

yum 安装方法

以下安装位于 Centos Linux 环境下安装,如果是你的 Linux 系统是 ubuntu 请使用 apt-get 命令。

默认情况下 Linux 环境已经支持了Python。你可以在终端输入Python命令来查看是否已经安装。

Python 2.7.3 (default, Aug 1 2012, 05:14:39) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 

安装 setuptools

命令:

yum install setuptools

完成之后,就可以使用 easy_install 命令安装 django

easy_install django

之后我们在python解释器输入以下代码:

[root@solar django]# python Python 2.7.3 (default, May 15 2014, 14:49:08) [GCC 4.8.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import django >>> django.VERSION (1, 6, 5, 'final', 0) >>>

我们可以看到输出了Django的版本号,说明安装成功。

pip 命令安装方法

pip install Django

如果 pip < 1.4,安装方法如下:

pip install https://www.djangoproject.com/download/1.11a1/tarball/

源码安装方法

下载源码包:https://www.djangoproject.com/download/

输入以下命令并安装:

tar xzvf Django-X.Y.tar.gz # 解压下载包 cd Django-X.Y # 进入 Django 目录 python setup.py install # 执行安装命令

安装成功后 Django 位于 Python 安装目录的 site-packages 目录下。

1.安装完CentOS 6.5系统,将默认的Python2.6升级到2.7。

2.下载setuptools工具,并解压进入目录后,使用命令:python2.7 setup.py install安装。

3.在/usr/local/bin/目录下会发现easy_install。 

4.直接使用命令easy_install django 安装django。

Centos6 安装 stun/turn服务

1,关于stun和turn

STUN(Simple Traversal of UDP over NATs,NAT 的UDP简单穿越)是一种网络协议,它允许位于NAT(或多重NAT)后的客户端找出自己的公网地址,查出自己位于哪种类型的NAT之后以及NAT为某一 个本地端口所绑定的Internet端端口。这些信息被用来在两个同时处于NAT 路由器之后的主机之间建立UDP通信。该协议由RFC 3489定义。目前RFC 3489协议已被RFC 5389协议所取代,新的协议中,将STUN定义为一个协助穿越NAT的工具,并不独立提供穿越的解决方案。它还有升级版本RFC 7350,目前正在完善中。 

http://baike.baidu.com/view/884586.htm

TURN的全称为Traversal Using Relay NAT,即通过Relay方式穿越NAT,TURN应用模型通过分配TURNServer的地址和端口作为客户端对外的接受地址和端口,即私网用户发出的报文都要经过TURNServer进行Relay转发。 

http://baike.baidu.com/subview/351571/10359693.htm

2,安装

参考: 

http://www.hankcs.com/program/network/compile-rfc5766-turn-server-to-build-turn-server.html

代码下载: 

https://github.com/coturn/rfc5766-turn-server/releases 

下载最新的tar.gz包。rfc5766-turn-server-3.2.5.9.tar.gz

安装依赖环境

##ssl 需要yum安装 yum install openssl openssl-libs libevent libevent-devel
  • 1
  • 2

如果还是报错,就手动安装libevent。

centos Libevent2 development libraries are not installed properly in required location
  • 1

下载:http://libevent.org/ 官网,下载 

https://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz 

然后解压缩编译安装即可

编译turn-server

tar -zxvf rfc5766-turn-server-3.2.5.9.tar.gz
cd rfc5766-turn-server-3.2.5.9 ./configure 
make
make install
  • 1
  • 2
  • 3
  • 4
  • 5

configure成功:

more is /usr/bin/more
install is /usr/bin/install
pkill is /usr/bin/pkill
Use TMP dir /var/tmp
Compiler: cc Do not use -lsocket Do not use -lwldap32 Do not use -lwldap64 Do not use -lintl
Sockets code is fine: no sin_len field present
Ignore IP_RECVERR
Crypto SSL lib found.
SSL lib found.
Libevent2 development found.
Libevent2 runtime found.
Libevent2 openssl found.
Libevent2 pthreads found.

POSTGRESQL DEVELOPMENT LIBRARY (libpq.a) AND/OR HEADER (libpq-fe.h)
        ARE NOT INSTALLED PROPERLY ON THIS SYSTEM.
        THAT'S OK BUT THE TURN SERVER IS BUILDING WITHOUT POSTGRESQL DATABASE SUPPORT. MYSQL DEVELOPMENT LIBRARY (libmysqlclient) AND/OR HEADER (mysql.h)
        ARE NOT INSTALLED PROPERLY ON THIS SYSTEM.
        THAT'S OK BUT THE TURN SERVER IS BUILDING WITHOUT MYSQL DATABASE SUPPORT. HIREDIS DEVELOPMENT LIBRARY (libhiredis.*) AND/OR HEADERS (hiredis/*.h)
        ARE NOT INSTALLED PROPERLY ON THIS SYSTEM.
        THAT'S OK BUT THE TURN SERVER IS BUILDING WITHOUT REDIS SUPPORT. PREFIX=/usr/local OSLIBS= -L/usr/local/lib/ -L/usr/local/lib/ -L/usr/local/lib64/ -L/usr/local/lib64/ -lrt -pthread -lcrypto -lssl -levent_core -levent_openssl -levent_pthreads  -Wl,-rpath,/usr/local/lib/ -Wl,-rpath,/usr/local/lib/ -Wl,-rpath,/usr/local/lib64/ -Wl,-rpath,/usr/local/lib64/ -Wl,-rpath,/usr/lib64/mysql -Wl,-rpath,/usr/local/lib DBLIBS= OSCFLAGS=-g  -Wall -Wno-deprecated-declarations -Wextra -Wformat-security -Wnested-externs -Wstrict-prototypes  -Wmissing-prototypes -Wpointer-arith -Wcast-qual -I/usr/local/include -I/usr/local/include/ -I/usr/local/include  -DTURN_HAS_DAEMON    -DINSTALL_PREFIX=/usr/local DBCFLAGS=
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

只是说没有数据库支持的库,暂时不需要。

安装之后说明:

1) If you system supports automatic start-up system daemon services, 
the, to enable the turnserver as an automatically started system 
service, you have to:

        a) Create and edit /etc/turnserver.conf or /usr/local/etc/turnserver.conf . 
        Use /usr/local/etc/turnserver.conf.default as an example.

        b) For user accounts settings, if using the turnserver with authentication: create and edit /etc/turnuserdb.conf 
        file, or set up PostgreSQL or MySQL or Redis database for user accounts.
        Use /usr/local/etc/turnuserdb.conf.default as example for flat file DB, or use /usr/local/share/turnserver/schema.sql as SQL database schema, or use /usr/local/share/turnserver/schema.userdb.redis as Redis database schema description and/or /usr/local/share/turnserver/schema.stats.redis as Redis status & statistics database schema description.

        c) add whatever is necessary to enable start-up daemon for the /usr/local/bin/turnserver. 2) If you do not want the turnserver to be a system service, then you can start/stop it "manually", using the "turnserver" executable with appropriate options (see the documentation). 3) To create database schema, use schema in file /usr/local/share/turnserver/schema.sql. 4) For additional information, run:

   $ man turnserver
   $ man turnadmin
   $ man turnutils
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

在根目录创建一个user.db文件 

使用turnserver启动:

turnserver --userdb /root/turnuser.db 里面是webrtc用户名密码: webrtc:secret
  • 1
  • 2
  • 3

3,页面调用

https://github.com/EricssonResearch/openwebrtc-examples/tree/master/web 

安装node参考之前文章: 

http://blog.csdn.net/freewebsys/article/details/46649667#t1

修改main.js

// must use 'url' here since Firefox doesn't understand 'urls' var configuration = { "iceServers": [
  { "url": "stun:mmt-stun.verkstad.net" },
  { "url": "turn:mmt-turn.verkstad.net", "username": "webrtc", "credential": "secret" }
  ]
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

将stun服务器和turn服务器替换。

4,总结

stun和trun是webrtc打通的关键服务器,但是资源有限没有在公网测试。

turnserver.conf文件详解

谷歌推荐的开源穿透服务器,包含trun和stun服务,主页:https://code.google.com/p/rfc5766-turn-server/
(个人觉得可以利用这个来进一步搭建VPN,有兴趣的可以试试)

由于国内通讯都被监控,所以WebRTC是不能直接P2P的,都需要中继服务作为转发的,所以在国内使用WebRTC是需要搭建中继服务。

安装:
版本:turnserver-3.2.3.95.tar.gz  系统环境:centos

下载必要库

yum install -y make auomake gcc cc gcc-c++ wget
yum install -y openssl-devel libevent libevent-devel mysql-devel mysql-server
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar xvfz libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable && ./configure
make && make install && cd ..


下载turnserver-3.2.3.95.tar.gz并安装

wget http://turnserver.open-sys.org/downloads/v3.2.3.95/turnserver-3.2.3.95.tar.gz
tar -xvzf turnserver-3.2.3.95.tar.gz
cd turnserver-3.2.3.95
./configure
make && make install




安装后,配置turnserver.conf和turnuserdb.conf
启动

turnserver -L <public_ip_address> -c turnserver.conf -o -a -b turnuserdb.conf -f -r <system_domain_name>




可以通过以下指令获取帮助

turnserver -h




turnserver.conf配置:

# RFC5766-TURN-SERVER configuration file
# RFC5766-TURN-SERVER配置文件
#
# Boolean values note: where boolean value is supposed to be used,
# you can use ‘0’, ‘off’, ‘no’, ‘false’, ‘f’ as ‘false,
# and you can use ‘1’, ‘on’, ‘yes’, ‘true’, ‘t’ as ‘true’
# If the value is missed, then it means ‘true’.
#
# 布尔值注意: 布尔值应该被使用,
# 您可以使用’0′, ‘off’, ‘no’, ‘false’, ‘f’ 相当于 ‘false,
# 还有你可以用’1′, ‘on’, ‘yes’, ‘true’, ‘t’ 相当于 ‘true’
# 如果没有值,相当于’true’.
#

# Listener interface device (optional, Linux only).
# NOT RECOMMENDED.
#
# 侦听器接口设备(仅可选,Linux)。
# 不推荐。
#
#listening-device=eth0

# TURN listener port for UDP and TCP (Default: 3478).
# Note: actually, TLS & DTLS sessions can connect to the
# “plain” TCP & UDP port(s), too – if allowed by configuration.
#
# TURN为UDP和TCP的侦听器端口(默认: 3478)。
# 注:实际上,TLS和DTLS会话可以连接到”清晰的”TCP和UDP端口,——如果允许配置。
#
#listening-port=3478
listening-port=3478

# TURN listener port for TLS (Default: 5349).
# Note: actually, “plain” TCP & UDP sessions can connect to the TLS & DTLS
# port(s), too – if allowed by configuration. The TURN server
# “automatically” recognizes the type of traffic. Actually, two listening
# endpoints (the “plain” one and the “tls” one) are equivalent in terms of
# functionality; but we keep both endpoints to satisfy the RFC 5766 specs.
# For secure TCP connections, we currently support SSL version 3 and
# TLS version 1.0, 1.1 and 1.2. SSL2 “encapculation mode” is also supported.
# For secure UDP connections, we support DTLS version 1.
#
# TURN为TLS的侦听器端口(默认: 5349)。
# 注意:事实上,”清晰的”TCP和UDP会话可以连接到TLS和DTLS端口,如果允许配置。
# TURN服务器”自动”识别传输类型。实际上,两个监听终端点(“清晰的”端和”TLS”端)是
# 对等的功能;但我们保持两个端点来满足RFC 5766规范。
# 对于安全的TCP连接,我们目前支持SSL的3个版本,是TLS 1.0版本,1.1版本和1.2版本。
# SSL2还支持”encapculation模式”。对于安全的UDP连接,我们支持DTLS版本1。
#
#tls-listening-port=5349
tls-listening-port=5349

# Alternative listening port for UDP and TCP listeners;
# default (or zero) value means “listening port plus one”.
# This is needed for RFC 5780 support
# (STUN extension specs, NAT behavior discovery). The TURN Server
# supports RFC 5780 only if it is started with more than one
# listening IP address of the same family (IPv4 or IPv6).
# RFC 5780 is supported only by UDP protocol, other protocols
# are listening to that endpoint only for “symmetry”.
#
# 选择UDP和TCP监听器监听端口;
# 默认(或者0)是表示监听的端口加1.
# 这是必须的,为了RFC 5780的支持(STUN的扩展规范, NAT后端的发现)。
# TURN服务器支持RFC 5780只有启动与多个监听同一族的IP地址(IPv4或IPv6).
# RFC 5780只有UDP协议,支持其他协议是监听”对称”型端口的。
#
#alt-listening-port=0
                                   
# Alternative listening port for TLS and DTLS protocols.
# Default (or zero) value means “TLS listening port plus one”.
#
# 选择监听端口TLS和DTLS协议。
# 默认(或者0)是表示TLS监听的端口加1.
#
#alt-tls-listening-port=0
    
# Listener IP address of relay server. Multiple listeners can be specified.
# If no IP(s) specified in the config file or in the command line options,
# then all IPv4 and IPv6 system IPs will be used for listening.
#
# 侦听器中继服务器的IP地址。可以指定多个侦听器。
# 如果没有在配置文件或者命令选项中指定监听的IP,
# 那么所有的IPv4和IPv6所有的IP将被监听
#
#listening-ip=172.17.19.101
#listening-ip=10.207.21.238
#listening-ip=2607:f0d0:1002:51::4
listening-ip=<IP>

# Auxiliary STUN/TURN server listening endpoint.
# Aux servers have almost full TURN and STUN functionality.
# The (minor) limitations are:
# 1) Auxiliary servers do not have alternative ports and
# they do not support STUN RFC 5780 functionality (CHANGE REQUEST).
# 2) Auxiliary servers also are never returning ALTERNATIVE-SERVER reply.
# Valid formats are 1.2.3.4:5555 for IPv4 and [1:2::3:4]:5555 for IPv6.
# There may be multiple aux-server options, each will be used for listening
# to client requests.
#
# 辅助STUN/TURN服务器监听端口。
# 辅助服务器几乎有齐TURN和STUN功能
# (一些)局限性:
# 1) 辅助服务器没有替代的端口并且他们不支持STUN RFC 5780功能(变更请求)。
# 2) 辅助服务器也不会返回ALTERNATIVE-SERVER回复。
# 有效格式,IPv4的1.2.3.4:5555 和IPv6的[1:2::3:4]:5555。
# 可能会有多个aux-server选项,每个将用于监听客户端请求。
#
#aux-server=172.17.19.110:33478
#aux-server=[2607:f0d0:1002:51::4]:33478

# (recommended for older Linuxes only)
# Automatically balance UDP traffic over auxiliary servers (if configured).
# The load balancing is using the ALTERNATE-SERVER mechanism.
# The TURN client must support 300 ALTERNATE-SERVER response for this
# functionality.
#
# (仅推荐老的Linuxes)
# 在辅助服务器自动均衡UDP流量(如果配置)。
# 使用ALTERNATE-SERVER的负载均衡机制。
# TURN客户端必须支持300个ALTERNATE-SERVER响应。
#
#udp-self-balance

# Relay interface device for relay sockets (optional, Linux only).
# NOT RECOMMENDED.
#
# 终极接口设备为中继套接字(可选, 仅Linux).
# 不推荐。
#
#relay-device=eth1

# Relay address (the local IP address that will be used to relay the
# packets to the peer).
# Multiple relay addresses may be used.
# The same IP(s) can be used as both listening IP(s) and relay IP(s).
# If no relay IP(s) specified, then the turnserver will apply the default
# policy: it will decide itself which relay addresses to be used, and it
# will always be using the client socket IP address as the relay IP address
# of the TURN session (if the requested relay address family is the same
# as the family of the client socket).
#
# 中继地址(本地IP地址将用于传递数据包的给每个端)
# 可以使用多个中继地址。
# 相同的IP可以用作监听IP和继电器IP。
# 如果没有指定中继IP,那么turnserver将应用默认策略:它将自行决定使用那个中继
# 地址,并且它总是会使用客户端套接字的IP地址作为中继的IP地址在TURN会话中(如果
# 请求的中继地址族解决同族的客户端套接字)。
#
#relay-ip=172.17.19.105
#relay-ip=2607:f0d0:1002:51::5
relay-ip=<IP>

# For Amazon EC2 users:#
# TURN Server public/private address mapping, if the server is behind NAT.
# In that situation, if a -X is used in form “-X <ip>” then that ip will be reported
# as relay IP address of all allocations. This scenario works only in a simple case
# when one single relay address is be used, and no RFC5780 functionality is required.
# That single relay address must be mapped by NAT to the ‘external’ IP.
# The “external-ip” value, if not empty, is returned in XOR-RELAYED-ADDRESS field.
# For that ‘external’ IP, NAT must forward ports directly (relayed port 12345
# must be always mapped to the same ‘external’ port 12345).
# In more complex case when more than one IP address is involved,
# that option must be used several times, each entry must
# have form “-X <public-ip/private-ip>”, to map all involved addresses.
# RFC5780 NAT discovery STUN functionality will work correctly,
# if the addresses are mapped properly, even when the TURN server itself
# is behind A NAT.
# By default, this value is empty, and no address mapping is used.
#
# Amazon EC2用户:
# TURN服务器公开/私有的地址映射,假如服务器是在NAT后端。
# 在这种情况下,如果一个表单中”-X <ip>”使用一个-X,然后该ip将被作为中继ip地址来使用。
# 这种情况只适用于一个简单的例子,当一个中继的地址是被使用,和没有RFC5780功能是必需的。
# 单个中继地址必须通过NAT映射到外部的IP。
# 外部的IP值,假如不为空,通过XOR-RELAYED-ADDRESS字段返回。
# 外部的IP,NAT必须直接转发端口(转发端口12345,必须总是映射到相同的外部端口12345)。
# 在更复杂的情况下,当涉及到多个IP地址,这个选项必须使用几次,每个条目必须形
# 成”-X <public-ip/private-ip>”,将所有涉及到的地址。
# RFC5780 NAT发现STUN功能正常工作,如果正确的地址映射,即使TURN服务器本身是
# 在一个NAT后。
# 默认,该值为空,并且没有使用地址映射。
#
#external-ip=60.70.80.91
#
#OR:
#
#external-ip=60.70.80.91/172.17.19.101
#external-ip=60.70.80.92/172.17.19.102
external-ip=<IP>

# Number of relay threads to handle the established connections
# (in addition to authentication thread and the listener thread).
# If set to 0 then application runs relay process in a single thread,
# in the same thread with the listener process (the authentication thread will
# still be a separate thread).
# In the older systems (Linux kernel before 3.9),
# the number of UDP threads is always one thread per network listening endpoint –
# including the auxiliary endpoints – unless 0 (zero) or 1 (one) value is set.
#
# 数量的中继线程处理建立连接(除了验证线程和侦听器线程)。
# 如果设置为0,那么应用程序中继进程在一个线程中运行,在同一
# 个线程中监听处理(身份验证线程仍然是一个单独的线程)。
# 在旧系统(3.9 Linux内核之前),数量的UDP线程总是一个线程监听一个网络端点,包括辅助端点——除非设置0或1值。
#
#relay-threads=0
relay-threads=10

# Lower and upper bounds of the UDP relay endpoints:
# (default values are 49152 and 65535)
#
# UDP中继端点的上下边界:
# (默认是49152至65535)
#
#min-port=49152
#max-port=65535
    
# Uncomment to run TURN server in ‘normal’ ‘moderate’ verbose mode.
# By default the verbose mode is off.
#
# 取消TURN服务器运行’normal’ ‘moderate’详细模式。
# 默认情况下,详细模式是关闭的。
#
#verbose
    
# Uncomment to run TURN server in ‘extra’ verbose mode.
# This mode is very annoying and produces lots of output.
# Not recommended under any normal circumstances.
#
# 取消TURN服务器运行’extra’详细模式。
# 这种模式是非常恼人的,产生大量的输出。
# 在任何正常情况下不建议。
#
#Verbose

# Uncomment to use fingerprints in the TURN messages.
# By default the fingerprints are off.
#
# 取消在TURN消息中使用指纹。
# 默认情况下,指纹是关闭的。
#
#fingerprint

# Uncomment to use long-term credential mechanism.
# By default no credentials mechanism is used (any user allowed).
# This option can be used with either flat file user database or
# PostgreSQL DB or MySQL DB or Redis DB for user keys storage.
#
# 取消使用长期证书机制。
# 默认情况下不使用凭证机制(允许任何用户)。
# 这个选项可能使用用户数据文件或PostgreSQL或MySQL或Redis来存储用户密钥。
#
#lt-cred-mech
lt-cred-mech

# Uncomment to use short-term credential mechanism.
# By default no credentials mechanism is used (any user allowed).
# For short-term credential mechanism you have to use PostgreSQL or
# MySQL or Redis database for user password storage.
#
# 取消使用短期证书机制。
# 默认情况下不使用凭证机制(允许任何用户)。
# 短期证书机制必须使用PostgreSQL或MySQL或Redis数据库来存储用户密码。
#
#st-cred-mech

# This option is opposite to lt-cred-mech or st-cred-mech.
# (TURN Server with no-auth option allows anonymous access).
# If neither option is defined, and no users are defined,
# then no-auth is default. If at least one user is defined,
# in this file or in command line or in usersdb file, then
# lt-cred-mech is default.
#
# 这个选项是lt-cred-mech或st-cred-mech相反。
# (TURN服务器no-auth选项允许匿名访问)。
# 如果没有选项定义,没有用户定义,那么no-auth默认。
# 如果至少定义有一个用户,在这个文件中或在命令行或usersdb文件,
# 那么lt-cred-mech默认。
#
#no-auth

# TURN REST API flag.
# Flag that sets a special authorization option that is based upon authentication secret.
# This feature can be used with the long-term authentication mechanism, only.
# This feature purpose is to support “TURN Server REST API”, see
# “TURN REST API” link in the project’s page
http://code.google.com/p/rfc5766-turn-server/.
# This option is used with timestamp:
# usercombo -> “timestamp:userid”
# turn user -> usercombo
# turn password -> base64(hmac(secret key, usercombo))
# This allows TURN credentials to be accounted for a specific user id.
# If you don’t have a suitable id, the timestamp alone can be used.
# This option is just turning on secret-based authentication.
# The actual value of the secret is defined either by option static-auth-secret,
# or can be found in the turn_secret table in the database (see below).
#
# TURN REST API标志。
# 标志是设置一个特殊的授权选项,是基于身份验证的私密。
# 这个功能可以用于长期验证机制。
# 这个功能的目的是支持”TURN Server REST API”,看到”TURN Server REST API”项目的页面的链接
http://code.google.com/p/rfc5766-turn-server/。
# 这个选项是使用时间戳:
# usercombo -> “timestamp:userid”
# turn user -> usercombo
# turn password -> base64(hmac(secret key, usercombo))
# 这允许TURN凭证占用一个特定的用户id。
# 如果你没有一个合适的id,可以使用单独的时间戳。
# 这个选项只是打开基于私密的身份验证。
# 实际值定义的私密就是通过选择static-auth-secret,或可以在数据库中找到turn_secret表(见下文)。
#
#use-auth-secret

# ‘Static’ authentication secret value (a string) for TURN REST API only.
# If not set, then the turn server
# will try to use the ‘dynamic’ value in turn_secret table
# in user database (if present). The database-stored  value can be changed on-the-fly
# by a separate program, so this is why that other mode is ‘dynamic’.
#
# TURN REST API的’Static’身份验证的私密值(字符串)
# 如果没有设置,那么turn服务器将尝试使用’dynamic’值在用户数据库的turn_secret表(如果存在)。
# 数据库存储的值可以随时改变,通过单独的程序,所以这就是’dynamic’模式。
#
#static-auth-secret     

# ‘Static’ user accounts for long term credentials mechanism, only.
# This option cannot be used with TURN REST API or with short-term credentials
# mechanism.
# ‘Static’ user accounts are NOT dynamically checked by the turnserver process,
# so that they can NOT be changed while the turnserver is running.
#
# ‘Static’用户长期占凭证机制。
# 这个选项不能用于TURN REST API或短期凭证机制。
# ‘Static’用户帐户不是turnserver程序动态检查,所以他们不能改变在turnserver运行时。
#
#user=username1:key1
#user=username2:key2
# OR:
#user=username1:password1
#user=username2:password2
#
# Keys must be generated by turnadmin utility. The key value depends
# on user name, realm, and password:
#
# 钥匙必须由turnadmin实用程序生成。键值取决于用户名称、领域和密码:
#
# Example:
# 例子,使用以下命令:
#
# $ turnadmin -k -u ninefingers -r north.gov -p youhavetoberealistic
#
# Output: 0xbc807ee29df3c9ffa736523fb2c4e8ee
# 输出是: 0xbc807ee29df3c9ffa736523fb2c4e8ee
#
# (‘0x’ in the beginning of the key is what differentiates the key from
# password. If it has 0x then it is a key, otherwise it is a password).
# (‘0x’开始的关键是区分从密码的关键。如果它有0x,那么它是一个关键,否则这是一个密码)。
#
# The corresponding user account entry in the config file will be:
# 相应的配置文件中的用户帐户条目将:
#
#user=ninefingers:0xbc807ee29df3c9ffa736523fb2c4e8ee
# Or, equivalently, with open clear password (less secure):
#或者是这样,明文密码(不安全的):
#user=ninefingers:youhavetoberealistic
#
user=<yourname:yourpsw>

# ‘Dynamic’ user accounts database file name.
# Only users for long-term mechanism can be stored in a flat file,
# short-term mechanism will not work with option, the short-term
# mechanism required PostgreSQL or MySQL or Redis database.
# ‘Dynamic’ long-term user accounts are dynamically checked by the turnserver process,
# so that they can be changed while the turnserver is running.
# Default file name is turnuserdb.conf.
#
# ‘Dynamic’用户帐户数据库文件名。
# 只有用户长期机制可以存储在一个文件,短期机制不会处理选项,短期机制需要PostgreSQL或MySQL或
# Redis数据库。
# ‘Dynamic’的长期用户帐户在turnserver程序中动态检查的,这样他们可以改变的在turnserver运行时。
# 默认文件名是turnuserdb.conf.
#
#userdb=/usr/local/etc/turnuserdb.conf
userdb=/etc/turnuserdb.conf

# PostgreSQL database connection string in the case that we are using PostgreSQL
# as the user database.
# This database can be used for long-term and short-term credential mechanisms
# and it can store the secret value for secret-based timed authentication in TURN RESP API.
# See http://www.postgresql.org/docs/8.4/static/libpq-connect.html for 8.x PostgreSQL
# versions connection string format, see
http://www.postgresql.org/docs/9.2/static/libpq-connect.html#LIBPQ-CONNSTRING
# for 9.x and newer connection string formats.
#
# PostgreSQL数据库连接字符串,使用PostgreSQL作为用户数据库。
# 该数据库可用于长期和短期证书机制,它可以存储的私密值,为基于私密身份验证的在TURN RESP API中。
# 8.x PostgreSQL版本请参见http://www.postgresql.org/docs/8.4/static/libpq-connect.html的连接字符串
# 格式,9.x和更新的请参阅http://www.postgresql.org/docs/9.2/static/libpq-connect.html LIBPQ-CONNSTRING
# 的连接字符串格式。
#
#psql-userdb=”host=<host> dbname=<database-name>
user=<database-user> password=<database-user-password>
connect_timeout=30″

# MySQL database connection string in the case that we are using MySQL
# as the user database.
# This database can be used for long-term and short-term credential mechanisms
# and it can store the secret value for secret-based timed authentication in TURN RESP API.
# Use string format as below (space separated parameters, all optional):
#
# MySQL数据库连接字符串,使用MySQL作为用户数据库。
# 该数据库可用于长期和短期证书机制,它可以存储的私密值,为基于私密身份验证的在TURN RESP API中。
# 使用字符串格式如下(空间分离参数,所有可选):
#
#mysql-userdb=”host=<host> dbname=<database-name>
user=<database-user> password=<database-user-password>
port=<port> connect_timeout=<seconds>”

# Redis database connection string in the case that we are using Redis
# as the user database.
# This database can be used for long-term and short-term credential mechanisms
# and it can store the secret value for secret-based timed authentication in TURN RESP API.
# Use string format as below (space separated parameters, all optional):
#
# Redis数据库连接字符串,使用Redis作为用户数据库。
# 该数据库可用于长期和短期证书机制,它可以存储的私密值,为基于私密身份验证的在TURN RESP API中。
# 使用字符串格式如下(空间分离参数,所有可选):
#
#redis-userdb=”ip=<ip-address> dbname=<database-number>
password=<database-user-password> port=<port>
connect_timeout=<seconds>”

# Redis status and statistics database connection string, if used (default – empty, no Redis stats DB used).
# This database keeps allocations status information, and it can be also used for publishing
# and delivering traffic and allocation event notifications.
# The connection string has the same parameters as redis-userdb connection string.
# Use string format as below (space separated parameters, all optional):
#
# Redis状态和统计数据库连接字符串,如果使用(默认空,没有Redis统计数据库使用)。
# 这个数据库保持分配状态信息,它也可以用于发布和交付传输和分配事件通知。
# 连接字符串有相同的参数作为redis-userdb连接字符串。
# 使用字符串格式如下(空间分离参数,所有可选):
#
#redis-statsdb=”ip=<ip-address> dbname=<database-number>
password=<database-user-password> port=<port>
connect_timeout=<seconds>”

# Realm for long-term credentials mechanism and for TURN REST API.
#
# TURN REST API的长期凭证机制范围。
#
#realm=mycompany.org

# Per-user allocation quota.
# default value is 0 (no quota, unlimited number of sessions per user).
#
# 每个用户分配配额。
# 默认值为0(没有配额,每个用户无限数量的会话)。
#
#user-quota=0

# Total allocation quota.
# default value is 0 (no quota).
#
# 总分配配额。
# 默认值为0(无配额)。
#
#total-quota=0

# Max bytes-per-second bandwidth a TURN session is allowed to handle
# (input and output network streams are treated separately). Anything above
# that limit will be dropped or temporary suppressed (within
# the available buffer limits).
#
# TURN会话允许最大的传输占用带宽(输入和输出网络流分别处理)。
# 高于限制将被删除或暂时抑制(在可用的缓冲区范围内)。
#
#max-bps=0
max-bps=1024

# Uncomment if no UDP client listener is desired.
# By default UDP client listener is always started.
#
# 如果没有UDP客户端监听器需要取消。
# 默认情况下UDP客户端监听器总是启动。
#
#no-udp

# Uncomment if no TCP client listener is desired.
# By default TCP client listener is always started.
#
# 如果没有TCPP客户端监听器需要取消。
# 默认情况下TCPP客户端监听器总是启动。
#
#no-tcp

# Uncomment if no TLS client listener is desired.
# By default TLS client listener is always started.
#
# 如果没有TLS客户端监听器需要取消。
# 默认情况下TLS客户端监听器总是启动。
#
#no-tls

# Uncomment if no DTLS client listener is desired.
# By default DTLS client listener is always started.
#
# 如果没有DTLS客户端监听器需要取消。
# 默认情况下DTLS客户端监听器总是启动。
#
#no-dtls

# Uncomment if no UDP relay endpoints are allowed.
# By default UDP relay endpoints are enabled (like in RFC 5766).
#
# 如果不允许UDP中继端点需要取消。
# 默认情况下启用UDP继电器端点(如在RFC 5766)。
#
#no-udp-relay

# Uncomment if no TCP relay endpoints are allowed.
# By default TCP relay endpoints are enabled (like in RFC 6062).
#
# 如果不允许TCP中继端点需要取消。
# 默认情况下启用TCP继电器端点(如在RFC 5766)。
#
#no-tcp-relay

# Uncomment if extra security is desired,
# with nonce value having limited lifetime (600 secs).
# By default, the nonce value is unique for a session,
# but it has unlimited lifetime. With this option,
# the nonce lifetime is limited to 600 seconds, after that
# the client will get 438 error and will have to re-authenticate itself.
#
# 取消如果需要额外的安全,现时已有有限的生命周期(600秒)。
# 默认情况下,一个会话的唯一临界值,但它一般拥有无限的生命周期。这个选项,临界值
# 仅限于600秒,之后,客户端将得到438错误,将不得不重新认证。
#
#stale-nonce

# Certificate file.
# Use an absolute path or path relative to the
# configuration file.
#
# 证书文件。
# 使用绝对路径或路径相对于配置文件。
#
#cert=/usr/local/etc/turn_server_cert.pem

# Private key file.
# Use an absolute path or path relative to the
# configuration file.
# Use PEM file format.
#
# 私钥文件。
# 使用绝对路径或路径相对于配置文件。使用PEM文件格式。
#
#pkey=/usr/local/etc/turn_server_pkey.pem

# Private key file password, if it is in encoded format.
# This option has no default value.
#
# 私有密钥文件密码,如果是在编码格式。
# 这个选项没有默认值。
#
#pkey-pwd=…

# Allowed OpenSSL cipher list for TLS/DTLS connections.
# Default value is “DEFAULT”.
#
# 允许OpenSSL的密码列表为TLS/DTLS连接。
# 默认值是”DEFAULT”
#
#cipher-list=”DEFAULT”

# CA file in OpenSSL format.
# Forces TURN server to verify the client SSL certificates.
# By default it is not set: there is no default value and the client
# certificate is not checked.
#
# 在OpenSSL格式的CA文件。
# 强制TURN服务器验证客户端SSL证书。
# 默认情况下它没有设置:没有默认值,不检查的客户端证书。
#
# Example:
#CA-file=/etc/ssh/id_rsa.cert

# Curve name for EC ciphers, if supported by OpenSSL library (TLS and DTLS).
# The default value is prime256v1.
#
# 曲线名称的EC密码,如果由OpenSSL库支持(TLS和DTLS)。
# 默认值是prime256v1。
#
#ec-curve-name=prime256v1

# Use 566 bits predefined DH TLS key. Default size of the key is 1066.
#
# 使用566位预定义DH TLS键。默认键大小是1066
#
#dh566

# Use 2066 bits predefined DH TLS key. Default size of the key is 1066.
#
# 使用2066位预定义DH TLS键。默认键大小是1066
#
#dh2066

# Use custom DH TLS key, stored in PEM format in the file.
# Flags –dh566 and –dh2066 are ignored when the DH key is taken from a file.
#
# 使用惯例的DH TLS键,使用PEM格式存储在文件里
# 当DH键从文件里加载,将忽略标志–dh566和–dh2066
#
#dh-file=<DH-PEM-file-name>

# Flag to prevent stdout log messages.
# By default, all log messages are going to both stdout and to
# the configured log file. With this option everything will be
# going to the configured log only (unless the log file itself is stdout).
#
# 标志防止输出日志信息
# 默认情况下,所有日志消息将输出到配置的日志文件。采用这一选项都将只配置日志
# (除非日志文件本身是输出的)。
#
#no-stdout-log

# Option to set the log file name.
# By default, the turnserver tries to open a log file in
# /var/log, /var/tmp, /tmp and current directories directories
# (which open operation succeeds first that file will be used).
# With this option you can set the definite log file name.
# The special names are “stdout” and “-” – they will force everything
# to the stdout. Also, the “syslog” name will force everything to
# the system log (syslog).
# In the runtime, the logfile can be reset with the SIGHUP signal
# to the turnserver process.
#
# 设置日志文件
# 默认情况下,turnserver尝试一个日志文件在/var/log,/var/tmp,/tmp和
# 当前目录(那个文件先打开成功,文件将被使用)。
# 采用这一选项可以设置明确的日志文件名。
# 特殊的名字是”stdout”和”-“——他们将强制所有的输出。同时,”syslog”名称将强制所有的系统日志(syslog)。
# 在运行时,日志文件可以重置通过SIGHUP信号在turnserver程序中。
#
#log-file=/var/tmp/turn.log

# Option to redirect all log output into system log (syslog).
#
# 选择重定向所有日志输出到系统日志(syslog)。
#
#syslog

# This flag means that no log file rollover will be used, and the log file
# name will be constructed as-is, without PID and date appendage.
#
# 这个标志意味着没有日志文件将使用翻转,并按原样将创建日志文件名称,没有PID和日期的附加。
#
#simple-log

# Option to set the “redirection” mode. The value of this option
# will be the address of the alternate server for UDP & TCP service in form of
# <ip>[:<port>]. The server will send this value in the attribute
# ALTERNATE-SERVER, with error 300, on ALLOCATE request, to the client.
# Client will receive only values with the same address family
# as the client network endpoint address family.
# See RFC 5389 and RFC 5766 for ALTERNATE-SERVER functionality description.
# The client must use the obtained value for subsequent TURN communications.
# If more than one –alternate-server options are provided, then the functionality
# can be more accurately described as “load-balancing” than a mere “redirection”.
# If the port number is omitted, then the default port
# number 3478 for the UDP/TCP protocols will be used.
# Colon ( characters in IPv6 addresses may conflict with the syntax of
# the option. To alleviate this conflict, literal IPv6 addresses are enclosed
# in square brackets in such resource identifiers, for example:
# [2001:db8:85a3:8d3:1319:8a2e:370:7348]:3478 .
# Multiple alternate servers can be set. They will be used in the
# round-robin manner. All servers in the pool are considered of equal weight and
# the load will be distributed equally. For example, if we have 4 alternate servers,
# then each server will receive 25% of ALLOCATE requests. A alternate TURN server
# address can be used more than one time with the alternate-server option, so this
# can emulate “weighting” of the servers.
#
# 选项设置”redirection”模式。这个选项的值将备用服务器的地址UDP和TCP服务形式的<ip>[:<port>]。
# 服务器将发送这个值属性ALTERNATE-SERVER,错误300,在ALLOCATE请求,客户端。
# 客户端将只接收和自己相同的地址族的客户端的值。查看RFC 5389和RFC 5766为ALTERNATE-SERVER的功能描述。
# 客户端必须使用获得的值为随后的TURN通信。如果不止一个——alternate-server选项提供,那么功能可以更准确
# 地描述为”load-balancing”,而不仅仅是一个”redirection”。如果端口号省略,那么为UDP/TCP协议,使用默认端
# 口号是3478。冒号(在IPv6地址字符可能与选项的语法冲突。缓解这种冲突,文字IPv6地址包含在方括号在这种
# 资源标识符,例如[2001:db8:85a3:8d3:1319:8a2e:370:7348]:3478 。
# 可以设置多个备用服务器。他们将用于循环的方式。所有服务器池中被认为是平等的重量和载荷将平均分配的原则。
# 例如,如果我们有4个备用服务器,每个服务器将获得25%的分配请求。备用TURN服务器地址可以使用超过一次
# alternate-server选项,所以这可以效仿的”weighting”服务器。
#
# Examples:
#alternate-server=1.2.3.4:5678
#alternate-server=11.22.33.44:56789
#alternate-server=5.6.7.8
#alternate-server=[2001:db8:85a3:8d3:1319:8a2e:370:7348]:3478
              
# Option to set alternative server for TLS & DTLS services in form of
# <ip>:<port>. If the port number is omitted, then the default port
# number 5349 for the TLS/DTLS protocols will be used. See the previous
# option for the functionality description.
#
# 选项设置替代服务器TLS和DTLS服务形式的<ip>:<port>。
# 如果省略的端口号,那么默认端口号5349将使用TLS/DTLS协议。看到前面选择的功能描述。
#
# Examples:
#tls-alternate-server=1.2.3.4:5678
#tls-alternate-server=11.22.33.44:56789
#tls-alternate-server=[2001:db8:85a3:8d3:1319:8a2e:370:7348]:3478

# Option to suppress TURN functionality, only STUN requests will be processed.
# Run as STUN server only, all TURN requests will be ignored.
# By default, this option is NOT set.
#
# 选择抑制TURN功能,只有STUN的请求将被处理。
# 作为STUN服务器,所有TURN请求将被忽略。
# 默认情况下,没有设置这个选项。
#
#stun-only

# Option to suppress STUN functionality, only TURN requests will be processed.
# Run as TURN server only, all STUN requests will be ignored.
# By default, this option is NOT set.
#
# 选择抑制STUN功能,只有TURN的请求将被处理。
# 作为TURN服务器,所有STUN请求将被忽略。
# 默认情况下,没有设置这个选项。
#
#no-stun

# This is the timestamp/username separator symbol (character) in TURN REST API.
# The default value is ‘:’.
#
# 这是时间戳/用户名分离器符号(字符)在TURN REST API。
# 默认是使用’:’
#
# rest-api-separator=:    

# Flag that can be used to disallow peers on the loopback addresses (127.x.x.x and ::1).
# This is an extra security measure.
#
# 标记用于不接受的端在环回地址(127.x.x.x 和 ::1)。
# 这是一个额外的安全措施。
#
#no-loopback-peers

# Flag that can be used to disallow peers on well-known broadcast addresses (224.0.0.0 and above, and FFXX:*).
# This is an extra security measure.
#
# 标记用于不接受的端在广播地址(224.0.0.0和以上的,和FFXX:*)。
# 这是一个额外的安全措施。
#
#no-multicast-peers

# Option to set the max time, in seconds, allowed for full allocation establishment.
# Default is 60 seconds.
#
# 选项设置的最大时间,以秒为单位,允许完整的分配。
# 默认60秒
#
#max-allocate-timeout=60

# Option to allow or ban specific ip addresses or ranges of ip addresses.
# If an ip address is specified as both allowed and denied, then the ip address is
# considered to be allowed. This is useful when you wish to ban a range of ip
# addresses, except for a few specific ips within that range.
# This can be used when you do not want users of the turn server to be able to access
# machines reachable by the turn server, but would otherwise be unreachable from the
# internet (e.g. when the turn server is sitting behind a NAT)
#
# 选择允许或禁止特定的ip地址或ip地址范围。
# 如果指定一个ip地址允许和拒绝,那么ip地址被认为是允许的。这是有用的,当你希望禁止一个范
# 围的ip地址,除了一些特定的ip范围内。
# 这可以使用当你不希望turn服务器的用户能够访问机器通过turn服务器,但可能是另一方面从互联
# 网上不能到达(例如,当turn服务器是在一个NAT后)
#
# Examples:
# denied-peer-ip=83.166.64.0-83.166.95.255
# allowed-peer-ip=83.166.68.45

# File name to store the pid of the process.
# Default is /var/run/turnserver.pid (if superuser account is used) or
# /var/tmp/turnserver.pid .
#
# 存储进程pid的文件名。
# 默认是/var/run/turnserver.pid(超级用户使用)或者是/var/tmp/turnserver.pid
#
#pidfile=”/var/run/turnserver.pid”
pidfile=”/var/tmp/turnserver.pid”

# Require authentication of the STUN Binding request.
# By default, the clients are allowed anonymous access to the STUN Binding functionality.
#
# 需要STUN绑定请求的身份验证。
# 默认情况下,客户允许匿名访问STUN绑定功能。
#
#secure-stun

# Require SHA256 digest function to be used for the message integrity.
# By default, the server uses SHA1 (as per TURN standard specs).
# With this option, the server
# always requires the stronger SHA256 function. The client application
# must support SHA256 hash function if this option is used. If the server obtains
# a message from the client with a weaker (SHA1) hash function then the
# server returns error code 426.
#
# 需要SHA256采摘功能用于消息的完整性。
# 默认情况下,服务器使用SHA1(按标准规格)。
# 采用这一选项,服务器总是需要更强的SHA256功能。客户端应用程序必须支持SHA256散列函数
# 如果使用这个选项。如果服务器获得消息从客户端较弱(SHA1)散列函数那么服务器返回错误代码426。
#
#sha256

# Mobility with ICE (MICE) specs support.
#
# 移动的ICE(MICE)的规范支持。
#
#mobility

# User name to run the process. After the initialization, the turnserver process
# will make an attempt to change the current user ID to that user.
#
# 用户名运行程序。初始化后,turnserver程序将试图改变当前用户的用户ID。
#
#proc-user=<user-name>

# Group name to run the process. After the initialization, the turnserver process
# will make an attempt to change the current group ID to that group.
#
# 组名运行程序。初始化后,turnserver程序将试图改变当前组的组ID。
#
#proc-group=<group-name>

# Turn OFF the CLI support.
# By default it is always ON.
# See also options cli-ip and cli-port.
#
# 关掉CLI的支持。
# 默认情况下它总是ON。
# 参阅选项cli-ip和cli-port。
#
#no-cli

#Local system IP address to be used for CLI server endpoint. Default value
# is 127.0.0.1.
#
# 本地系统的IP地址将用于CLI服务器端点。默认值是127.0.0.1。
#
#cli-ip=127.0.0.1

# CLI server port. Default is 5766.
#
# CLI服务器端口。默认是5766。
#
#cli-port=5766

# CLI access password. Default is empty (no password).
#
# CLI访问密码。默认是空的(没有密码)。
#
#cli-password=logen

# Server relay. NON-STANDARD AND DANGEROUS OPTION.
# Only for those applications when we want to run
# server applications on the relay endpoints.
# This option eliminates the IP permissions check on
# the packets incoming to the relay endpoints.
#
# 中继服务器。NON-STANDARD和DANGEROUS的选择。
# 只对这些应用程序时,我们想在中继服务器上运行服务器应用程序端点。
# 这个选项可以消除IP权限检查传递的数据包传入的端点。
#
#server-relay

# Maximum number of output sessions in ps CLI command.
# This value can be changed on-the-fly in CLI. The default value is 256.
#
# 最大数量的输出会议在ps CLI命令。
# 这个值可以动态改变在CLI。默认值是256。
#
#cli-max-output-sessions

# Set network engine type for the process (for internal purposes).
#
# 设置网络引擎类型(用于内部目的)的过程。
#
#ne=[1|2|3]

# Do not allow an SSL/TLS version of protocol
#
# 不允许一个SSL/TLS版本的协议
#
#no-sslv2
#no-sslv3
#no-tlsv1
#no-tlsv1_1
#no-tlsv1_2




turnuserdb.conf

#This file can be used as user accounts storage for long-term credentials mechanism.
#这个文件可以用作长期用户帐户存储凭证机制。
#
#username1:key1
#username2:key2
# OR:
#username1:password1
#username2:password2
#
# Keys must be generated by turnadmin utility. The key value depends
# on user name, realm, and password:
# 钥匙必须由turnadmin实用程序生成。键值取决于用户名称、领域和密码:
#
# Example:
# 例子,使用以下命令:
# $ turnadmin -k -u ninefingers -r north.gov -p youhavetoberealistic
# Output: 0xbc807ee29df3c9ffa736523fb2c4e8ee
# 输出是: 0xbc807ee29df3c9ffa736523fb2c4e8ee
#
# (‘0x’ in the beginning of the key is what differentiates the key from
# password. If it has 0x then it is a key, otherwise it is a password).
# (‘0x’开始的关键是区分从密码的关键。如果它有0x,那么它是一个关键,否则这是一个密码)。
#
# The corresponding user account entry in the userdb file will be:
# 相应的用户帐号在userdb文件中是:
#
#ninefingers:0xbc807ee29df3c9ffa736523fb2c4e8ee
# Or, equivalently (less secure):
#或者是这样(不安全的):
#ninefingers:youhavetoberealistic
#
yourname:yourpsw


转自:www.webrtcbbs.com

webrtc与stunserver、turnserver建立连接花费时间十秒左右

  很奇怪,使用之前基于webrtc的p2p模块时出了了大问题,问题如标题左右,记得之前使用另外版本的webrtc做开发的时候,本地在CreateOffer后能够能够很快和turnserver连接,估计最左就两三秒,然而现在却是十秒左右了!

   由于换了一个webrtc的版本(此版本是支持winxp系统的),所以第一感觉似乎是webrtc版本的问题,实际上不是,因为就算是换回之前的版本,client和turnserver的连接时间几乎花费了与当前版本webrtc 差不多的时间。

 
 之前也说了,就是之前有点时间,client与turnserver的连接是正常的,于是在google到了一个解决方案,即是trickle
ice技术,据说使用该方法能够大大缩短client与opposite
client的连接时间,这个解决方案似乎和当前所遇到的问题擦着一点边,但是似乎可以值得尝试,因为这或多或少会提升client连接到对面的体验!然而client和turnserver的连接速度是似乎没多大作用,放弃此方案。

   
实际上只要网络状态好,按道理来讲本地client和turnserver的connect
时间应该很短才对,实际上也是如此!后来调试发现在client连接turnserver的过程中在stunrequest.cc中都有调用OnTimeout函数,而且说明本地client和turnserver的连接很不理想,通过查看源码获知在timeout的过程中,本地客户端总共尝试了MAX_SENDS次重发送(发送给turnserver、stunserver),在源码中MAX_SENDS被宏定义为9,超过9次之后才正式通知外部(OnTimeout),
OnTimeout函数最终会触发webrtc底层,告知client本地的icecandidate的收集已经完成,接着出发了外部的OnIceGatheringChange函数,该函数的icecandidate收集状态state将会为kIceGatheringComplete,此时本地的client才会知道本地的icecandidate信息收集已经完结,那么怎么根据当前peerconnection是否成功和stunserver、turnserver连接呢?如果已经收集到的icecandidate中不但包含了本地的ip信息,还包括了stunserver、turnserver的ip信息,那么就可以决断本地client已经成功和turnserver连接,如果只是包含了本地的ip地址信息(icecandidate信息的type字段为host、local),那么就可以决断本地client连接turnserver服务器失败。

 
 而我遇到的情况是,从client开始连接到收集icecandidate信息成功花费了太长的时间(10左右),不过最后还是能够成功连接上turnserver,之前也说了花费了那么长时间全是浪费在timeout上了,那么问题来了?为什么我本地的网络情况良好(可下载、可开网页),怎么在就是在探测turnserver的时候那么艰难呢?断点查看timeout时对应的ip地址,明白了,这个ip地址是我电脑中之前安装的virtulBox中一个虚拟机的ip地址,这个我真是没想到!查看源码,知道webrtc在探测turnserver的时候是要遍历当前平台下的所有的网络适配器的,不管是系统自带的无限网络、还是以太有线网,还是其他应用软件虚拟出来的适配器,webrtc探测时都会遍历,之所以出现时间是花在timeout上,也只是说明对应的网络适配器在和turnserver尝试连接的时候,网路状况不好!鉴于此,于是在控制面板中将virtualBox中虚拟出来的适配器禁用,重新打开本地的client,发现几乎是秒连了!

PHP的性能演进(从PHP5.0到PHP7.1的性能速度全评测)

导读:PHP 是 Web 开发最常用的语言,每个大版本的更新都带来不少新特性和性能提升。特别是 PHP 7.0 的发布,带来 PHP
性能飞跃。本文作者对各个 PHP 版本进行了 CPU 性能基准测试,并且带来了PHP下个大版本的消息。本文中文版由高可用架构志愿者翻译。

自 1994 年 Rasmus Lerdorf 创建 PHP 以来, PHP 语言经历了许多改进,其中性能是开发人员在评估新版本时考虑的主要标准之一。

阅读这篇文章,可以了解从 PHP 5 到 7(包括 7.1)的性能提升,同时也将了解到即将加入到 PHP 8 的试验性的 JIT 分支版本的性能。

简介

本文将根据时间作出更新,增加更多信息和基准测试结果,包括尚未发布的新版本,以便更好地了解多年来 PHP 性能演变。如果您有更正或建议改进,请在文后留言。

自 1994 年 Rasmus Lerdorf 创建 PHP 以来, PHP 语言经历了激烈的演进。虽然第一版是一个简单的一人开发的
CGI 程序,Rasmus Lerdorf、Andi Gutmans 和 Zeev Suraski
加入了该语言的第三个版本的开发,并根本性重新设计。从那之后, PHP 开发组也创建并发展起来。

随着项目的发展,由于 PHP 3 天然的可扩展性, PHP 在核心和附加扩展开发的功能得到了蓬勃发展,如网络通信,解析,缓存和数据库支持。

语言本身也在发展,带来了一系列的改进。这包括支持面向对象的结构,例如类,接口, traits,闭包等。

对于许多开发人员来说,仅有新功能是不够的。随着语言越来越受欢迎, PHP 社区对于提供更好性能,可扩展性和更少内存使用的需求越来越强烈。

PHP 开发团队近 20 年来一直致力于解决这些需求,虽然 PHP 3 的引入大大提高了性能,但直到 Andi Gutmans 和 Zeev Suraski 引入 Zend Engine 并发布 PHP 4, PHP 的性能才开始变得正式起来。

2000 年推出的新的内存编译器和执行器模型大大提高了 PHP 的性能(提高了 5 倍甚至 10 倍),并首次被正式的 Web 应用程序和站点所使用。我们可以说,今天 PHP 的成果远远超出了任何人在 PHP 项目诞生时的期望。

PHP 的蓬勃发展增加了改善性能的欲望。幸运的是, Zend Engine 中设计的模型为持续优化性能提供了良好的基础。

虽然 PHP 5.0 没有带来实质性的性能提升,并且在某些情况下甚至比 PHP4 更慢,一个由 Dmitry Stogov
领导的团队在社区的大力帮助下已经在后续版本中不断优化语言,在 PHP 5.6 发布的时候,在大多数情况下,性能提升在 1.5x 和 3x 之间。

2015 年 12 月, PHP 7.0 取得了重大突破。 2016 年 12 月,7.1 版本也带来了一系列增强功能。

PHP 8 性能展望

这是一个前途光明的版本,目前正在开发当中,由 Zend 的 Dmitry Stogov 主导。虽然它是基于 PHP 7.1 版本基础,但实际版本号尚未定义,所以本文称这个版本为“试验 JIT”分支下。

关键功能 JIT(Just-In-Time)编译,是一种将代码转换为另一种字节码(比如运行它的机器 CPU 的本地代码)的技术。 JIT 可以使程序运行更快。

本文涵盖了几个基准测试的结果,从 PHP 5 的第一个版本到 PHP 的试验性 JIT 分支版本,PHP 5 之前的版本性能本文不作介绍。

在写这篇文章的时候,我们很难确定 PHP 8 之前是否会有另一个主要版本,比如 PHP 7.2。但是可以假设在 PHP 8 发布时,它已经包括当前试验版 JIT 分支的强大功能。

PHP 性能评估

本文只运行纯 CPU 任务脚本的基准测试(不需要I / O操作的任务例如访问文件,网络或数据库连接)。

使用的基准测试脚本如下所示:

  1. bench.php 可在PHP源代码的 php-src/Zend 目录
  2. micro_bench.php 也可以在 PHP 源代码发布的 php-src/Zend 目录中找到
  3. mandelbrot.php https://gist.githubusercontent.com/dstogov/12323ad13d3240aee8f1/raw/37fed3beb7e666b70e199bcf361af541b3c30d2d/b.php

基准脚本仅使用每个PHP主要版本的最新小版本运行。因此,测试的版本如下:

  1. 5.0.5
  2. 5.1.6
  3. 5.2.17
  4. 5.3.29
  5. 5.4.45
  6. 5.5.38
  7. 5.6.28
  8. 7.0.13
  9. 7.1.0
  10. PHP-JIT(JIT实验分支)

当然,我想确定,我们在相同的基准上运行所有小版本,例如在 5.3.0 到 5.3.29 之间。结果是有说服力的:性能方面的主要增强不是由小版本带来的,而是主要版本号的变化,例如从 PHP 5.4 到 PHP 5.5,或从PHP 5.6 到 PHP 7。

小版本没有显示任何明显的性能改进。这意味着相同的脚本应该以相同的速度运行,无论您使用 PHP 5.4.0 还是 PHP 5.4.45。

您可以查看基准进程部分,详细说明主机系统的设置,各个基准的运行方式以及如何解释时序结果。

纯 CPU 基准测试结果

这部分给出了每个 PHP 版本的基准测试结果。

每个基准列显示 3 个值:

  • 时间: 执行时间,以秒和毫秒为单位
  • %rel, gain:相对于以前的版本收益的执行时间。 在下面的表格中,例如,%rel。 bench.php 和版本 5.3.29 的收益是 31.89%,意味着该脚本比 5.2.17 版本运行快 31.89%。
  • %abs, gain:与 PHP 5.0 相比脚本运行的收益。 如果你看看bench.php 和试验性的 JIT 分支的这个列的交集,你会注意到,对于这个特定的测试基准,PHP 8 比 PHP 5.0 快 41 倍以上。

纯CPU基准测试的结果如下所示:

CPU基准测试

CPU基准测试


(1)测试不能在 5.3 之前的版本上运行,因为它使用了尚未实现的对象功能。
(2)此列中的结果有点偏颇,因为基准需要至少 PHP 5.3 运行。把它们当成纯粹说明,因为他们不能与 PHP 5.0 性能进行比较。
(3)这是一个 mandelbrot.php 脚本的修改版本,它运行得太快,在 7.1.0 和试验 JIT 分支无法准确的统计时间,我们在脚本中运行计算 100 次而不是 1 次。

纯CPU测试曲线图

当然,这些都是纯 CPU 的基准测试。它们不涵盖 PHP 性能的所有方面,它们可能不代表真实情况。但是结果足够显著,足以说明几个方面的问题:

完全使用 SFTP 替代 FTP :SFTP+OpenSSH+ChrootDirectory 设置详解

由于采用明文传输用户名和密码,FTP协议是不安全的。在同一机房中只要有一台服务器被攻击者控制,它就可能获取到其它服务器上的FTP密码,从而控制其它的服务器。

当然,很多优秀的FTP服务器都已经支持加密。但如果服务器上已经开了SSH服务,我们完全可以使用SFTP来传输数据,何必要多开一个进程和端口呢?

下面,我就从账户设置、SSH设置、权限设置这三个方面来讲讲如何使用SFTP完全替代FTP。本教程基于CentOS5.4。

范例

本文要实现以下功能:

SFTP要管理3个目录:

  • homepage
  • blog
  • pay

权限配置如下:

  • 账户www,可以管理所有的3个目录;
  • 账户blog,只能管理blog目录;
  • 账户pay,只能管理pay目录。

web服务器需求:

  • 账户blog管理的目录是一个博客网站,使用apache服务器。apache服务器的启动账户是apache账户,组为apache组。
  • 账户blog属于apache组,它上传的文件能够被apache服务器删除。同样的,它也能删除在博客中上传的文件(就是属于apache账户的文件)。

账户设置

SFTP的账户直接使用Linux操作系统账户,我们可以用useradd命令来创建账户。

首先建立3个要管理的目录:

				
				
1
2
3
				
				
mkdir /home/sftp/homepage
mkdir /home/sftp/blog
mkdir /home/sftp/pay

创建sftp组和www、blog、pay账号,这3个账号都属于sftp组:

				
				
1
2
3
4
5
6
7
8
9
10
11
12
				
				
groupadd sftp
useradd -M -d /home/sftp -G sftp www
useradd -M -d /home/sftp/blog -G sftp blog
useradd -M -d /home/sftp/pay -G sftp pay
# 将blog账户也加到apache组
useradd -M -d /home/sftp/blog -G apache blog
#设置3个账户的密码密码
passwd www
passwd blog
passwd pay

至此账户设置完毕。

SSH设置

首先要升级OpenSSH的版本。只有4.8p1及以上版本才支持Chroot。

CentOS 5.4的源中的最新版本是4.3,因此需要升级OpenSSH。

指定新的源:

				
				
1
2
3
4
5
6
7
8
				
				
vim /etc/yum.repos.d/test.repo
#输入如下内容
[centalt]
name=CentALT Packages for Enterprise Linux 5 - $basearch
baseurl=http://centos.alt.ru/repository/centos/5/$basearch/
enabled=0
gpgcheck=0
# wq保存

执行升级:

				
				
1
2
3
4
5
6
				
				
yum --enablerepo=centalt update -y openssh* openssl*
# 重启服务
service sshd restart
# 重看版本
ssh -V
# OpenSSH_5.8p1, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008

升级成功后,设置sshd_config。通过Chroot限制用户的根目录。

				
				
1
2
3
4
5
6
7
8
9
10
11
12
13
				
				
vim /etc/ssh/sshd_config
#注释原来的Subsystem设置
Subsystem sftp /usr/libexec/openssh/sftp-server
#启用internal-sftp
Subsystem sftp internal-sftp
#限制www用户的根目录
Match User www
ChrootDirectory /home/sftp
ForceCommand internal-sftp
#限制blog和pay用户的根目录
Match Group sftp
ChrootDirectory %h
ForceCommand internal-sftp

完成这一步之后,尝试登录SFTP:

				
				
1
2
3
4
5
6
				
				
sftp www@abc.com
#或者
ssh www@abc.com
#如果出现下面的错误信息,则可能是目录权限设置错误,继续看下一步
#Connection to abc.com closed by remote host.
#Connection closed

权限设置

要实现Chroot功能,目录权限的设置非常重要。否则无法登录,给出的错误提示也让人摸不着头脑,无从查起。我在这上面浪费了很多时间。

目录权限设置上要遵循2点:

  1. ChrootDirectory设置的目录权限及其所有的上级文件夹权限,属主和属组必须是root;
  2. ChrootDirectory设置的目录权限及其所有的上级文件夹权限,只有属主能拥有写权限,也就是说权限最大设置只能是755。

如果不能遵循以上2点,即使是该目录仅属于某个用户,也可能会影响到所有的SFTP用户。

				
				
1
2
				
				
chown root.root /home/sftp /home/sftp/homepage /home/sftp/blog /home/sftp/pay
chmod 755 /home/sftp /home/sftp/homepage /home/sftp/blog /home/sftp/pay

由于上面设置了目录的权限是755,因此所有非root用户都无法在目录中写入文件。我们需要在ChrootDirectory指定的目录下建立子目录,重新设置属主和权限。以homepage目录为例:

				
				
1
2
3
				
				
mkdir /home/sftp/homepage/web
chown www.sftp /home/sftp/homepage/web
chmod 775 /home/sftp/homepage/web

要实现web服务器与blog账户互删文件的权限需求,需要设置umask,让默认创建的文件和目录权限为775即可。将下面的内容写入.bashrc中:

				
				
1
				
				
umask 0002

至此,我们已经实现了所有需要的功能

CentOS 7 进入单用户模式图文详解

CentOS 7在进入单用户的时候和6.x做了很多改变,下面让我们来看看如何进入单用户。

在RHEL6(包括之前的版本)恢复root密码的话,只需在启动的时候,编辑下内核启动项,在kernel的最后一行加入s(1|single)就可以进入单用户模式对root密码进行修复。

而到了RHEL7之后是不可以这样操作的。在RHEL7里进入到单用户有rescure,emergency等模式,但还是必须要输入root密码才可以登录。如果要修复root密码只要按照下面的步骤操作:

在开机看到内核条目的时候,按e开始编辑,在kernel的最后加入init=/bin/sh,同时需要去掉rhgb和 quiet参数(必须要去掉),按ctrl+x启动系统,此时无需密码即可进入系统:

1、重启服务器,在选择内核界面使用上下箭头移动

2、选择内核并按“e”

3、找到下面这行,把ro改为rw 在此行最后面加上 init=/bin/bash 当然也可以是 init=/bin/sh

4、修改

这里要删除掉rhgb quiet,如下图

5、使用“ctrl + x” 来重启服务器就可以了,重启后就会进入到单用户

6、退出单用户命令

exec /sbin/init

网上有另外一种方法,我也没有用过,如果哪位童鞋操作了,请给留言下!

1、启动的时候,在启动界面,相应启动项,内核名称上按“e”;
2、进入后,找到linux16开头的地方,按“end”键到最后,输入rd.break,按ctrl+x进入;
3、进去后输入命令mount,发现根为/sysroot/,并且不能写,只有ro=readonly权限;
4、mount -o remount,rw /sysroot/,重新挂载,之后mount,发现有了r,w权限;
5、chroot /sysroot/ 改变根;
(1)echo RedHat|passwd –stdin root 修改root密码为redhat,或者输入passwd,交互修改;
(2)还有就是先cp一份,然后修改/etc/shadow文件
6、touch /.autorelabel 这句是为了selinux生效
7、ctrl+d 退出
8、然后reboot

还有一种:

第一个里程碑 — 在启动GRUB菜单中选择编辑选项,按键  “e”  进入编辑;

第二个里程碑 — 大约在第16行找到 “ro”  将 “ro” 修改为 ” rw init=/sysroot/bin/bash “;

第三个里程碑 — 同时按下 ” ctrl + x “,进入单用户模式;

第四个里程碑  — 用 “chroot /sysroot ” 命令进入系统;

第五个里程碑 — ” passwd root ” 重置root密码;

第六个里程碑 — 用 ” touch /.autorelabel ”  更新SELinux信息;

第七个里程碑 — 输入 ” exit “退出 chroot ;

第八个里程碑 — 用 ” reboot -f  ” 重启你的系统;

第九个里程碑 — 登陆系统测试;

 

参考文档:  https://www.unixmen.com/reset-root-password-centos-7/

redis 3.2.10 安装和主从配置

1. 下载 redis

wget http://download.redis.io/releases/redis-3.2.9.tar.gz

2. 解压

tar xzf redis-3.2.9.tar.gz

3. 进入 src 目录

cd redis-3.2.9

4. make

5. make test && make install

6. 如果出现 tcl 需要安装 yum -y install tcl

7. make install

8.注意 rdb 目录 和 save 配置 ,dir 目录指定文件存档目录, bind 指定ip

9. 修改密码 requirepass 修改

10. 指定启动目录 redis-server /etc/redis.conf

11. slave 机器安装 redis

12. slave 机器 redis.conf 修改 slaveof 和  masterauth

13. 重启

14. info 查看信息

master:

slave:


./redis-cli -p <修改的端口号> -a <修改的密码> shutdown

ffmpeg 文件推流 rtsp和rtmp

// rtsp推流  /opt/srs/srs2

./objs/ffmpeg/bin/ffmpeg -re -i /root/mp4/1.mp4 -vcodec copy -codec copy -f rtsp rtsp://192.168.2.161/live/rtsp_test

// rtmp 推流

./objs/ffmpeg/bin/ffmpeg -re -i /root/mp4/1.flv -vcodec copy -codec copy -f flv rtmp://192.168.2.161/live/rtsp_test

// rtsp推流  /opt/srs/srs2

./objs/ffmpeg/bin/ffmpeg -re -i /root/mp4/1.mp4 -vcodec copy -codec copy -f rtsp rtsp://192.168.2.161/live/rtsp_test

// rtmp 推流./objs/ffmpeg/bin/ffmpeg -re -i /root/mp4/1.flv -vcodec copy -codec copy -f flv rtmp://192.168.2.161/live/rtsp_test

基于Nginx搭建http/rtmp/hls协议的MP4/FLV流媒体服务器

一.搭建nginx平台:
基本是基于网上资料一步步安装nginx搭建流媒体服务器 这篇博客来搭建。
我的ubuntu是14.04LTS。各种包的版本是:
nginx-1.9.9
nginx_mod_h264_streaming-2.2.7.tar.gz
openssl-0.9.8zh.tar.gz
pcre-8.12.tar.gz
zlib-1.2.7.tar.gz
为了支持rtmp,还下载了一个模块nginx-rtmp-module-master,没有版本的区别。
在安装过程中的注意事项:
1.上述无非是./configure make make install.
2.记住如果要修改nginx的./configure的话只用make无需install因为不是覆盖安装。
3.要在sbin的目录下检查./nginx -V 才能看到nginx的配置。
4.nginx在make的时候注意把objs里面的Makefile的权限改成a+w,并且将-Werror删掉,这样就不会把warning看成error来对待。修改makefile是在configure之后make之前。
二.测试http、rtmp、hls的功能
1.配置文件(仅支持http和rtmp)
user  www www;  ##管理用户

worker_processes 30;    ##后台进程

error_log  /usr/local/nginx/logs/error.log;

##nginx错误日志存放路径

pid        /usr/local/nginx/logs/nginx.pid;

events {

use epoll;

##轮训方式

worker_connections      65535;

##允许的最大连接数

}

http {

include       mime.types;

default_type  application/octet-stream;

log_format  main  ‘$remote_addr – $remote_user [$time_local] “$request” ‘

‘$status $body_bytes_sent “$http_referer” ‘

‘”$http_user_agent” “$http_x_forwarded_for”‘;

access_log  /usr/local/nginx/logs/access.log;

sendfile        on;

tcp_nopush     on;

#keepalive_timeout  0;

keepalive_timeout  65;

gzip on;
gzip_min_length 1000;
gzip_buffers 4 8k;
gzip_types text/plain;

server {

listen       80;

server_name  192.168.16.69;
#root html;
root /usr/local/nginx/html/flv_file;

#charset koi8-r;

limit_rate_after 5m;

limit_rate  512k;
index  index.html;
charset utf-8;

#   access_log  /usr/local/nginx/logs/host.access.log  main;

#    location / {

#    root   /usr/local/nginx/html/flv_file;

#            index  index.html;

# limit_rate_after 5m;

# limit_rate  512k;

#error_page  404              /404.html;

location ~ \.flv$ {
#     root /var/www/flv;
flv;
}

location ~ \.mp4$ {
#          root /var/www/mp4;
mp4;
}
}
}
rtmp {
server {
listen 1935;
chunk_size 4000;

# video on demand
application vod {
play /usr/local/nginx/html/flv_file;
}

# HLS
# HLS requires libavformat & should be configured as a separate
# NGINX module in addition to nginx-rtmp-module:
# ./configure … –add-module=/path/to/nginx-rtmp-module/hls …
# For HLS to work please create a directory in tmpfs (/tmp/app here)
# for the fragments. The directory contents is served via HTTP (see
# http{} section in config)
#
# Incoming stream must be in H264/AAC/MP3. For iPhones use baseline #H264
# profile (see ffmpeg example).
# This example creates RTMP stream from movie ready for HLS:
#
# ffmpeg -loglevel verbose -re -i movie.avi  -vcodec libx264
#    -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1
#    -f flv rtmp://localhost:1935/hls/movie
#
# If you need to transcode live stream use ‘exec’ feature.
#
application hls {
hls on;
hls_path /usr/local/nginx/html/flv_file;
hls_fragment 10s;
}
}
}
2.配置文件(可支持http,rtmp,hls)

#filename:nginx.conf

#user  nobody;
worker_processes  1;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;

events {
use epoll;
worker_connections  1024;
}

rtmp {
server {
listen 1935;
chunk_size 4000;

# video on demand
application vod {
play /usr/local/nginx/html/flv_file;
}

# HLS
# HLS requires libavformat & should be configured as a separate
# NGINX module in addition to nginx-rtmp-module:
# ./configure … –add-module=/path/to/nginx-rtmp-module/hls …
# For HLS to work please create a directory in tmpfs (/tmp/app here)
# for the fragments. The directory contents is served via HTTP (see
# http{} section in config)
#
# Incoming stream must be in H264/AAC/MP3. For iPhones use baseline #H264
# profile (see ffmpeg example).
# This example creates RTMP stream from movie ready for HLS:
#
# ffmpeg -loglevel verbose -re -i movie.avi  -vcodec libx264
#    -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1
#    -f flv rtmp://localhost:1935/hls/movie
#
# If you need to transcode live stream use ‘exec’ feature.
#
application hls {
hls on;
hls_path /usr/local/nginx/html/flv_file;
hls_fragment 10s;
}
}
}

http {

include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;

#log format

log_format  access  ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” $http_x_forwarded_for’;

#定义一个名为addr的limit_zone,大小10M内存来存储session
limit_conn_zone $binary_remote_addr zone=addr:10m;

server {
listen 8080;
server_name localhost;

# HTTP can be used for accessing RTMP stats
# This URL provides RTMP statistics in XML
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /home/nairely/Documents/nginxserver/nginx-rtmp-module-master;
}
location /control {
rtmp_control all;
}
location / {
root /home/nairely/Documents/nginxserver/nginx-rtmp-module-master/test/rtmp-publisher;
}
}

server {
listen 80;
server_name localhost;

location / {
root /usr/local/nginx/html/flv_file;
index index.html;
}

location ~ \.flv$ {
root /usr/local/nginx/html/flv_file;
flv;
limit_conn addr 20;
limit_rate 200k;
}
location ~ \.mp4$ {
root /usr/local/nginx/html/flv_file;
mp4;
limit_conn addr 20;
limit_rate 200k;
}

location /hls {
# Serve HLS fragments
alias /usr/local/nginx/html/flv_file;
}

access_log  logs/nginxflv_access.log access;
}
}

3.如果视频不能播放很有可能是权限的问题,设置成644. root(read and write),group(read only)user(read only)
4.nginx作为一个后台服务器,用户从html/flv_file的文件夹中取出视频用户点播。测试的播放器用的是vlc。
http的地址是http://192.168.16.46/yequ.flv
rtmp的地址是rtmp://192.168.16.46:1935/vod/yequ.flv
hls的地址是http://192.168.16.46/hls/sample.m3u8(在segment命令将output的URL设置为http://192.168.16.46/hls)将sample.m3u8文件放在html/flv_file文件夹下,当然这取决与segment语句在哪个地址下进行。
5.如何启动nginx:
cd /usr/local/nginx/sbin
./nginx -t 检查配置文件的语法问题
如果发现配置文件的路径不对
./nginx -c 路径
./nginx -s reload重新加载配置文件
killall -9 nginx 杀掉所有进程从头开始,如果遇到端口被占用的问题的话。
./nginx 启动,注意在杀掉进程之后一定要重新启动。
service nginx start
三.配置hls+ffmpeg的环境
在配置http和rtmp都比较简单。在搭建nginx平台的前提下就可以实现点播。配置hls出现的问题都比较简单。只是会花一段时间。
主要的配置还是根据这篇来的http://www.lc365.net/blog/b/31519/ 基于HTTP Live Streaming(HLS) 搭建在线点播系统
这些包实在太多了,我简直属于无聊的阶段。
1.faac的编译问题
http://zhidao.baidu.com/link?url=ASyVwiBE-01ox_O0QascgPdqNNRlXpHCfI6cXyg71JIboOK5MTj3NLfHUPC31HH5b0FiE3tbWUetUfKL29HAzzXu4q0p75Iveu05HPp_ST3

2.在编译ffmpeg的时候发现x264notfound的解决方法
在x264的./configure –enable-static –enable-shared
–enable-visualize –system-libx264 –enable-gprof –enable-strip
–enable-pic –enable-debug
就是把所以的开关都打开。这简直是误打误撞。
3.m3u8configure的时候总是会遇到error的问题,可以看到这些错误都是什么东西过时的啥的,直接换ffmpeg。换ffmpeg版本到最新。ffmpeg-2.8.4
git clone https://github.com/johnf/m3u8-segmenter
cd m3u8-segmenter
然后configure的时候
gcc -Wall -g m3u8-segmenter.c -o segmenter -lavformat -lavcodec -lavutil
cp segmenter /usr/bin/
在html/flv_file路径下
ffmpeg -i /var/flvs/baluobu.flv  -f mpegts -acodec libmp3lame -ar
48000 -ab 128k -vcodec libx264 -b 96k -flags +loop -cmp +chroma
-partitions +parti4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 1
-coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71
-bt 200k -maxrate 96k -bufsize 96k -rc_eq ‘blurCplx^(1-qComp)’ -qcomp
0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 320:240 -g 30 -async 2
/var/app/baluobu/baluobu.ts
上述是把flv文件转换成ts文件
下面用segmenter命令将ts转换成10秒一个ts切片,segmenter_test是ts小切片的前缀,-u制定URL地址。
segmenter -i vp5.ts -d 10 -p segmenter_test -m vp5.m3u8 -u http://192.168.16.46/hls/
在segmenter的时候有一个红色的ignore,之前一直认为是一个error,我去才发现是一个不用管的东西,然后在vlc上用http://192.168.16.46/hls/vp5.m3u8放,其实类似一个直播的功能,播完了就没有ts文件了。
再来一次测试就得再来一遍ffmpeg和segmenter.
总结到这儿。