bingooyong / note

1 stars 1 forks source link

整理一下Openresty安装 #17

Open bingooyong opened 5 years ago

bingooyong commented 5 years ago

编译安装

yum -y install pcre-devel openssl-devel gcc curl
tar xzf openresty-1.11.2.5.tar.gz && cd openresty-1.11.2.5
./configure --prefix=/home/footstone/openresty \
            --with-pcre-jit \
            --with-ipv6 \
            --without-http_redis2_module \
            --with-http_realip_module \
            --with-http_ssl_module \
            --with-http_stub_status_module \
            --with-http_v2_module \
            -j2
gmake -j2 && gmake install

配置开机自启

添加脚本

cat >  /usr/lib/systemd/system/nginx.service <<'EOF'
[Unit]
Description=full-fledged web platform
After=network.target

[Service]
User=footstone
Group=footstone
Type=forking
PIDFile=/home/footstone/openresty/nginx/logs/nginx.pid
ExecStartPre=/home/footstone/openresty/nginx/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/home/footstone/openresty/nginx/sbin/nginx -g 'daemon on; master_process on;'
ExecStartPost=/bin/sleep 0.1
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
TimeoutStopSec=5
KillMode=mixed

[Install]
WantedBy=multi-user.target
EOF

生效脚本

systemctl daemon-reload
systemctl enable nginx
systemctl start nginx
systemctl reload nginx
#查看状态
systemctl status nginx
#日志
journalctl -f -u nginx.service

配置日志切割

cat > /etc/logrotate.d/openresty <<'EOF'
/home/footstone/openresty/nginx/logs/*log {
    su root footstone
    create 0644 footstone footstone
    daily
    rotate 7
    missingok
    notifempty
    compress
    sharedscripts
    dateext
    postrotate
        /bin/kill -USR1 `cat /home/footstone/openresty/nginx/logs/nginx.pid 2>/dev/null` 2>/dev/null || true
    endscript
}
EOF

手动测试下脚本

验证脚本合法性

logrotate -d -f /etc/logrotate.d/openresty

手动执行下后方可自动生效

logrotate -f /etc/logrotate.d/openresty

其他命令

systemctl list-unit-files| grep nginx
shuvigoss commented 5 years ago

OSX下手动安装openresty 由于brew默认无法指定模块,所以需要手动安装

brew install pcre openssl


./configure \
--with-cc-opt="-I/usr/local/opt/openssl/include/ -I/usr/local/opt/pcre/include/" \
--with-ld-opt="-L/usr/local/opt/openssl/lib/ -L/usr/local/opt/pcre/lib/" \
--with-pcre-jit \
--with-ipv6 \
--without-http_redis2_module \
--with-http_realip_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_v2_module \
-j8

make -j8 && make install