前言:
時間服務器部署,這樣可以防止網絡帶來的阻塞和延遲導致服務器的時間不一致,時間的不一致容易導致各種錯誤。假如監控時間報錯了,你老大會怎麼想
部署:
1.安裝ntp
yum -y install ntp [root@nfs01 ~]# rpm -qa ntpntp-4.2.6p5-10.el6.centos.2.x86_64
2.配置文件
[root@m01 ~]# grep -Ev "#|^$" /etc/ntp.conf driftfile /var/lib/ntp/drift restrict default nomodify restrict 127.0.0.1 restrict -6 ::1server ntp1.aliyun.com server time.nist.gov includefile /etc/ntp/crypto/pw keys /etc/ntp/keys
步驟,此處略low,可以使用直推推送配置文件的方法
sed -i 's#server 3.centos.pool.ntp.org iburst##g' /etc/ntp.confsed -i 's#server 2.centos.pool.ntp.org iburst##g' /etc/ntp.confsed -i 's#server 1.centos.pool.ntp.org iburst##g' /etc/ntp.confsed -i 's#server 0.centos.pool.ntp.org iburst##g' /etc/ntp.confsed -i 's#restrict default kod nomodify notrap nopeer noquery##g'sed -i 's#restrict -6 default kod nomodify notrap nopeer noquery##g'echo -e "server ntp1.aliyun.com\nserver time.nist.gov\nrestrict default nomodify" >> /etc/ntp.conf
3.啓動並查看
/etc/init.d/ntpd startntpq -p
劇本
---- hosts: 172.16.1.61 tasks: - name: install ntp yum: name: ntp state: installed - name: update cfg shell: sed -i 's#server 3.centos.pool.ntp.org iburst##g' /etc/ntp.conf;sed -i 's#server 2.centos.pool.ntp.org iburst##g' /etc/ntp.conf;sed -i 's#server 1.centos.pool.ntp.org iburst##g' /etc/ntp.conf;sed -i 's#server 0.centos.pool.ntp.org iburst##g' /etc/ntp.conf;sed -i 's#restrict default kod nomodify notrap nopeer noquery##g' /etc/ntp.conf;sed -i 's#restrict -6 default kod nomodify notrap nopeer noquery##g /etc/ntp.conf';echo -e "server ntp1.aliyun.com\nserver time.nist.gov\nrestrict default nomodify" >> /etc/ntp.conf - name: start ntp service: name: ntpd state: started enabled: yes- hosts: aige tasks: - name: cron ntp cron: name: sync time minute: "*/5" job: '/usr/sbin/ntpdate 172.16.1.61 >/dev/null 2>&1'