CentOS7 NTP server + keepalived
NTP安装
yum -y install ntp
systemctl enable ntpd
首先同步一次时间
ntpdate time.windows.com
ntp配置(Host1 Host2)
/etc/ntp.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
server time.windows.com prefer
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
#记录上次的NTP server与上层NTP server连接接所花费的时间
driftfile /var/lib/ntp/drift
#设置默认策略为允许任何主机进行时间同步
restrict 0.0.0.0 mask 0.0.0.0 nomodify
#设置ntp日志的path
statsdir /var/log/ntp/
#设置ntp日志文件
logfile /var/log/ntp/ntp.log
mkdir /var/log/ntp/; touch /var/log/ntp/ntp.log; chown ntp:ntp /var/log/ntp/ntp.log
systemctl start ntpd
Keepalived安装
yum -y install Keepalived
host1配置
/etc/keepalived/keepalived.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
global_defs {
notification_email {
xx@xx.com
}
notification_email_from keepalived@xx.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER ############ MASTER/BACKUP
interface eno16777984
virtual_router_id 51
mcast_src_ip 172.16.0.2
priority 150 ########### MASTER权值要比BACKUP高
advert_int 1
authentication {
auth_type PASS
auth_pass GSksLAyTX9ylwG86U2Ez
}
virtual_ipaddress {
172.16.0.10
}
}
Host2配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
global_defs {
notification_email {
xx@xx.com
}
notification_email_from keepalived@xx.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP ############ MASTER/BACKUP
interface eno16777984
virtual_router_id 51
mcast_src_ip 172.16.0.3
priority 150 ########### MASTER权值要比BACKUP高
advert_int 1
authentication {
auth_type PASS
auth_pass GSksLAyTX9ylwG86U2Ez
}
virtual_ipaddress {
172.16.0.10
}
}
systemctl enable keepalived
systemctl start keepalived
1 windows客户端向NTP每10分钟同步一次时间
gpedit.msc打开组策略
1.1 启动windows NTP客户端
1.2 配置windows NTP客户端
1.3 Internet时间设置里指定时间服务器
点击立即更新
2 linux客户端向NTP每10分钟同步一次时间2.1 安装NTPyum -y install ntp
2.2 设置时间同步执行下面的命令
echo -e "\n\n## sync time\n*/10 * * ** root ntpdate 172.16.0.10 && hwclock-w" >> /etc/crontab
页:
[1]