首页 > 系统相关 >keepalived+nginx二进制安装

keepalived+nginx二进制安装

时间:2023-01-08 11:34:41浏览次数:46  
标签:00 lft 二进制 keepalived nginx usr local

keepalived二进制安装
1、下载keepalived安装包:
keepalived下载地址:https://www.keepalived.org/download.html
wget http://www.keepalived.org/software/keepalived-2.0.18.tar.gz

2、环境:
主:192.168.1.5 vm5
备:192.168.1.6 vm6
准备前工作先安装依赖:
yum install -y openssl openssl-devel libnl libnl-devel libnl3-devel

3、解压keepalived安装包:
tar -zxvf keepalived-2.0.18.tar.gz
4、安装keepalived:
mkdir /usr/local/keepalived
cd keepalived-2.0.18
./configure --prefix=/usr/local/keepalived  #指定位置下安装目录
make
make install
检查keepalived版本号
/usr/local/keepalived/sbin/keepalived -v

复制keepalived配置文件到 /etc/keepalived/ 目录下:
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
(启动 keepalived 时,默认会去 /etc/keepalived 目录下找 keepalived.conf 文件)
keepalived日志文件路径:/var/log/messages

4 修改配置:
主节点修改配置文件/etc/keepalived/keepalived.conf
global_defs {
   notification_email {
     [email protected]
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id NGINX_MASTER
}
vrrp_script check_nginx {
    script "/etc/keepalived/check_nginx.sh"
}
vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    # 虚拟IP
    virtual_ipaddress {
        192.168.1.100/24
    }
    track_script {
        check_nginx
    }
}


nginx检查脚本:
cat /etc/keepalived/check_nginx.sh
#!/bin/bash
count=$(ps -ef |grep nginx |egrep -cv "grep|$$")

if [ "$count" -eq 0 ];then
    exit 1
else
    exit 0
fi



备节点修改配置文件/etc/keepalived/keepalived.conf
global_defs {
   notification_email {
     [email protected]
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id NGINX_BACKUP
}
vrrp_script check_nginx {
    script "/etc/keepalived/check_nginx.sh"
}
vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.100/24
    }
    track_script {
        check_nginx
    }
}

配置keepalived开机自启:
systemctl daemon-reload
systemctl start keepalived
systemctl enable keepalived


二 nginx二进制安装

nginx二进制包下载地址:https://nginx.org/en/download.html
useradd nginx
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -zxf nginx-1.20.1.tar.gz
cd nginx-1.20.1
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --user=nginx --group=nginx 

(主节点和备节点一样)修改nginx配置:/usr/local/nginx/conf/nginx.conf
cat /usr/local/nginx/conf/nginx.conf
user nginx;
worker_processes auto;
error_log /usr/local/nginx/logs/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}


stream {

    log_format  main  '$remote_addr $upstream_addr - [$time_local] $status $upstream_bytes_sent';

    access_log  /usr/local/nginx/logs/k8s-access.log  main;

    upstream k8s-apiserver {
       server 192.168.1.5:6443;
       server 192.168.1.6:6443;
       server 192.168.1.7:6443;
    }
    
    server {
       listen 6443;
       proxy_pass k8s-apiserver;
    }
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /usr/local/nginx/logs/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /usr/local/nginx/conf/mime.types;
    default_type        application/octet-stream;

    server {
        listen       80 default_server;
        server_name  _;

        location / {
        }
    }
}

设置nginx自启动:/usr/lib/systemd/system/nginx.service
cat /usr/lib/systemd/system/nginx.service 
[Unit]
Description=nginx service
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target


配置开机启动:
systemctl daemon-reload
systemctl start nginx
systemctl enable nginx

验证:
在主节点上停止nginx,看vip是否漂移至备节点

[root@vm5 keepalived]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.【‘【0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:91:c0:26 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.5/24 brd 192.168.1.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::6735:3111:2325:e44e/64 scope link tentative noprefixroute dadfailed 
       valid_lft forever preferred_lft forever
    inet6 fe80::3cda:3b19:334b:896a/64 scope link tentative noprefixroute dadfailed 
       valid_lft forever preferred_lft forever
    inet6 fe80::8776:aa8b:537e:2dc6/64 scope link noprefixroute 
       valid_lft forever preferred_lft foreve

 

标签:00,lft,二进制,keepalived,nginx,usr,local
From: https://www.cnblogs.com/skyzy/p/17034308.html

相关文章

  • 二进制数和十六进制数
    最后再补充说明一下二进制数和十六进制数的关系。在以位为单位表示数据时,使用二进制数很方便,但如果位数太多,看起来就比较麻烦。因此,在实际程序中,也经常会用十六进制数来代......
  • 用二进制数表示小数
    由于计算机内部所有的信息都是以二进制数的形式来处理的,因此在这一点上,整数和小数并无差别。不过,使用二进制数来表示整数和小数的方法却有很大的不同。  上图是把1011.......
  • nginx配置访问图片等静态资源
    nginx配置访问图片等静态资源配置:通过使用别名属性alias配置真是图片路径即可location/public/uploads/{alias/www/wwwroot/quick.com/v2.0.0/dist/pu......
  • 宝塔 Nginx 实现日志记录 Cloudflare 下访客真实IP
    网站套Cloudflare后,Nginx日志记录的都CloudflareIP,要记录访客真实IP,可以按下面方法:1.自动化脚本生成如下配置文件因为Cloudflare的IP段会定期更新,所以建个任务计......
  • nginx配置文件中$request_uri变量
    1、变量作用这个$request_uri就是完整url中刨去最前面$host剩下的部分,比如http://www.qipa250.com/pan/beta/test1?fid=3这个url,去掉www.qipa250.com剩下的就是了,日志......
  • Nginx和Tomcat实现负载均衡​
    实验图​推荐步骤​Nginx服务器开启路由转发功能,客户端和Tomcat服务器配置ip地址设置正确​安装Tomcat服务器配置网站​安装Nginx代理和负载均衡功能配置DNS服务器域名解析,......
  • Nginx之突然不能域名访问
    一、问题背景像往常一样,重启Windows和Linux环境利用docker部署的nginx等服务,但是Windows访问不了部署的服务二、报错截图如下三、我的项目配置如下四、分析问题(1)查......
  • k8s 1.22.10 Ingress-nginx 的部署
    1.创建ingressingress-nginx/index.mdatcontroller-v1.1.3·kubernetes/ingress-nginx(github.com)源文件地址:ingress-nginx/index.mdatcontroller-v1.1.3·ku......
  • nginx通过http_x_forwarded_for限制来访IP示例
    由于入访经过负载均衡设备,后端nginx无法获取client_ip,只能通过http_x_forwarded_for获取到最原始用户IP。这里通过http_x_forwarded_for来限制固定IP的用户可以访问。普......
  • Nginx https证书生成
    一、证书和私钥的生成1234567891011121314151617181920212223241.创建服务器证书密钥文件server.key:opensslgenrsa-des3-outser......