When the server is more, time is accurate or not, the same is a big problem. Although this problem is always overlooked, it is necessary to unify the time. Here's how to configure a Linux time server within a LAN.
Configuration of the environment and requirements:
Assume that in the 192.168.0.0 network segment, a Linux machine time server with IP 192.168.0.101 is needed.
192.168.0.101 Server can Sisu network, can be synchronized with the more authoritative public network time server
Automatically synchronizes time to 192.168.0.101 per hour for other machines in the same network segment
1. Install the NTP service and back up the configuration file
[Plain]View PlainCopy
- Yum Install NTP
- Chkconfig ntpd on
- cd/etc/
- MV Ntp.conf Ntp.conf.bak
2. vi/etc/ntp.conf, enter the following configuration:
[Plain]View PlainCopy
- #设置此服务器同上层服务器做时间同步的IP地址, prefer means the preferred IP address
- #经试验, the next few times the server is pretty fast.
- Server 210.72.145.44 prefer
- Server 218.21.130.42
- Server 0.asia.pool.ntp.org
- Server 1.asia.pool.ntp.org
- Server 2.asia.pool.ntp.org
- The time spent #记录上次的NTP server joins the upper NTP server
- Driftfile/etc/ntp/drift
- #设置默认策略为允许任何主机进行时间同步
- Restrict default Ignore
- #设置允许访问此时间服务器的时间服务的IP地址
- #根据自己实际情况配置
- Restrict 127.0.0.1
- Restrict 192.168.10.2 # Specify a machine time synchronization
- Restrict 192.168.0.0 mask 255.255.255.0 #允许192.168.0.0/254 in-subnet host time synchronization
- Restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap #允许任何主机跟进行时间同步
- #指定阶层编号为10, reducing its priority.
- Fudge 127.127.1.1 Stratum 10
- #设置ntp日志的path
- statsdir/var/log/ntp/
- #设置ntp日志文件
- Logfile/var/log/ntp/ntp.log
3. Maintenance of NTP Server
[Plain]View PlainCopy
- ----added as a service
- Chkconfig--level 345 ntpd on
- ----Start
- Service NTPD Start
- Or
- /ETC/RC.D/INIT.D/NTPD start
- ----Stop
- Service NTPD Stop
- Or
- /ETC/RC.D/INIT.D/NTPD stop
- ----Management Commands
- Ntpq–p #查看本机和上层服务器的时间同步结果
- Ntptrace #可以用來追踪某台时间服务器的时间对应关系
- Ntpdate IP #客户端要和NTP server for clock synchronization.
- /var/log/ntp/ntp.log #查看ntp日志
4. Configure Client Linux client: (Time-required machine in LAN)
Clock synchronization with NTP server hourly and write to native BIOS
[Plain]View PlainCopy
- echo "*/1 * * * * root/usr/sbin/ntpdate 192.168.0.240;/sbin/hwclock-w" >>/etc/crontab
-------------------------------------------------------------------------------------1.4 Configuring time synchronization between clusters 1.4.1 Configure the primary Time service node in the cluster
1) Check if NTP server is installed
Rpm–qa|grep NTP;
2) Modify the configuration file/etc/ntp.conf
Modify three Places
1. Open Restrict 192.168.60.0 mask 255.255.255.0 nomodify notrap;
2. Comment out
#server 0.centos.pool.ntp.org Iburst
#server 1.centos.pool.ntp.org Iburst
#server 2.centos.pool.ntp.org Iburst
#server 3.centos.pool.ntp.org Iburst
3. Add
Server 127.127.1.0
Fudge 127.127.1.0 Stratum 10
3) Modify the configuration file/etc/sysconfig/ntpd
In the first line add: Sync_hwclock=yes
4) Start the NTP service
1. Check that there is no boot
Service NTPD status;
2. Start
Service NTPD start;
3. Set the next system boot, NTPD automatically start
Chkconfig ntpd on;
5) Set the time of the CDH1 node
Execute Date-s 17:55:00, after the modification, remember to execute the CLOCK-W, the system time to write to the CMOS.
1.4.2 configuration in the cluster from the Time service node
In Cdh2, CDH3, CDH4 cluster, set synchronization time every 10 seconds;
To be set under root user is only valid.
Crontab–e;
0-59/10 * * * * */usr/sbin/ntpdate CDH1;
Manual Sync Time
/usr/sbin/ntpdate Cdh1;
Linux configuration NTP server, time synchronization