2021年11月

安装依赖

yum install libmaxminddb-devel -y
git clone https://github.com/arut/nginx-rtmp-module.git #也可以下载zip文件,解压

先不要安装nginx,如果已经安装请先卸载
安装选择编译安装,在自定义模板里输入

--add-module=/www/server/nginx-rtmp-module

安装完成,新建站点live.liugang.net,并新建live目录,然后配置nginx,重载配置

rtmp {   
     
    server {   
        listen 1935;  #监听的端口 ,可以改为你自己喜欢的端口号,记得在宝塔后台放行此端口!!!
        chunk_size 4000;      
        application hls {  #rtmp推流请求路径 
            live on;   
            hls on;   
            hls_path /www/wwwroot/live.liugang.net/live;   #这个目录就是推流文件存储的位置
            hls_fragment 2s;         #本地切片长度
            hls_playlist_length 6s;  #HLS播放列表长度
        }   
    }   
} 

配置就完成了
推流地址 rtmp://ip:1935/hls
推流密钥 index
播放地址 http://live.liugang.net/live/index.m3u8

土豪绕道,土豪可以使用共享带宽、多核CPU、高内存、云盘等……
本文主要讨论如何充分使用多个性能低下与主机。为什么买配置低的?因为作者穷啊,考虑到性价比
双11主机上搞活动,云主机特别便宜,入手了10台入门云主机,每台10台1核1G2M,50G硬盘的配置,10台就有10个独立ip,20M带宽,500G硬盘,想想20M带宽可不便宜,就想着充分利用这些带宽

下面是使用nginx负载均衡搭建静态服务器的配置,大家有什么好的建议

定义上服务器,用一致性哈希hash consistent,可以充分利用硬盘,不同请求的 url文件会缓存到不同的服务器磁盘

upstream backend { 
hash $uri consistent;   
server 10.5.245.1:30018;
server 10.5.245.2:30018;
server 10.5.245.3:30018;
server 10.5.245.4:30018;
server 10.5.245.5:30018;
server 10.5.245.6:30018;
server 10.5.245.7:30018;
server 10.5.245.8:30018;
server 10.5.245.9:30018;
server 10.5.245.10:30018;
} 

nginx反向代理,如何是内网ip请求,则缓存文件,

#PROXY-START/

location ^~ /oss/
{
    proxy_pass http://www.liugang.net/;
    proxy_set_header Host www.liugang.net;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    


    add_header X-Cache $upstream_cache_status;
    #Set Nginx Cache

    proxy_ignore_headers Set-Cookie Cache-Control expires;
    proxy_cache cache_one;
    if ($ckey = ""){
    set $ckey $uri;
    }
    proxy_cache_key $ckey;
    proxy_cache_valid 200 304 301 302 30d;

}
location ^~ /  
{
    if ($proxy_add_x_forwarded_for ~* "10.5.245.")
    {
         set $ckey $uri;
        rewrite ^/(.*) /oss/$1 last;
    }
    proxy_pass http://backend/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    expires 24h;

}
#PROXY-END/

充分利用带宽,可以在域名解析时候添加10个A记录指向不同的ip即可

PUT /my_index
{
    "settings": {
        "analysis": {
            "char_filter": {
                "&_to_and": {
                    "type":       "mapping",
                    "mappings": [ "&=> and "]
            }},
            "filter": {
                "my_stopwords": {
                    "type":       "stop",
                    "stopwords": [ "the", "a" ]
            },
       "my_synonym_filter": {
          "type": "synonym", 
          "synonyms": [ 
            "british,english",
            "queen,monarch"
          ]
        }},
            "analyzer": {
                "my_analyzer": {
                    "type":         "custom",
                    "char_filter":  [ "html_strip", "&_to_and" ],
                    "tokenizer":    "standard",
                    "filter":       [ "lowercase", "my_stopwords","my_synonym_filter"]
            }}
}}}

master端:

--binlog-do-db 二进制日志记录的数据库(多数据库用逗号,隔开)
--binlog-ignore-db 二进制日志中忽略数据库 (多数据库用逗号,隔开)

以下是mysql主从忽略授权表的方法案例:
in master:
binlog-do-db=YYY 需要同步的数据库。不添加这行表示同步所有
binlog-ignore-db = mysql 这是不记录binlog,来达到从库不同步mysql库,以确保各自权限
binlog-ignore-db = performance_schema
binlog-ignore-db = information_schema

slave端
--replication-do-db 设定需要复制的数据库(多数据库使用逗号,隔开)
--replication-ignore-db 设定需要忽略的复制数据库 (多数据库使用逗号,隔开)
--replication-do-table 设定需要复制的表
--replication-ignore-table 设定需要忽略的复制表
--replication-wild-do-table 同replication-do-table功能一样,但是可以通配符
--replication-wild-ignore-table 同replication-ignore-table功能一样,但是可以加通配符