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
}
}
[root@baojian-79 ~]# cat /data/nginx/sbin/nginx_pid.sh
#!/bin/bash
if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
killall keepalived
fi
config nginx
[root@insurace-24 conf]# cat nginx.conf
user root;
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
worker_rlimit_nofile 65535;
error_log /data/nginx/logs/error.log error;
#pid logs/nginx.pid;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/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_log logs/access.log main;
sendfile on;
client_max_body_size 256m;
server_tokens off ;
proxy_intercept_errors on;
#keepalive_timeout 0;
keepalive_timeout 30;
gzip on;
gzip_min_length 5k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 4;
gzip_types text/plain application/x-javascript application/javascript text/css application/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;
include conf.d/*.conf;
fastcgi_intercept_errors on;
server {
listen 80;
server_name 10.17.17.79;
charset UTF-8;
}
server {
listen 80;
server_name 10.17.17.80;
charset UTF-8;
}
}