centos7.9 部署nginx1.19.7 配置双机高可用
master:10.17.17.78
slave: 10.17.17.79
vip: 10.17.17.80
install nginx1.19.7
- 10.17.17.78/79 同样操作
[root@baojian-79 ~]# wget http://nginx.org/download/nginx-1.19.7.tar.gz
[root@baojian-79 ~]# yum -y install gcc pcre-devel zlib-devel openssl openssl-devel lua-devel python-devel -y
[root@baojian-79 ~]# tar -xf nginx-1.19.7.tar.gz
[root@baojian-79 ~]# cd nginx-1.19.7
###带附加模块的
./configure --prefix=/data/nginx --with-pcre --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-ipv6 --with-http_realip_module --with-http_gzip_static_module --with-pcre-jit --with-ld-opt=-ljemalloc --with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib --add-module=/usr/local/src/nginx1.19.7-module/lua-nginx-module-0.10.13 --add-module=/usr/local/src/nginx1.19.7-module/ngx_devel_kit-0.3.0 --add-module=/usr/local/src/nginx1.19.7-module/nginx-module-vts --add-module=/usr/local/src/nginx1.19.7-module/nginx_upstream_check_module
###[root@baojian-79 ~]# ./configure --prefix=/data/nginx --with-pcre --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-ipv6 --with-http_realip_module --with-http_gzip_static_module --with-pcre-jit --with-ld-opt=-ljemalloc --with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib [root@baojian-79 ~]# make -j 4 && make install
install keepalived
- 10.17.17.78/79 同样操作
[root@baojian-78 ~]# yum install -y ipvsadm keepalived
[root@baojian-78 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
}
router_id LVS_DEVEL
}vrrp_script chk_http_port {
script "/data/nginx/sbin/nginx_pid.sh"
interval 1
weight 2
}vrrp_instance VI_1 {
state MASTER
interface ens192#ip a查看你的网卡叫什么
virtual_router_id 28
priority 100#slave 节点要比master小比如80
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.17.17.80
}
track_script {
chk_http_port
}
}
【centos7.9 部署nginx1.19.7 配置双机高可用】
文章图片
[root@baojian-79 ~]# cat /data/nginx/sbin/nginx_pid.sh
#!/bin/bashif [ `ps -C nginx --no-header |wc -l` -eq 0 ];
then
killall keepalived
fi
config nginx
[root@insurace-24 conf]# cat nginx.conf
userroot;
worker_processes8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
worker_rlimit_nofile 65535;
error_log /data/nginx/logs/error.log error;
#pidlogs/nginx.pid;
events {
use epoll;
worker_connections65535;
}http {
includemime.types;
default_typeapplication/octet-stream;
log_format main'{"@timestamp":"$time_iso8601",'
'"@source":"$server_addr",'
'"hostname":"$hostname",'
'"ip":"$http_x_forwarded_for",'
'"client":"$remote_addr",'
'"request_method":"$request_method",'
'"scheme":"$scheme",'
'"domain":"$server_name",'
'"referer":"$http_referer",'
'"request":"$request_uri",'
'"args":"$args",'
'"size":$body_bytes_sent,'
'"status": $status,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamaddr":"$upstream_addr",'
'"http_user_agent":"$http_user_agent",'
'"https":"$https"'
'}';
access_loglogs/access.logmain;
sendfileon;
client_max_body_size 256m;
server_tokens off ;
proxy_intercept_errors on;
#keepalive_timeout0;
keepalive_timeout30;
gzip on;
gzip_min_length5k;
gzip_buffers4 16k;
gzip_http_version 1.0;
gzip_comp_level 4;
gzip_typestext/plain application/x-javascript application/javascripttext/cssapplication/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
vhost_traffic_status_zone;
vhost_traffic_status_filter_by_host on;
includeconf.d/*.conf;
fastcgi_intercept_errors on;
server {
listen80;
server_name 10.17.17.79;
charset UTF-8;
}
server {
listen80;
server_name10.17.17.80;
charset UTF-8;
}
}
推荐阅读
- Beego打包部署到Linux
- 私有化轻量级持续集成部署方案--03-部署web服务(下)
- Spring|Spring Boot部署到Resin遇到的问题
- 如何在阿里云linux上部署java项目
- 部署专题集合
- jar|springboot项目打成jar包和war包,并部署(快速打包部署)
- 一键编译部署Mysql
- 8月16日|8月16日 全网备份
- 改变企业沟通环境|改变企业沟通环境 从部署企业IM开始
- Jenkins自动化部署-前端篇|Jenkins自动化部署-前端篇 (四)