1.解压,编译,安装nginx
[root@server1 ~]# ls
nginx-1.15.8.tar.gz nginx-1.16.0.tar.gz
[root@server1 ~]# tar zxf nginx-1.15.8.tar.gz
[root@server1 ~]# cd nginx-1.15.8
[root@server1 nginx-1.15.8]# ls
[root@server1 nginx-1.15.8]# vim auto/cc/gcc
#关闭debug文件
# debug
#CFLAGS="$CFLAGS -g"
安装依赖性,编译:
yum install -y gcc pcre-devel zlib-devel
./configure --prefix=/usr/local/nginx/
安装:
[root@server1 nginx-1.15.8]# make && make install
objs目录下多了nginx
2.给文件加高光
[root@server1 ~]# mkdir .vim
[root@server1 ~]# cd nginx-1.15.8/contrib/
[root@server1 contrib]# ls
README geo2nginx.pl unicode2nginx vim
[root@server1 contrib]# cp -r vim/* ~/.vim/
[root@server1 contrib]# vim ../conf/nginx.conf
3.设置nginx的worker工作数:
[root@server1 nginx-1.15.8]# vim /usr/local/nginx/conf/nginx.conf
user nginx nginx; ##设置使用nginx的用户和组
worker_processes 2; ##设置启动worker进程为2个
[root@server1 ~]# useradd nginx
设置最大连接数,先设置系统允许最大连接数:
vim /etc/security/limits.conf
nginx - nofile 65535
vim /usr/local/nginx/conf/nginx.conf
events {
worker_connections 65535;
}
4.开启nginx
[root@server1 ~]# /usr/local/nginx/sbin/nginx -t #检测文件
[root@server1 ~]# /usr/local/nginx/sbin/nginx -V #查看版本号
[root@server1 ~]# /usr/local/nginx/sbin/nginx
查看端口是否开启:
[root@server1 ~]# netstat -tnlp
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6208/nginx: master
[root@server1 ~]# ps -ef | grep nginx ##可以查看到nginx的master与worker进程,master用于监控
打开浏览器:http://172.25.60.1/
nginx安装成功
先给源版本做备份,如果更新出错,便于回退
[root@server1 ~]# cd /usr/local/nginx/sbin/
[root@server1 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 6208(master进程号) ##使当前版本的nginx执行完正在执行的任务后不再执行 这时新旧版本一起工作
ps -ef | grep nginx ##可查看到新旧进程
kill -WINCH 6208 ##关闭旧的master下的worker
ps -ef | grep nginx ##可查看到只有新版的worker
/usr/local/nginx/sbin/nginx -V ##可看到新版号
nginx更新成功!
[root@server1 ~]# cd /usr/local/nginx/sbin/
[root@server1 sbin]# ls
nginx nginx.old
[root@server1 sbin]# cp -f nginx.old nginx
cp: overwrite 'nginx'? y
[root@server1 ~]# ps -ef | grep nginx
[root@server1 ~]# kill -HUP 6208 ##将旧版master唤醒
[root@server1 ~]# ps -ef | grep nginx
[root@server1 ~]# kill -USR2 18305
[root@server1 ~]# ps -ef | grep nginx
[root@server1 ~]# kill -WINCH 18305
[root@server1 ~]# ps -ef | grep nginx
[root@server1 ~]# /usr/local/nginx/sbin/nginx -V