您好,登錄后才能下訂單哦!
準備yum源
cd /etc/yum.repos.d/
rm -rf *
wget http://mirrors.aliyun.com/repo/Centos-7.repo
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
wget http://mirrors.aliyun.com/repo/epel-7.repo
yum repolist
配置keepalived
yum -y install keepalived
vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state MASTER #另一臺服務器是SLAVE
interface ens33 #默認是eth0,一定要修改
virtual_router_id 51
priority 100 #另一臺服務器優先級要低于100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.19
}
}
關掉master,測試slave是否能接替master
systemctl stop keepalived
在slave上查看
tail -f /var/log/messages
Jul 24 14:09:37 jenkins-slave Keepalived_vrrp[3340]: VRRP_Instance(VI_1) Entering MASTER STATE
配置haproxy
cd /usr/local/src/
將haproxy壓縮包上傳到該目錄
yum install gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools vim iotop bc zip unzip zlib-devel lrzsz tree screen lsof tcpdump wget ntpdate -y
tar xvf haproxy-1.8.13.tar.gz
cd haproxy-1.8.13/
make ARCH=x86_64 TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_CPU_AFFINITY=1 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
cp haproxy /usr/sbin/
haproxy -v
準備啟動腳本
vim /usr/lib/systemd/system/haproxy.service
[Unit]
Description=HAProxy Load Balancer
After=syslog.target network.target
[Service]
ExecStartPre=/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/conf -c -q
ExecStart=/usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/conf -p /r
un/haproxy.pidExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
準備haproxy配置文件
mkdir -p /var/lib/haproxy #配置文件中需要該目錄
mkdir -p /etc/haproxy/conf
cd /etc/haproxy/
vim haproxy.cfg
global
maxconn 100000
chroot /usr/local/haproxy
stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin #動態調整后端
uid 99
gid 99
daemon
nbproc 4
cpu-map 1 0
cpu-map 2 1
cpu-map 3 2
cpu-map 4 3
pidfile /usr/local/haproxy/run/haproxy.pid
log 127.0.0.1 local3 info
defaults
option http-keep-alive
option forwardfor
maxconn 100000
mode http
timeout connect 300000ms
timeout client 300000ms
timeout server 300000ms
listen stats
mode http
bind 0.0.0.0:9999
stats enable
log global
stats uri /haproxy-status
stats auth admin:mypassword
http://192.168.1.19:9999/haproxy-status
準備業務配置文件
cd conf/
vim tomcat-server.cfg
listen web_port
bind 192.168.1.19:80 #VIP
mode http
log global
server 192.168.1.17 192.168.1.17:8080 check inter 3000 fall 2 rise 5
server 192.168.1.18 192.168.1.18:8080 check inter 3000 fall 2 rise 5
sysctl -a |grep nonlocal
sysctl -a |grep forward
vim /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1
sysctl -p
systemctl start haproxy
systemctl enable haproxy
systemctl status haproxy
ss -tnl |grep 80
LISTEN 0 128 192.168.1.19:80 :
http://192.168.1.19/web01/
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。