nginx搭建flv和mp4流媒体服务器

准备软件:
nginx-1.6.0.tar.gz
yamdi-1.9.tar.gz

yamdi 是渐进式流支持模块,抓取视频资源关键帧实现播放时的随意拖动效果
下载地址:http://ncu.dl.sourceforge.net/project/yamdi/yamdi/1.9/yamdi-1.9.tar.gz

flv视频可以通过http或rtmp方式发布。这里用http方式。

安装nginx及mp4支持模块和flv模块:
nginx支持mp4模块下载地址:http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
下载后解压。

安装编译环境:

[root@localhost nginx-1.6.0]# yum install -y zlib zlib-devel pcre pcre-devel
[root@localhost nginx-1.6.0]# useradd -s /sbin/nologin www
[root@localhost nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --add-module=../nginx_mod_h264_streaming-2.2.7 --with-http_ssl_module --user=www --group=www --with-http_flv_module --with-http_stub_status_module
[root@localhost nginx-1.6.0]# make && make install

make -f objs/Makefile
make[1]: Entering directory `/root/nginx-1.6.0′
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -D_LARGEFILE_SOURCE -DBUILDING_NGINX -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I src/mail \
-o objs/addon/src/ngx_http_h264_streaming_module.o \
../nginx_mod_h264_streaming-2.2.7/src/ngx_http_h264_streaming_module.c
In file included from ../nginx_mod_h264_streaming-2.2.7/src/ngx_http_h264_streaming_module.c:2:
../nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c: In function ‘ngx_streaming_handler’:
../nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c:158: error: ‘ngx_http_request_t’ has no member named ‘zero_in_uri’
make[1]: *** [objs/addon/src/ngx_http_h264_streaming_module.o] Error 1
make[1]: Leaving directory `/root/nginx-1.6.0′
make: *** [build] Error 2

出现一个错误,解决方法:

编辑/root/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c

[root@localhost src]# vim ngx_http_streaming_module.c

注释掉:
/* TODO: Win32 */
if (r->zero_in_uri)
{
return NGX_DECLINED;
}

重新make通过。

nginx配置文件:
[root@localhost nginx-1.6.0]# grep -v “#” /usr/local/nginx/conf/nginx.conf | grep -v “^$”

worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root /usr/local/nginx/html;

location ~\.flv {
flv;
}

location ~\.mp4$ {
mp4;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

创建两个视频文件夹/usr/local/nginx/html/flv、/usr/local/nginx/html/mp4 存放视频文件。

安装yamdi实现拖动效果:
[root@localhost yamdi-1.9]# make && make install  #两步即可

给视频添加帧:
[root@localhost flv]# yamdi -i 1.flv -o test.flv  #给1.flv添加关键帧输出为test.flv

找一个flash播放器,下载地址:http://chinaapp-wordpress.stor.sinaapp.com/uploads/2013/08/player.swf   推荐wget方式下载。
测试:
浏览器访问: http://192.168.0.172/player.swf?type=http&file=flv/test.flv

192.168.0.172 #服务器ip地址
player.swf       #flash播放器程序
http                  #用http方式发布
flv                     #为路径
test.flv             #为视频文件

Linux下搭建iSCSI服务器

这里用esxi虚拟化中的虚拟机测试,添加一块200G的硬盘。
selinux、iptables 关闭

[root@localhost ~]# fdisk -l  #对新硬盘创建分区,不用挂载。

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8d42c5ad

Device Boot Start End Blocks Id System
/dev/sdb1 1 26108 209712478+ 83 Linux

安装scsi target:
[root@localhost ~]# yum install -y scsi-target-utils

配置文件及命令:
/etc/tgt/targets.conf       主配置文档,设置要分享的磁盘
/usr/sbin/tgt-admin       线上查询、删除target 等功能的管理工具
/usr/sbin/tgt-setup-lun 建立target 以及设置分享的磁盘与可使用的用户端等工具软体
/usr/sbin/tgtadm            手动直接管理的管理员工具(可使用配置文档取代)
/usr/sbin/tgtd                 主要提供iSCSI target 服务的主程式
/usr/sbin/tgtimg             建置预计分享的映像档装置的工具(以映像档模拟磁盘)

编辑配置文件:
[root@localhost ~]# vi /etc/tgt/targets.conf

default-driver iscsi
<target iqn.2015-01.org.rootop:scsi1>
backing-store /dev/sdb1
initiator-address 192.168.0.16
incominguser admin admin123456789
</target>

target                      #目标名称
backing-store       #存储设备
initiator-address #限制来源IP
incominguser       #身份认证

重启tgtd服务:
[root@localhost ~]# service tgtd restart
[root@localhost ~]# chkconfig tgtd on

查看iscsi信息:

客户端挂载:

在 ESXi“192.168.0.150”上调用对象 “storageSystem”的“HostStorageSystem.ComputeDiskPartitionInfo” 失败。

在esxi5.5上添加ip-san,提示错误:

在 ESXi“192.168.0.150”上调用对象 “storageSystem”的“HostStorageSystem.ComputeDiskPartitionInfo” 失败。

后来查到是因为已经有了分区(之前挂载到windows下),后来找了台windows重新挂载上去,删掉分区。重新在esxi中添加。
或者是登陆到esxi主机执行命令删掉分区。
先在vsphere client中开启esxi的ssh。

#列出连接的iscsi设备

~ # esxcfg-scsidevs -l

#获取设备磁盘信息

~ # partedUtil get /dev/disks/t10.FreeBSD_iSCSI_Disk______005056bf230c000_______
13054 255 63 209715200
1 2048 209713151 0 0 #分区1

#删除分区

~ # partedUtil delete /dev/disks/t10.FreeBSD_iSCSI_Disk______005056bf230c000_________________ 1
~ # partedUtil #几个参数
Not enough arguments

Usage:
 Get Partitions : get <diskName>
 Set Partitions : set <diskName> ["partNum startSector endSector type attr"]*
 Delete Partition : delete <diskName> <partNum>
 Resize Partition : resize <diskName> <partNum> <start> <end>

解决

haproxy安装配置及测试

系统版本:centos6.5_x64
软件版本:haproxy-1.5.9.tar.gz
后端服务器IP:10.10.10.5、10.10.10.6

这里提供haproxy的本站下载地址:wget -c https://www.rootop.org/rs/haproxy-1.5.9.tar.gz

安装:

[root@rootop-haproxy haproxy-1.5.9]# make TARGET=linux26 PREFIX=/usr/local/haproxy install

这里为什么是linux26,可以去看下README文档。

创建配置文件:
[root@rootop-haproxy ~]# mkdir /usr/local/haproxy/conf
[root@rootop-haproxy ~]# vi /usr/local/haproxy/conf/haproxy.cfg

global
    log 127.0.0.1 local0 info
    maxconn 1000
    chroot /usr/local/haproxy
    uid nobody
    gid nobody
    daemon
    nbproc 1
    pidfile /tmp/haproxy.pid

defaults
    log global
    mode http
    option httplog
    retries 3
    option httpclose
    option dontlognull
    option forwardfor
    option redispatch
    log 127.0.0.1 local3
    balance roundrobin
    maxconn 20480
    timeout connect 5000
    timeout client 50000
    timeout server 50000
    timeout check 2000

    stats enable
    stats refresh 30s
    stats uri /ha_check
    stats hide-version
    stats auth admin:admin

frontend http-in
    bind *:80
    mode http
    option httplog
    log global
    default_backend http_pool

backend http_pool
    balance roundrobin
    option httpchk HEAD /index.html HTTP/1.0
    cookie SERVERID insert indirect
    server WEBSRV1 10.10.10.5:80 maxconn 1500 cookie SRV1 check inter 2000 rise 2 fall 3 weight 1
    server WEBSRV2 10.10.10.6:80 maxconn 1500 cookie SRV2 check inter 2000 rise 2 fall 3 weight 1

启动服务:
[root@rootop-haproxy ~]# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg

stats uri /status #监控页面
stats auth admin:admin #监控页身份认证

提供一个管理脚本:

#!/bin/bash
PROXY_CONF=/usr/local/haproxy/conf/haproxy.cfg
PROXY_BIN=/usr/local/haproxy/sbin/haproxy
CHECK_PROXY=$(ps aux | grep "haproxy -f" | grep -v grep | wc -l)

case $1 in

        start)
        if [ $CHECK_PROXY -ge 1 ]; then
                echo "already running , exit"
                exit
        else
        $PROXY_BIN -f $PROXY_CONF
                if [ $? == 0 ]; then
                        echo "start ok"
                else
                        echo "start failed"
                fi
        fi
        ;;

        stop)
        kill -9 $(cat /tmp/haproxy.pid)
                if [ $? == 0 ]; then
                        rm -f /tmp/haproxy.pid && echo "stop ok"
                else
                        echo "stop failed"
                fi
        ;;

        restart)
        kill -9 $(cat /tmp/haproxy.pid)
                if [ $? == 0 ]; then
                        rm -f /tmp/haproxy.pid && echo "stop ok"
                else
                        echo "stop failed"
                fi

        $PROXY_BIN -f $PROXY_CONF
                if [ $? == 0 ]; then
                        echo "start ok"
                else
                        echo "start failed"
                fi
        ;;

        *)
        echo "only start/stop/restart"
