shell脚本--ntp编译安装与一键升级

34 篇文章 2 订阅

官方包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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值