时间NTP服务器集群部署
1. 服务器信息2. 系统架构图3 安装部署3.1 安装相应软件包三台都要装yum install ntp -yyum install -y ipvsadmyum install –y keepalivedyum install -y nc3.2 配置ntp服务,时间同步vi /etc/ntp.conf#server 0.centos.pool.ntp.org iburst#server 1.ce
1. 服务器信息
2. 系统架构图
3 安装部署
3.1 安装相应软件包
三台都要装
yum install ntp -y
yum install -y ipvsadm
yum install –y keepalived
yum install -y nc
3.2 配置ntp服务,时间同步
vi /etc/ntp.conf
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server ntp.aliyun.com
systemctl start ntpd
systemctl status ntpd
systemctl enable ntpd
3.3 配置keepalived高可用
cd /etc/keepalived/
cp keepalived.conf keepalived.conf.bak
mkdir -p /usr/local/scripts/keepalived/
vi /usr/local/scripts/keepalived/UDP_CHECK.sh
#!/bin/bash
/usr/bin/nc -uz -w1 $1 $2 >/dev/null
exit $?
主节点:
vi /etc/keepalived/keepalived.conf
global_defs {
router_id timeserver01 #标识当前节点名字,两个节点的此项需要不相同。
}
vrrp_instance ntp { #定义一个实例,一个集群就是一个实例。 默认VI_1 可以随意改
state MASTER #指定 A 节点为主节点 备用节点上设置为 BACKUP 即可
interface ens192 #绑定虚拟 IP 的网络接口
virtual_router_id 51 #VRRP 组名,两个节点的设置必须一样,以指明各个节点属于同一 VRRP 组
priority 100 #主节点的优先级(1-254 之间),备用节点必须比主节点优先级低
advert_int 1 #组播信息发送间隔,两个节点设置必须一样
authentication { #设置验证信息,两个节点必须一致
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.100.113 #指定虚拟 IP, 两个节点设置必须一样
}
}
virtual_server 192.168.100.113 123 { #对虚拟IP63添加LVS相关内容
delay_loop 6 #Keepalived 多长时间监测一次 RS
lb_algo rr #分发算法
lb_kind DR #DR 模式
protocol UDP
real_server 192.168.100.110 123 {
weight 1
MISC_CHECK {
misc_path "/usr/local/scripts/keepalived/UDP_CHECK.sh 192.168.100.110 123"
misc_timeout 10
}
}
real_server 192.168.100.111 123 {
weight 1
MISC_CHECK {
misc_path "/usr/local/scripts/keepalived/UDP_CHECK.sh 192.168.100.111 123"
misc_timeout 10
}
}
real_server 192.168.100.112 123 {
weight 1
MISC_CHECK {
misc_path "/usr/local/scripts/keepalived/UDP_CHECK.sh 192.168.100.112 123"
misc_timeout 10
}
}
}
备节点:
vi /etc/keepalived/keepalived.conf
global_defs {
router_id timeserver02 #标识当前节点名字,两个节点的此项需要不相同。
}
vrrp_instance ntp { #定义一个实例,一个集群就是一个实例。 默认VI_1 可以随意改
state BACKUP #指定 A 节点为主节点 备用节点上设置为 BACKUP 即可
interface ens192 #绑定虚拟 IP 的网络接口
virtual_router_id 51 #VRRP 组名,两个节点的设置必须一样,以指明各个节点属于同一 VRRP 组
priority 90 #主节点的优先级(1-254 之间),备用节点必须比主节点优先级低
advert_int 1 #组播信息发送间隔,两个节点设置必须一样
authentication { #设置验证信息,两个节点必须一致
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.100.113 #指定虚拟 IP, 两个节点设置必须一样
}
}
virtual_server 192.168.100.113 123 { #对虚拟IP63添加LVS相关内容
delay_loop 6 #Keepalived 多长时间监测一次 RS
lb_algo rr #分发算法
lb_kind DR #DR 模式
protocol UDP
real_server 192.168.100.110 123 {
weight 1
MISC_CHECK {
misc_path "/usr/local/scripts/keepalived/UDP_CHECK.sh 192.168.100.110 123"
misc_timeout 10
}
}
real_server 192.168.100.111 123 {
weight 1
MISC_CHECK {
misc_path "/usr/local/scripts/keepalived/UDP_CHECK.sh 192.168.100.111 123"
misc_timeout 10
}
}
real_server 192.168.100.112 123 {
weight 1
MISC_CHECK {
misc_path "/usr/local/scripts/keepalived/UDP_CHECK.sh 192.168.100.112 123"
misc_timeout 10
}
}
}
systemctl status keepalived
systemctl enable keepalived
systemctl start keepalived
3.4 配置ip地址转发,三个节点都要
vi /etc/init.d/add-vip
#!/bin/bash
VIP=192.168.100.113
. /etc/rc.d/init.d/functions
case "$1" in
start)
ifconfig ens192:1 $VIP netmask 255.255.255.255 broadcast $VIP up
/sbin/route add -host $VIP dev ens192:1
echo "1" >/proc/sys/net/ipv4/conf/ens192/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/ens192/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p >/dev/null 2>&1
echo "RealServer Start OK"
;;
stop)
ifconfig ens192:1 down
route del $VIP >/dev/null 2>&1
echo "0" >/proc/sys/net/ipv4/conf/ens192/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/ens192/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "RealServer Stoped"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
chmod +x /etc/init.d/add-vip
/etc/init.d/add-vip start
3.5 客户端配置
*/5 * * * * /usr/sbin/ntpdate ntp.nbdeli.com
更多推荐
所有评论(0)