#!/bin/sh
cd /etc/yum.repos.d? #
mv CentOS-Base.repo ./CentOS-Base.repo.backup? #移動(dòng)(規(guī)范)
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo? #換源 安裝東西就到它這下面找
yum makecache? #安裝makecache(同步服務(wù)器上的緩存)這個(gè)包
yum update -y? #更新升級(jí)
yum install git gcc make pcre-devel openssl-devel? #安裝git gcc make pcre-devel openssl-devel這些包
cd /usr/local/? #到時(shí)local下
git clone git://github.com/arut/nginx-rtmp-module.git? #擴(kuò)展包
wget http://nginx.org/download/nginx-1.15.0.tar.gz? #安裝nginx源碼壓縮包
tar xzf nginx-1.15.0.tar.gz? #解壓源碼包
cd nginx-1.15.0
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module #編譯文件
make && make install? ? #創(chuàng)建并安裝它建立makefile文件
cd ../nginx/sbin/
./nginx -V? #查看版本號(hào)
./nginx
./nginx? #第二次查看啟動(dòng)沒
systemctl stop firewalld.service? ? ? # 關(guān)防火墻
firewall-cmd --state? ? ? ? ? ? ? ? ? # 查看防火墻狀態(tài)not running
#修改Nginx的conf文件 配置rtmp端口 1935端口
cat >/usr/local/nginx/conf/nginx.conf<<EOF? ? ?
#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 {
? ? worker_connections? 1024;
}
rtmp{
? server{
? ? ? ? listen 1935;
? ? ? ? chunk_size 5000;
? ? ? ? application hls{
? ? ? ? live on;
? ? ? ? hls on;
? ? ? ? record off;
? ? ? ? hls_path /usr/local/nginx/html/hls;
? ? ? ? hls_fragment 3s;
? ? ? ? }
? ? }
}
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? logs/access.log? main;
? ? sendfile? ? ? ? on;
? ? #tcp_nopush? ? on;
? ? #keepalive_timeout? 0;
? ? keepalive_timeout? 65;
? ? #gzip? on;
? ? server {
? ? ? ? listen? ? ? 80;
? ? ? ? server_name? localhost;
? ? ? ? #charset koi8-r;
? ? ? ? #access_log? logs/host.access.log? main;
? ? ? ? location / {
? ? ? ? ? ? root? html;
? ? ? ? ? ? index? index.html index.htm;
? ? ? ? }
location /hls {?
? ? ? ? #server hls fragments?
? ? ? ? types{?
? ? ? ? ? application/vnd.apple.mpegurl m3u8;?
? ? ? ? ? video/mp2t ts;?
? ? ? ? }?
? ? ? ? alias /temp/hls;?
? ? ? ? expires -1;?
? ? ? ? }
? ? ? ? #error_page? 404? ? ? ? ? ? ? /404.html;
? ? ? ? # redirect server error pages to the static page /50x.html
? ? ? ? #
? ? ? ? error_page? 500 502 503 504? /50x.html;
? ? ? ? location = /50x.html {
? ? ? ? ? ? root? html;
? ? ? ? }
? ? ? ? # proxy the PHP scripts to Apache listening on 127.0.0.1:80
? ? ? ? #
? ? ? ? #location ~ \.php$ {
? ? ? ? #? ? proxy_pass? http://127.0.0.1;
? ? ? ? #}
? ? ? ? # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
? ? ? ? #
? ? ? ? #location ~ \.php$ {
? ? ? ? #? ? root? ? ? ? ? html;
? ? ? ? #? ? fastcgi_pass? 127.0.0.1:9000;
? ? ? ? #? ? fastcgi_index? index.php;
? ? ? ? #? ? fastcgi_param? SCRIPT_FILENAME? /scripts$fastcgi_script_name;
? ? ? ? #? ? include? ? ? ? fastcgi_params;
? ? ? ? #}
? ? ? ? # deny access to .htaccess files, if Apache's document root
? ? ? ? # concurs with nginx's one
? ? ? ? #
? ? ? ? #location ~ /\.ht {
? ? ? ? #? ? deny? all;
? ? ? ? #}
? ? }
? ? # another virtual host using mix of IP-, name-, and port-based configuration
? ? #
? ? #server {
? ? #? ? listen? ? ? 8000;
? ? #? ? listen? ? ? somename:8080;
? ? #? ? server_name? somename? alias? another.alias;
? ? #? ? location / {
? ? #? ? ? ? root? html;
? ? #? ? ? ? index? index.html index.htm;
? ? #? ? }
? ? #}
? ? # HTTPS server
? ? #
? ? #server {
? ? #? ? listen? ? ? 443 ssl;
? ? #? ? server_name? localhost;
? ? #? ? ssl_certificate? ? ? cert.pem;
? ? #? ? ssl_certificate_key? cert.key;
? ? #? ? ssl_session_cache? ? shared:SSL:1m;
? ? #? ? ssl_session_timeout? 5m;
? ? #? ? ssl_ciphers? HIGH:!aNULL:!MD5;
? ? #? ? ssl_prefer_server_ciphers? on;
? ? #? ? location / {
? ? #? ? ? ? root? html;
? ? #? ? ? ? index? index.html index.htm;
? ? #? ? }
? ? #}
}
EOF
#增加
cat >/usr/local/nginx/html/play.html<<EOF
<!DOCTYPE html>
<html lang="en">
<head>
? ? <meta charset="UTF-8">
? ? <meta name="viewport" content="width=device-width, initial-scale=1.0">
? ? <meta http-equiv="X-UA-Compatible" content="ie=edge">
? ? <title>PC HLS video</title>
? ? <link rel="stylesheet">
</head>
<body>
<h1>PC 端播放 HLS(<code>.m3u8</code>) 視頻</h1>
<p>借助 video.js 和 videojs-contrib-hls</p>
<p>由于 videojs-contrib-hls 需要通過 XHR 來獲取解析 m3u8 文件, 因此會(huì)遭遇跨域問題, 請(qǐng)?jiān)O(shè)置瀏覽器運(yùn)行跨域</p>
<video id="hls-video" width="300" height="200" class="video-js vjs-default-skin"
? ? ? playsinline webkit-playsinline
? ? ? autoplay controls preload="auto"
? ? ? x-webkit-airplay="true" x5-video-player-fullscreen="true" x5-video-player-typ="h5">
? ? <!-- 直播的視頻源 -->
? ? <source src="http://ivi.bupt.edu.cn/hls/cctv13.m3u8" type="application/x-mpegURL">
? ? <!-- 點(diǎn)播的視頻源 -->
? ? <!--<source src="http://devstreaming.apple.com/videos/wwdc/2015/413eflf3lrh1tyo/413/hls_vod_mvp.m3u8" type="application/x-mpegURL">-->
</video>
<script src="http://cdn.bootcss.com/video.js/6.0.0-RC.5/video.js"></script>
<!-- PC 端瀏覽器不支持播放 hls 文件(m3u8), 需要 videojs-contrib-hls 來給我們解碼 -->
<script src="http://cdn.bootcss.com/videojs-contrib-hls/5.3.3/videojs-contrib-hls.js"></script>
<script>
? ? // XMLHttpRequest cannot load http://xxx/video.m3u8. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.198.98:8000' is therefore not allowed access.
? ? // 由于 videojs-contrib-hls 需要通過 XHR 來獲取解析 m3u8 文件, 因此會(huì)遭遇跨域問題, 請(qǐng)?jiān)O(shè)置瀏覽器運(yùn)行跨域
? ? var player = videojs('hls-video');
? ? player.play();
</script>
</body>
</html>
EOF
cd /usr/local/nginx/conf
/usr/local/nginx/sbin/nginx -s stop? #停止服務(wù)
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf? #啟動(dòng)服務(wù)
/usr/local/nginx/sbin/nginx? ? #查看是否城功
#OBS推流機(jī) rtmp://主機(jī)ip地址:1935/oldboy_live? room01 room02
#google瀏覽器上 輸 自己IP/play.html