shell腳本--ntp編譯安裝與一鍵升級

官方包4.2.8p13下載鏈接:http://www.ntp.org/downloads.html

cenots7

安裝

#!/bin/bash
cd /tmp/
yum -y install gcc
tar zvxf /tmp/ntp-4.2.8p10.tar.gz -C /tmp/

cd /tmp/ntp-4.2.8p10
./configure  --enable-all-clocks --enable-parse-clocks --enable-clockctl
make
make install



cat << EOF >> /etc/ntp.conf
################
server 10.108.84.44
server 10.108.84.45

fudge 127.127.1.0 stratum 3
restrict 127.0.0.1 
driftfile /var/lib/ntp/drift
logfile /var/log/ntp.log
restrict 10.101.0.0 mask 255.255.0.0 nomodify 
#################
EOF

cat << EOF > /usr/lib/systemd/system/ntpd.service
[Unit]
Description=Network Time Service
After=syslog.target

[Service]
Type=forking
EnvironmentFile=-/etc/sysconfig/ntpd
ExecStart=/usr/local/bin/ntpd -u ntp:ntp $OPTIONS
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

systemctl enable ntpd 
systemctl start ntpd
systemctl status ntpd

ntpd --version
ntpq -p

升級

#!/bin/bash
cp /etc/ntp.conf /etc/ntp.conf_bak
cp -r /etc/ntp /etc/ntp_bak
cp /usr/lib/systemd/system/ntpd.service /usr/lib/systemd/system/bak-ntpd.service
cp /usr/lib/systemd/system/ntpdate.service /usr/lib/systemd/system/bak-ntpdate.service
tar zxvf ntp-4.2.8p13.tar.gz
cd ntp-4.2.8p13
service ntpd stop
./configure  --enable-all-clocks --enable-parse-clocks --enable-clockctl
make
make install
cp /etc/ntp.conf_bak /etc/ntp.conf           
cp -r /etc/ntp_bak/* /etc/ntp
cp /usr/local/sbin/ntp* /usr/sbin
cp /usr/lib/systemd/system/bak-ntpd.service /usr/lib/systemd/system/ntpd.service
cp /usr/lib/systemd/system/bak-ntpdate.service /usr/lib/systemd/system/ntpdate.service
service ntpd restart
systemctl enable ntpd
ntpd -v
ntpq -p

centos6

#!/bin/bash
cp /var/lock/subsys/ntpd /var/lock/subsys/ntpd_bak
cp /var/run/ntpd.pid /var/run/ntpd.pid_bak
cp /etc/rc.d/init.d/ntpd /etc/rc.d/init.d/ntpd_bak
cp /etc/rc.d/init.d/ntpdate /etc/rc.d/init.d/ntpdate_bak
cp /etc/sysconfig/ntpd     /etc/sysconfig/ntpd_bak
cp /etc/sysconfig/ntpdate  /etc/sysconfig/ntpdate_bak
cp /etc/ntp.conf /etc/ntp.conf_bak
cp -r /etc/ntp /etc/ntp_bak
tar zxvf ntp-4.2.8p13.tar.gz
cd ntp-4.2.8p13
service ntpd stop
./configure  --enable-all-clocks --enable-parse-clocks --enable-clockctl
make
make install
cp /var/lock/subsys/ntpd_bak /var/lock/subsys/ntpd
cp /etc/rc.d/init.d/ntpd_bak   /etc/rc.d/init.d/ntpd   
cp /etc/rc.d/init.d/ntpdate_bak /etc/rc.d/init.d/ntpdate
cp /etc/sysconfig/ntpd_bak /etc/sysconfig/ntpd     
cp /etc/sysconfig/ntpdate_bak /etc/sysconfig/ntpdate  
cp /etc/ntp.conf_bak /etc/ntp.conf           
cp /var/run/ntpd.pid_bak /var/run/ntpd.pid
cp -r /etc/ntp_bak/* /etc/ntp
cp /usr/local/sbin/ntp* /usr/sbin
service ntpd restart
chkconfig ntpd on
ntpd -v
ntpq -p
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章