esac

exit

然后通过多个客户端访问haproxy的ip地址可以看到后端不同服务器提供的内容。

cookie SERVERID insert indirect  其中这句设置了会话保持,通过插入cookie方式,测试效果。

访问到服务器1:

访问到服务器2:

浏览器关闭后,会话断开。

试用Microsoft Azure 微软云计算平台

Microsoft Azure 是一个开放且灵活的云平台,通过该平台,您可以在 Microsoft 管理的数据中心的全球网络中快速构建、部署和管理应用程序。

官方网站:http://www.windowsazure.cn/  说由世纪互联公司运营,最近提供免费试用,申请了个账户,试用30天。

在里面创建了两个虚拟机,一个server 2012 一个openlogic。 可以看到后面有一个DNS名称,这个就是用来访问的地址,通过这个域名解析出来的ip就是虚拟机的ip。

远程登陆windows:

点击虚拟机,点下面的连接,会弹出来下载提示,这里下载了一个 test.rdp 文件,也就是远程桌面的配置文件,直接双击连接,输入创建虚拟机时的用户名和密码即可登陆。还有一种方法就是直接利用系统的远程桌面连接,输入 dns名称:52555 ,端口为52555,这个端口号是端点中定义的,映射为系统的3389,提高了安全性。登陆为管理员权限。在里面安装了一个iis,发布服务。这里需要在端点中放行80端口。openstack中记得叫安全访问。

下面那个勾还没搞明白,第一次勾选了最后一个复选框,结果发布的iis服务访问不到,删掉重新创建端点。负载平衡集,类似于阿里云的SLB,应该是四层或七层代理。

访问linux虚拟机openlogic (一个衍生rhel的再编译产物):

通过DNS名称解析出来的ip即为服务器ip。通过域名或者ip访问都行,输入创建虚拟机时创建的账户,我这里在创建虚拟机时没有导入密钥。直接密码登陆,修改root密码。

sudo passwd root   #修改root密码

安装nginx,启动nginx服务,关闭系统自带防火墙,在虚拟机端点中放行80端口。

[root@openlogic7 ~]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service

还有其它功能,比如hadoop,cdn,SQL等。使用起来感觉比较繁琐。想熟悉azure平台得可以注册个账户熟悉一下。