#安装nginx
yum install -y epel-release
yum install -y nginx
# rpm安装
Index of /packages/centos/7/x86_64/RPMS/
rpm -ivh *.rpm
#启动niginx
systemctl start nginx
systemctl enable nginx
#安装tomact用于测试
有tar包解压
cd 进去
cd bin
./startup.sh
#配置反向代理 /etc/nginx/nginx.conf
#要添加反向代理就添加一段server
#在 http 里在 server 外
#基础字段
server {
listen port;
location / {
proxy_pass http://ip:port;
}}
#示例
server {
listen 81;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
#修改完配置文件后重新加载
nginx -s reload
nginx服务不能重启
#负载均衡
nginx upstream
轮询
权重轮询
ip 哈希
url_hash算法
#配置在http顶部——nginx.conf
upstream tomcat {
server 127.0.0.1:8080 weight=1 max_fails=3 fail_timeout=10s;
server 127.0.0.1:8081 weight=5 max_fails=3 fail_timeout=10s;
server 127.0.0.1:8082 backup; # 备用节点,主节点全挂才启用}
max_fails=3 fail_timeout=10s不属于负载均衡策略,是健康检查容错配置:#意思是,当访问失败三次后就,超时等待10秒再继续访问检测
#两处修改一个是添加upstream负载均衡策略
#二是把反向代理的地址换成 upstream 名
#基础配置


#动静分离
#nginx平滑升级
tar -xvf
cd
dnf install gcc gcc-c++ make pcre-devel zlib-devel openssl-devel -y
CFLAGS="-Wno-deprecated-declarations" ./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_modulemake -j4
make install
usradd -s /sbin/nologin -M nginx
cd /usr/local/nginx/sbin
./nginx
#解压18
tar
cd
CFLAGS="-Wno-deprecated-declarations" ./configure --prefix=/opt/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module
#只升级主进程sbin/nginx——只替换这个
#把旧的挪走
cd /opt/nginx/sbin
mv /usr/local/nginx/sbin/nginx /root/nginx_old
mv /opt/nginx/sbin/nginx /usr/local/nginx/sbin/nginx
检查配置
ps -ef | grep nginx
kill -USR2 旧pid
ps -ef | frep nginx
#逐步关掉旧进程
kill -WINCH 16591
#在确定新版稳定后
kill -QUIT 16591
#倘若进版本出问题了就把之前的旧版本移回来 nginx_old
记住一个前提更新nginx都是因为服务器不止一个nginx先更新不是主的nginx







1507

被折叠的 条评论
为什么被折叠?



