1.解压,编译,安装nginx
tar zxf nginx-1.17.1.tar.gz
cd nginx-1.17.1/
vim auto/cc/gcc
#关闭debug文件
# debug
#CFLAGS="$CFLAGS -g"
yum install -y gcc pcre-devel zlib-devel
./configure --prefix=/usr/local/nginx/
make && make install
2.给文件加高光
mkdir .vim
cd nginx-1.17.1/contrib/
cp -r vim/* ~/.vim/
vim ../conf/nginx.conf
vim /usr/local/nginx/conf/nginx.conf
user nginx nginx; ##设置使用nginx的用户和组
worker_processes 2; ##设置启动worker进程为2个
useradd nginx
设置最大连接数,先设置系统允许最大连接数:
cd /usr/local/nginx/conf
vim nginx.conf
nginx - nofile 65535
vim /usr/local/nginx/conf/nginx.conf
events {
worker_connections 65535;
}
cd /usr/local/nginx/
./sbin/nginx -v
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -v
/usr/local/nginx/sbin/nginx
netstat -tnlp
cd /usr/local/nginx/sbin/
cp nginx nginx.old
tar zxf nginx-1.16.0.tar.gz
cd nginx-1.16.0
./configure --prefix=/usr/local/nginx --with-file-aio
make #不能make install,会在/usr/local/nginx/目录下生成sbin目录,替换原来的目录
cd objs/
cp -f nginx /usr/local/nginx/sbin/nginx ##-f,强制复制 不加会报nginx正在运行无法复制
ps -ef | grep nginx ##查看nginx master和worker进程号
kill -USR2 3655(master进程号) ##使当前版本的nginx执行完正在执行的任务后不再执行 这时新旧版本一起工作
kill -WINCH 3655 ##关闭旧的master下的worker
ps -ef | grep nginx ##可查看到只有新版的worker
/usr/local/nginx/sbin/nginx -v #可以看到更新后的版本号
cd /usr/local/nginx/sbin/
cp -f nginx.old nginx
ps -ef | grep nginx
kill -HUP 3655 ##将旧版master唤醒
ps -ef | grep nginx
kill -USR2 6206
ps -ef | grep nginx
kill -WINCH 6206
ps -ef | grep nginx