Linux 设置时间同步命令

CentOs查看当前系统所用的时区,设置ntpd授时服务之前先调整好时区,例如集群中提供授时服务主机IP为192.168.3.1

[[email protected] conf]$ date -R
Mon, 08 Jun 2015 19:24:39 +0800

若不是我们的时区,将时区设置为东8区的时间

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Mon, 08 Jun 2015 19:24:39 +0800

修改ntpd服务配置文件vim /etc/ntp.conf

# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
#restrict default kod nomodify notrap nopeer noquery
#restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1 
#restrict -6 ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.3.0 mask 255.255.255.0 nomodify
restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap noquery notrust

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
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
server 127.127.1.0

#broadcast 192.168.1.255 autokey	# broadcast server
#broadcastclient			# broadcast client
#broadcast 224.0.1.1 autokey		# multicast server
#multicastclient 224.0.1.1		# multicast client
#manycastserver 239.255.254.254		# manycast server
#manycastclient 239.255.254.254 autokey # manycast client

# Enable public key cryptography.
#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography. 
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8

# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats

重新启动 service ntpd start 服务作为集群中提供授时服务的主机,先利用网络时间更新好授时主机192.168.3.1的时间

ntpdate  0.cn.pool.ntp.org 
/sbin/hwclock -w

然后在集群上其他主机上设置crontab服务,同步更新自己时间

crontab -e
10 16 * * * (/usr/sbin/ntpdate 192.168.3.1 && /sbin/hwclock -w) >> /var/log/ntpdate.log

#每天下午16:10同步授时主机上的时间
时间: 2024-12-16 05:22:19

Linux 设置时间同步命令的相关文章

Linux设置快捷命令

vi ~/.bashrc 在.bashrc目录中,添加 alias 设置 例如 cdtools='cd ~/GIT/tools' 对于一条比较长的命令,如显示系统运行时长 cat /proc/uptime| awk -F. '{run_days=$1 / 86400;run_hour=($1 % 86400)/3600;run_minute=($1 % 3600)/60;run_second=$1 % 60;printf("系统已运行:%d天%d时%d分%d秒\n",run_days,

linux设置时间同步

设定时区:dpkg-reconfigure tzdata选择Asia -> 再选择Shanghai -> OK同步时间命令:1.sudo apt-get install ntpdate // 安装时间同步工具2.sudo ntpdate cn.pool.ntp.org // 与网络服务器同步时间3.date // 查看时间是否已同步 原文地址:https://blog.51cto.com/14579193/2445411

Linux 系统常用命令汇总(七) 安全设置

 安全设置 分类 命令 选项 注解 安全策略 selinux setenforce number(0,1) 设置selinux状态,0关闭,1开启 getenforce 显示当前selinux状态,enforcing表示启用,permissive表示关闭 防火墙 iptables 三个表:filter,nat,mangle 例如:iptables -A INPUT -p tcp --dport 22 -j ACCEPT -A(-I,-D) 增加(插入,删除)一条规则 INPUT(OUTPUT,F

linux设置时间服务器

对多个linux服务器,时间保持一致是很必要的.根据精确度要求,应该有相应的时间间隔进行时间同步.如果不进行时间同步,时间久了就会差别很大,遇到问题时定位就很困难.因为多台设备的配合,log之间可能有前因后果,时间是同步事件的先后的重要依据. 一般来说,对一个机房内的设备,可以设置一台时间服务器,由它定期从一个标准的时间服务器上获取时间.其他的服务器可以通过内网的连接从这台服务器进行同步.这样不仅时间会一致,而且照顾到一些没有公网的设备. 本文测试系统: [[email protected] ~

【系统知识点】linux基础&优化命令

Xshell上传下载服务器的文件: yum -y install lrzsz sysstat//安装对应软件 sz XXXX//下载 rz XXXX//上传 创建用户: Useradd vrfxie //创建用户 -c comment 指定一段注释性描述. -d 目录 指定用户主目录,如果此目录不存在,则同时使用-m选项,可以创建主目录. -g 用户组 指定用户所属的主用户组. -G 用户组,用户组 指定用户所属的附加组. -s Shell文件 指定用户的登录Shell. #可以设置为/sbin

Linux之简单命令之日期时间命令之date,cal,clock ,hwclock和tzselect

一.date命令: 在linux环境中,不管是编程还是其他维护,时间是必不可少的,也经常会用到时间的运算,熟练运用date命令来表示自己想要表示的时间,肯定可以给自己的工作带来诸多方便. 1.命令格式: date [参数]... [+格式] 2.命令功能: date 可以用来显示或设定系统的日期与时间. 3.命令参数: 必要参数: %H 小时(以00-23来表示).  %I 小时(以01-12来表示).  %K 小时(以0-23来表示).  %l 小时(以0-12来表示).  %M 分钟(以00

每天一个linux之touch命令

linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件. 文件存在三个时间戳(可用stat查看): access time:访问时间,简写为atime,读取文件内容 modify time: 修改时间, mtime,改变文件内容(数据) change time: 改变时间, ctime,元数据发生改变 1.命令格式: touch [选项]... 文件... 2.命令参数:   -a 或--time=atime或--time=access

Linux 服务器时间同步

Linux 服务器时间同步 Linux服务器运行久时,系统时间就会存在一定的误差,一般情况下可以使用date命令进行时间设置,但在做数据库集群分片等操作时对多台机器的时间差是有要求的,此时就需要使用ntpdate进行时间同步. 1.安装ntpd [[email protected] node1]# yum install ntpd 手动同步时间: [[email protected] node1]# ntpdate ntp.api.bz ntp常用服务器: 中国国家授时中心:210.72.145

Linux系统上命令的使用格式

简述: 在学习Linux系统时,必不可少的要接触命令的使用方法和格式,下面通过详细介绍ifconfig.echo.tty.startx.export.pwd.history.shutdown.poweroff.reboot.hwclock.date等Linux常用命令的使用方法,来了解Linux系统上命令的使用格式. 正文: Linux系统命令使用格式: #COMMAND  [OPTIONS...]  [ARGUMENTS...] COMMAND :命令:一个可执行的二进制程序文件 OPTION