這里簡(jiǎn)單記錄下 nginx / php-fpm
日常使用到的一些命令和命令背后的故事筐钟。先說nginx
:
測(cè)試下指定配置是否存在錯(cuò)誤:
nginx -t -c /usr/local/conf/nginx.conf
測(cè)試默認(rèn)的nginx配置文件
nginx -t
啟動(dòng)nginx:
nginx -c /usr/local/conf/nginx.conf
平滑重啟nginx
:
nginx
收到HUP信號(hào)之后赤嚼,重啟過程中nginx
會(huì)檢測(cè)修改的配置文件是否正確,如果不正確遥赚,新的work
不會(huì)創(chuàng)建交汤,舊的進(jìn)程將繼續(xù)工作剃幌。配置文件沒有問題,就先啟動(dòng)新的work
税肪,同時(shí)通知舊的work
關(guān)閉監(jiān)聽套接字溉躲,但已經(jīng)存在的連接繼續(xù)服務(wù),直到所有舊連接處理完成益兄,舊work
就退出了锻梳。
nginx -s reload
后者 sudo kill -HUP 'cat /usr/local/var/run/nginx.pid'
停止nginx:
直接干掉 pkill -9 nginx
從容停止 kill -QUIT 主進(jìn)程號(hào)
快速停止 kill -TERM 主進(jìn)程號(hào)
平滑升級(jí)nginx:
nginx
升級(jí)官方建議使用自動(dòng)升級(jí),其實(shí)半自動(dòng)升級(jí)偏塞。
[root@tm /data/nginx-1.10.1]# ./configure --prefix=/usr/local/nginx
[root@tm /data/nginx-1.10.1]#make
[root@tm /data/nginx-1.10.1]#cp objs/nginx /usr/local/nginx/sbin
[root@tm /data/nginx-1.10.1]#ps -ef | grep nginx
[root@tm ~/nginx/nginx-1.10.1]#ps -ef | grep nginx
root 20634 1 0 18:04 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 20635 20634 0 18:04 ? 00:00:00 nginx: worker process
root 20641 15050 0 18:04 pts/0 00:00:00 grep --color=auto nginx
[root@tm ~/nginx/nginx-1.10.1]#cat Makefile // 瞅瞅makefie文件
default: build
clean:
rm -rf Makefile objs
build:
$(MAKE) -f objs/Makefile
install:
$(MAKE) -f objs/Makefile install
upgrade:
/usr/local/nginx/sbin/nginx -t
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
[root@tm ~/nginx/nginx-1.10.1]#make upgrade
[root@tm ~/nginx/nginx-1.10.1]#ps -ef | grep nginx
[root@tm /usr/local/nginx/sbin]#./nginx -V
nginx version: nginx/1.10.1
這里順便給出一個(gè)添加nginx
到systemctl
服務(wù)管理里面,這樣上面的啟動(dòng)唱蒸,重啟,停止都可以通過systemctl
來管理了,在/lib/systemd/system下面增加一個(gè)nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
再來看下php-fpm
:
測(cè)試配置文件是否正常:
/usr/local/php/sbin/php-fpm -t
啟動(dòng)php-fpm:
systemctl start php-fpm //服務(wù)方式控制
or
/usr/local/php/sbin/php-fpm
停止php-fpm:
systemctl stop php-fpm
or
kill -QUIT 'cat /usr/local/php/var/run/php-fpm.pid' // 平滑停止
kill -INT 'cat /usr/local/php/var/run/php-fpm.pid' // 快速停止
重啟php-fpm:
kill -HUP 'cat /usr/local/php/var/run/php-fpm.pid' // 平滑重啟
這里順便給也出一個(gè)添加php-fpm
到systemctl
服務(wù)管理里面,這樣上面的啟動(dòng)灸叼,重啟神汹,停止都可以通過systemctl
來管理了,在/lib/systemd/system下面增加一個(gè)php-fpm.service
[Unit]
Description=The PHP 5.6 FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=/usr/local/var/run/php-fpm.pid
ExecStart=/etc/init.d/php-fpm --nodaemonize --fpm-config /usr/local/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
小記1:設(shè)置文件的權(quán)限方式, 文字設(shè)定和數(shù)字設(shè)定:chmod (-R) u=r file_name
or chmod (-R)400 file_name
小記2:你嘗試使用systemctl start docker.service
發(fā)現(xiàn)報(bào)錯(cuò)如下:
[root@username system]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2017-10-10 09:49:19 CST; 11min ago
Docs: http://docs.docker.com
Process: 29127 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY (code=exited, status=1/FAILURE)
Main PID: 29127 (code=exited, status=1/FAILURE)
Oct 10 09:49:19 taomin.localdomain systemd[1]: Starting Docker Application Container Engine...
Oct 10 09:49:19 taomin.localdomain dockerd-current[29127]: time="2017-10-10T09:49:19+08:00" level=fatal msg="unable to configure the Docker daemon with file /etc/docker/daemon.... string\n"
Oct 10 09:49:19 taomin.localdomain systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Oct 10 09:49:19 taomin.localdomain systemd[1]: Failed to start Docker Application Container Engine.
Oct 10 09:49:19 taomin.localdomain systemd[1]: Unit docker.service entered failed state.
Oct 10 09:49:19 taomin.localdomain systemd[1]: docker.service failed.
這種報(bào)錯(cuò)的原因是:/etc/docker/daemon.json
這個(gè)文件不應(yīng)該存在庆捺,如果存在它應(yīng)該是一個(gè)合法的json文件。解決上面的報(bào)錯(cuò)可以將/etc/docker/daemon.json
這個(gè)刪掉即可屁魏。