● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)
Active: failed (Result: resources) since Sat 2018-08-04 13:06:35 EDT; 16s ago
Process: 3435 ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Aug 04 13:06:35 localhost.localdomain systemd[1]: Starting LVS and VRRP High Availability Monitor...
Aug 04 13:06:35 localhost.localdomain systemd[1]: PID file /var/run/keepalived.pid not readable (yet?) after start.
Aug 04 13:06:35 localhost.localdomain systemd[1]: Failed to start LVS and VRRP High Availability Monitor.
Aug 04 13:06:35 localhost.localdomain systemd[1]: Unit keepalived.service entered failed state.
Aug 04 13:06:35 localhost.localdomain systemd[1]: keepalived.service failed.
keepalivedを構築するための注意事項:
周囲
メインnginx [ロードバランス](https://cloud.tencent.com/product/clb?from=10680)デバイス:192.168.5.129(VIPはkeepalivedを介して構成されます:外部使用のために192.168.5.101/0)
副nginxロードバランサー:192.168.5.130(VIPはkeepalivedを介して構成されます:外部使用のために192.168.5.101/0)
tar xf keepalived-1.3.4.tar.gz
cd keepalived-1.3.4./configure --prefix=/usr/local/keepalived
make && make install
コピー/sbin/に生き続ける/usr/sbin
> cp /keepalived/sbin/keepalived /usr/sbin/
keepalivedはデフォルトで読み取ります/etc/keepalived/keepalived.conf設定ファイル
> mkdir /etc/keepalived
> cp /keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
sysconfigファイルをにコピーします/etc/sysconfigの下
> cp /keepalived/etc/sysconfig/keepalived /etc/sysconfig/
起動スクリプトをにコピーします/etc/init.dの下
> cd /keepalived-1.3.4> cp ./keepalived/etc/init.d/keepalived /etc/init.d/> chmod 755/etc/init.d/keepalived
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0}
vrrp_instance VI_1 {
state MASTER(BACKUP)interfaceens33--ネットワークカード名に注意してください
virtual_router_id 51
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111}
virtual_ipaddress {192.168.5.100192.168.5.101}}
service keepalived start
systemctl status keepalived.service
5.残りの問題:
サービスが開始されると、サービスは一定期間自動的に閉じられます;(約数分後)
vim /lib/systemd/system/keepalived.service
[ Unit]
Description=Keepalived
After=syslog.target network.target remote-fs.target nss-lookup.target
[ Service]
Type=forking
PIDFile=/var/run/keepalived.pid
ExecStart=/usr/local/keepalived/sbin/keepalived -D
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true[Install]
WantedBy=multi-user.target
1; systemctl daemon-リロードリロード
2: systemctl enable keepalived.自動的に開始するように設定されたサービス
3: systemctl disable keepalived.サービスキャンセル自動起動
4: systemctl start keepalived.サービス開始
5: systemctl stop keepalived.サービス停止
自動的に開始するようにnginxを設定します
vim /lib/systemd/system/keepalived.service
[ Unit]
Description=nginx
After=network.target
[ Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true[Install]
WantedBy=multi-user.target
systemctl enable nginx.service
systemctl start nginx.サービス開始nginx
systemctl stop nginx.サービスはnginxを終了します
systemctl restart nginx.サービス再起動nginx
vi /root/check_nginx.sh
#! /bin/bash
if[`ps -C nginx --no-header |wc -l`-eq 0]
then
systemctl start nginx.service
sleep 2if[`ps -C nginx --no-header |wc -l`-eq 0]
then
systemctl stop keepalived.service
fi
fi
chmod +x /root/check_nginx.sh
ジョブプランに追加
crontab -e
* /1****/root/check_nginx.sh >>/root/check_nginx.log
keepalived.confファイルを追加します
vrrp_script check_nginx { ######nginxを監視するスクリプトを定義します
script "/root/check_nginx.sh"
interval 2 ######監視間隔
weight 2 ######負荷パラメータ
}
vrrp_instance vrrptest {
track_script {
check_nginx
}
8. 知識の補足:シェルプログラミングを学ぶ
Recommended Posts