码迷,mamicode.com
首页 > 系统相关 > 详细

linux服务

时间:2017-02-20 23:11:58      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:ntp ntpdate crontab

1 学习一个软件服务配置的步骤

1 搞懂这个技术,服务是做什么,功能是什么,用途在哪,为什么要用它
2 这个软件安装的方式,在服务端安装,还是客户端安装,安装命令是什么
3 该软件安装完毕后,路经在哪里,配置文件在哪里,启动文件在哪里
4 配置文件里面的内容是什么,参数的含义是什么
5 如何启动服务,怎么查看是否已经启动,端口号是多少
必须监听一个端口 ntp UDP-123 
6 这个软件和服务都部署好了,怎么验证,怎么使用

2 ntp服务

a NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。
b 安装
NTP服务器监听端口为UDP的123,那就需要在本地防火墙开启运行客户端访问123端口,vi /etc/sysconfig/iptables添加如下规则:
-AINPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT
关闭防火墙的命令:
service stop firewalld 
关闭Selinux软件服务:
Setenforce 0 临时关闭
Sestatus查看selinux的状态,为disabled就OK了。
NTP时间服务器配置:
yum install ntp ntpdate -y 即可!
修改ntp.conf配置文件
cp  /etp/ntp.conf /etc/ntp.conf.bak 
vi/etc/ntp.conf 只修改如下两行,把#号去掉即可!
server 127.127.1.0     #local clock
fudge  127.127.1.0stratum 10
以守护进程启动ntpd 
/etc/init.d/ntpd start 即可
(注意*: ntpd启动后,客户机要等几分钟再与其进行时间同步,否则会提示“no server suitable for synchronization found”错误。)
以下是ntp服务器配置文件内容(局域网NTP,如果需要跟外网同步,添加外网server即可) 
driftfile  /var/lib/ntp/drift
restrict   default kod nomodify notrap nopeer noquery
restrict-6 default kod nomodify notrap nopeer noquery
restrict127.0.0.1 
restrict-6 ::1
server   127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10
includefile/etc/ntp/crypto/pw
keys  /etc/ntp/keys

c 查看安装的ntp路经
[root@57135test ~]# rpm -ql ntp |more
/etc/ntp.conf
[root@57135test ~]# systemctl restart ntpd
d  查看是否启动
[root@57135test ~]# ps -ef|grep ntp
ntp       23526      1  0 04:00 ?        00:00:00 /usr/sbin/ntpd -u ntp:ntp -g
root      23549  22795  0 04:01 pts/1    00:00:00 grep --color=auto ntp
e 服务器监听的所有端口
[root@57135test ~]# netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp6       0      0 :::3306                 :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN
[root@57135test ~]# netstat -nul
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
udp        0      0 192.168.57.135:123      0.0.0.0:*                          
udp        0      0 127.0.0.1:123           0.0.0.0:*                          
udp        0      0 0.0.0.0:123             0.0.0.0:*                          
udp        0      0 0.0.0.0:25831           0.0.0.0:*                          
udp        0      0 0.0.0.0:68              0.0.0.0:*                          
udp6       0      0 fe80::20c:29ff:fe62:123 :::*                               
udp6       0      0 ::1:123                 :::*                               
udp6       0      0 :::123                  :::*                               
udp6       0      0 :::6678
注:
   ntp与ntpdate的区别
   服务端安装配置好ntp服务后,局域网内的其它机器可以直接使用ntpdate IP 可以保证局域网所有的服务器与时间服务器的时间保持一致
   ntpdate直接与时间服务器同步,可以配置到定时任务中
   [root@57135test ~]# ntpdate pool.ntp.org
f 配置时间同步客户机
crontab -e 
增加一行,在每天的6点10分与时间同步服务器进行同步
10 06 * * * /usr/sbin/ntpdate ntp-server的ip>>/usr/local/logs/crontab/ntpdate.log
分 时 日 月 周  命令 
注:命令要使用绝对路径,crontab精确到分钟
    安装:[root@57135test ~]# yum -y install crontab*
    重启:[root@57135test ~]# systemctl status crond





本文出自 “卓尔的博客” 博客,请务必保留此出处http://6874869.blog.51cto.com/6864869/1899640

linux服务

标签:ntp ntpdate crontab

原文地址:http://6874869.blog.51cto.com/6864869/1899640

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!