openresty——yum安装 配置 使用 错误处理 docker方式安装

yum方式安装

wget https://openresty.org/package/centos/openresty.repo

mv openresty.repo /etc/yum.repos.d/

ll /etc/yum.repos.d/

yum list | grep openresty 

yum install -y openresty.x86_64

service openresty status

service openresty start

/usr/local/openresty/nginx/sbin/nginx -v

vim /usr/local/openresty/nginx/conf/nginx.conf

/usr/local/openresty/nginx/sbin/nginx -s reload

支持lua 配置文件添加

 #lua 缓存(每次修改lua后需要重启)默认是开启 on , 开发阶段建议关闭,生产环境必须开启 
    lua_code_cache on;
    lua_package_path  "/root/data/acgn/game_res/?.lua;/root/data/acgn/game_res/script/?.lua;/root/data/acgn/game_res/serverbattle/src/?.lua;;"; #lua 模块   
    server {
        listen       8009;
        server_name  localhost;

        client_max_body_size 50m;
        client_body_buffer_size 10m;

        location /battle_callback {
            default_type text/plain;
            content_by_lua_file /root/data/acgn/game_res/blaze_battle.lua;
        }

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

 

报错

tail -f /usr/local/openresty/nginx/logs/error.log

tail -f /usr/local/openresty/nginx/logs/error.log
2021/05/26 17:19:14 [error] 83655#83655: *6 failed to load external Lua file "/root/data/acgn/game_res/blaze_battle.lua": cannot open /root/data/acgn/game_res/blaze_battle.lua: Permission denied, client: 192.168.1.51, server: localhost, request: "GET /battle_callback HTTP/1.1", host: "192.168.1.20:8009"
2021/05/26 17:19:26 [error] 83655#83655: *7 failed to load external Lua file "/root/data/acgn/game_res/blaze_battle.lua": cannot open /root/data/acgn/game_res/blaze_battle.lua: Permission denied, client: 192.168.1.51, server: localhost, request: "POST /battle_callback HTTP/1.1", host: "192.168.1.20:8009"

原因: nginx进程所属用户nobody

[root@bogon acgn]# ps -ef | grep nginx
root      15795      1  0 May25 ?        00:00:00 nginx: master process /usr/local/openresty/nginx/sbin/nginx
nobody    83709  15795  0 17:19 ?        00:00:00 nginx: worker process
root      83736  36201  0 17:20 pts/0    00:00:00 grep --color=auto nginx

vim /usr/local/openresty/nginx/conf/nginx.conf

把 user nobody 改为 user root

/usr/local/openresty/nginx/sbin/nginx -s reload

解决。

 

 

下面是docker方式安装

1、拉取镜像

docker images
docker pull openresty/openresty:1.19.3.1-centos7

2、先启动一个作出配置文件

docker run -d --name openresty \
              -p 8009:8009 \
              openresty/openresty:1.19.3.1-centos7
做目录
tree /root/data/soft/openresty
    /root/data/soft/openresty
    ├── conf
    ├── logs
    └── lua
docker cp openresty:/usr/local/openresty/nginx/conf/nginx.conf /root/data/soft/openresty/conf/

3、删除旧容器

docker stop openresty
docker rm openresty
docker ps -a

4、启动 指定nginx.conf  lua路径  logs路径

lua_code_cache on;
lua_package_path  "/lua/acgn/game_res/?.lua;/lua/acgn/game_res/script/?.lua;lua/acgn/game_res/serverbattle/src/?.lua;;"; #lua 模块   
server {
    listen       8009;
    server_name  localhost;

    client_max_body_size 50m;
    client_body_buffer_size 10m;

    location /battle_callback {
        default_type text/plain;
        content_by_lua_file /lua/acgn/game_res/blaze_battle.lua;
    }

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

6、重新加载配置或者重启openresty

docker exec -it openresty nginx -s reload
修改容器所占最大内存 docker update
-m 1G --memory-swap 1G openresty

 

7、下面是HAProxy负载均衡配置

在三台机器  192.168.1.20   192.168.1.21  192.168.1.22 各部署一个openresty,用HAProxy作负载均衡

vim /etc/haproxy/haproxy.cfg 

#openresty for battle check
listen acgn_battle
   bind 0.0.0.0:8008
   mode http
   balance roundrobin
   server battle1 192.168.1.20:8009
   server battle2 192.168.1.21:8009
   server battle3 192.168.1.22:8009

service haproxy restart

service haproxy status

posted @ 2021-05-25 19:46  会飞的斧头  阅读(518)  评论(0编辑  收藏  举报