linux 系統服務篇(-)
一.NTP時間伺服器 network time protocol
NTP伺服器的使命:使區域網路内伺服器(或個人pc端)的時間保持一緻。
二.開源軟體的使用步驟:
1.安裝軟體服務。
(1)源碼方式安裝
下載下傳,解壓源碼(wegt 或 rz (我用CRT)tar xf)
分析安裝平台 ./configure(一般是測試軟體的安裝環境,看缺少哪些必要的依賴安裝包)
編譯軟體
make (這裡涉及makefile檔案,makefile定義編譯和依賴的關系規則交于make工具自動編譯)
安裝軟體
make install
(2)RPM安裝及SRPM執行個體 (最大的缺點就是對作業系統環境依賴關系很大,需要大量庫的支援)
常見選項:-i 安裝 -e 解除安裝 -U 更新(如果發現多個依賴包,可以加入U 一起安裝)
-q 查詢 -f (查詢檔案) -l (查詢清單) -p(查詢包) -i(查詢軟體包的詳細資訊)
以ganglia-3.4.0-1.src.rpm 為例;
# rpm -i ganglia-3.4.0-1.src.rpm
# cd /root/rpmbuild/SPECS
# ls
ganglia.spec
# rpmbuild -bb ganglia.spec
# cd /root/rpmbuild/RPMS/x86_64
然後就是熟悉的 rpm包了。
(3)yum 方式克服了rpm的缺點。可以自動識别安裝依賴。但是,yum需要配置資源庫(完整的資源庫以滿足需求)
常用的 install -y 自動安裝 remove删除
(4) 以打包(*.tar.gz *.zip形式存在的二進制安裝
2.軟體安裝路徑及配置檔案路徑。
/usr/local/xx /etc/xx/xx.conf
3.軟體安裝後的服務啟動檔案和指令檔案
/etc/init.d/xxx /usr/local/xxx/bin/xxd
4.修改配置檔案,熟悉配置參數。
5.啟動服務,如何應用。
用戶端也可以使用 ntpdate 和網際網路的時間伺服器同步:
ntpdate 0.centos.pool.ntp.org
2台虛拟機。ntp主機 140 ntp客戶141
140
# yum ntp ntpdate -y
(這裡ntp 是服務名稱 ntpdate 是時間同步指令多用于用戶端)
# cp /etc/ntp.conf /etc/ntp.conf.bak
# vim /etc/ntp.conf
driftfile /var/lib/ntp/drift
#關閉所有NTP要求的封包
restrict default kod nomodify notrap nopeer noquery
#預設的規則
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
#開啟内部遞歸網絡接口 lo
restrict -6 ::1
#ipv6形式的遞歸網絡接口
server time.windows.com
#設定上級同步時間伺服器
server 127.127.1.0
#安全措施。如果上級時間伺服器不可用。則以本地時間為标準同步,保證時間伺服器正常運作
fudge 127.127.1.0 stratum 10
#設定層級的優先級别
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
# service ntpd restart
Shutting down ntpd: [ FAILED]
Starting ntpd: [ OK ]
# ntpq -p
remote refid st t when poll reach delay offset jitter
=============================================================
52.165.34.139 .INIT. 16 u - 64 0 0.000 0.000 0.000
*LOCAL(0) .LOCL. 10 l 1 64 3 0.000 0.000 0.000
(測試ntpd伺服器是否生效,及性能。offset 值越小說明 時間相差越少。)
如果需要的話還可以 加入開機啟動。
一般安裝系統的時候預設安裝開啟。
# chkconfig ntpd on
# chkconfig --list | grep ntpd
ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
141(用戶端)
# yum install ntpdate -y
# which ntpdate
/usr/sbin/ntpdate
# date -s '2016-1-3'
# /usr/sbin/ntpdate 192.168.1.140
7 Feb 00:01:31 ntpdate[26508]: step time server 192.168.1.140 offset 34646299.836629 sec
中間出現不可用。
問題出在防火牆和seliux(在140關閉)
可以寫入contab -e (每小時零點同步)
0 */1 * * * /usr/sbin/ntpdate 192.168.1.140 >>/data/logs/ntp.log 2>&1
需要注意的是:如果ntp伺服器出現時間不正常。可以停掉服務。利用ntpdate 同步時間後在開啟ntpd服務。
低核心的linux開啟NTP服務将出現閏秒現象。會造成開啟ntp服務的linux伺服器重新開機。
預防措施:在閏秒即将來臨時先關閉伺服器,過後重新開機即可。
還可以配置win7與配置的時間伺服器同步:
點選工作列的時間==》更改日期和時間設定=》Internet時間==》更改設定==》伺服器:後面的預設設定删除填寫自己配置的ntp伺服器的ip位址==》确定。
本文轉自 swallow_zys 51CTO部落格,原文連結:http://blog.51cto.com/12042068/1895460,如需轉載請自行聯系原作者