yum方式安裝html
wget https://openresty.org/package/centos/openresty.reponginx
mv openresty.repo /etc/yum.repos.d/docker
ll /etc/yum.repos.d/vim
yum list | grep openresty centos
yum install -y openresty.x86_64緩存
service openresty status負載均衡
service openresty startlua
/usr/local/openresty/nginx/sbin/nginx -vcentos7
vim /usr/local/openresty/nginx/conf/nginx.confspa
/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方式安裝
一、拉取鏡像
docker images
docker pull openresty/openresty:1.19.3.1-centos7
二、先啓動一個做出配置文件
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/
三、刪除舊容器
docker stop openresty
docker rm openresty
docker ps -a
四、啓動 指定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; } }
六、從新加載配置或者重啓openresty
docker exec -it openresty nginx -s reload
修改容器所佔最大內存
docker update -m 1G --memory-swap 1G openresty
七、下面是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