CentOS 7 学习笔记(一)时间管理

1 获取当前时间

[[email protected] ~]# date
2015年 05月 22日 星期五 01:30:50 CST

2 获取当前日期

[[email protected] ~]# date  "+%Y%m%d"
20150522

3 获取三天之前日期

[[email protected] ~]# date -d "-3 days" "+%Y%m%d"
20150519

4 获取三天之后的日期

[[email protected] ~]# date -d "+3 days" "+%Y%m%d"
20150525

5 获得月末日期

[[email protected] ~]# cal|xargs|awk ‘{ print $NF }‘|sed ‘s/ //g‘
31

6 查看时区

[[email protected] ~]# date -R
Fri, 22 May 2015 01:45:26 +0800 (+0800 表示东八区)

7 设置时间

[[email protected] ~]# date 0522082515
2015年 05月 22日 星期五 08:25:00 CST
或者
[[email protected] ~]# date -s "2015-05-22 08:25:22"
2015年 05月 22日 星期五 08:25:22 CST

[[email protected] ~]# hwclock -r   //读入BIOS时间
2015年05月22日 星期五 01时50分54秒  -0.726681 秒
[[email protected] ~]# hwclock -w   //向BIOS写入时间
[[email protected] ~]# hwclock -r
2015年05月22日 星期五 08时26分08秒  -0.582655 秒

8 检测时区配置

[[email protected] sysconfig]# timedatectl
      Local time: 五 2015-05-22 08:30:02 CST
  Universal time: 五 2015-05-22 00:30:02 UTC
        RTC time: 五 2015-05-22 00:29:44
        Timezone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

9 列出所有时区

[[email protected] sysconfig]# timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
Africa/Brazzaville

10 设置时区

[[email protected] sysconfig]# timedatectl set-timezone Asia/Shanghai (设置系统时区为上海)
[[email protected] sysconfig]# timedatectl set-local-rtc 0 # 将硬件时钟调整为与本地时钟一致, 0 为设置为 UTC 时间

11 NTP服务(端口123)

/usr/sbin/ntpdate xxx.xxx.xxx.xxx 手工与指导ntp服务器同步时间

NTP服务进程:

[[email protected] ntp]# ps -ef|grep ntp|grep -v grep
ntp        4304      1  0 08:32 ?        00:00:00 /usr/sbin/ntpd -u ntp:ntp -g

启动NTP服务:

[[email protected] ntp]# systemctl start ntpd.service
[[email protected] ntp]# systemctl status ntpd.service
ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled)
   Active: active (running) since 五 2015-05-22 08:44:05 CST; 3s ago
  Process: 4398 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 4399 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─4399 /usr/sbin/ntpd -u ntp:ntp -g

5月 22 08:44:05 limt01 ntpd[4399]: Listen and drop on 1 v6wildcard :: UDP 123
5月 22 08:44:05 limt01 ntpd[4399]: Listen normally on 2 lo 127.0.0.1 UDP 123
5月 22 08:44:05 limt01 ntpd[4399]: Listen normally on 3 eno16777736 192.168.1.104 UDP 123
5月 22 08:44:05 limt01 ntpd[4399]: Listen normally on 4 lo ::1 UDP 123
5月 22 08:44:05 limt01 ntpd[4399]: Listen normally on 5 eno16777736 fe80::20c:29ff:fe38:2d00 UDP 123
5月 22 08:44:05 limt01 ntpd[4399]: Listening on routing socket on fd #22 for interface updates
5月 22 08:44:05 limt01 ntpd[4399]: 0.0.0.0 c016 06 restart
5月 22 08:44:05 limt01 ntpd[4399]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
5月 22 08:44:05 limt01 ntpd[4399]: 0.0.0.0 c011 01 freq_not_set
5月 22 08:44:06 limt01 ntpd[4399]: 0.0.0.0 c614 04 freq_mode

ntpdate 与 ntpd 不能同时使用

查看NTP同步状态:

[[email protected] ntp]# /usr/sbin/ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+news.neu.edu.cn 236.43.203.76    2 u   67   64    3   16.655    7.426   1.443
*dns2.synet.edu. 202.118.1.46     2 u    2   64    3   15.917    8.520   1.687

配置文件/etc/ntp.conf

[[email protected] ntp]# less /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 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 ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# 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

#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

# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor
时间: 2024-08-02 22:05:38

CentOS 7 学习笔记(一)时间管理的相关文章

Linux学习笔记一 磁盘管理常用命令

Linux学习笔记一 磁盘管理常用命令 Linux系统下,一切均是文件,磁盘是一种特殊的块设备文件. 常用的硬盘接口类型 并口:IDE ,SCSI 串口:SATA,SAS 磁盘设备文件设备文件的命令规则: IDE: 设备名为/dev/hda, /dev/hdb-.  (末尾的a ,b-代表不同的IDE硬盘) SCSI:设备名为/dev/sda, /dev/sdb-.(末尾的a,b-代表不用的SCSI硬盘 机械式硬盘: track: 磁道(盘面上由外向里划分成不同的磁道) cylinder: 柱面

计算机操作系统学习笔记_4_进程管理 --处理机调度

h3.western { font-family: "Liberation Sans",sans-serif; }h3.cjk { font-family: "微软雅黑"; }h3.ctl { font-family: "AR PL UMing CN"; }h1 { margin-bottom: 0.21cm; }h1.western { font-family: "Liberation Sans",sans-serif; f

oracle学习笔记之用户管理-3

用户权限机制 1.不同用户表权限的赋予 grant select on scott.emp to software; ---当前登录用户为表所有者,则表名前不用指定所属用户 2.用software登录后 select * from scott.emp; ---software才有权限查询到scott的emp表 方案(schema) 当用户创建好后,如果该用户创建了一个数据对象(如表),此时dbms会创建一个对应的方案与改用户对应,并且该方案的名称和用户名称一致. system与scott都拥有自

oracle学习笔记之用户管理-2

案例:创建一个用户software,然后给分配权限,可以让software登录数据库.创建表.操作自己创建的表,回收角色,最后删除用户. 1.创建software用户,密码system create user software identified by system; 2.让software连接数据库,需要给其connect.resource权限 grant connect to software; grant resource to software; 3.使用software用户登录 co

Object C学习笔记25-文件管理(一)

在此篇文章中简单记录一下文件管理,在Object C中NSFileManager用于管理文件已经路径.在Object C中的文件路径可以是相对路径也可以是绝对路径.斜线"/"开头,斜线实际上就是一个目录,称为 根目录.字符(-)用作用户主目录的缩写.点" . "表示当前目录,两点"  .. "表示父目录. 一. 创建NSFileManager 对象 NSFileManager非常简单,可以使用如下方式来创建NSFileManager对象. NSS

linux kernel学习笔记-5内存管理(转)

http://blog.sina.com.cn/s/blog_65373f1401019dtz.htmllinux kernel学习笔记-5 内存管理1. 相关的数据结构 相比用户空间而言,在内核中分配内存往往受到更多的限制,比如内核中很多情况下不能睡眠,此外处理内存分配失败也不像用户空间那么容易.内核使用了页和区两种数据结构来管理内存: 1.1 页 内核把物理页作为内存管理的基本单位.尽管CPU的最小可寻址单位通常为字(甚至字节),但是MMU(内存管理单元,管理内存并把虚拟地址转换为物理地址的

oracle学习笔记之用户管理-1

sys    system(管理员) scott(普通用户) sqlserver sa 前提:oracle 上,假如自己是管理员,当需要建立用户的时候,由自己操作: 1.创建用户(sys system用户) create user username identified by password; 注意:密码不能以数字开头 create user mmy identified by system; 创建的mmy用户,并不能通过conn立刻登录,需要进行下面一步 2.赋予用户相应的权限 grant

Qt学习笔记-Widget布局管理

Qt学习笔记4-Widget布局管理 以<C++ GUI Programming with Qt 4, Second Edition>为参考 实例:查找对话框 包含三个文件,finddialog.h,finddialog.cpp及main.cpp. //finddialog.h代码 #ifndef FINDDIALOG_H#define FINDDIALOG_H #include <QDialog> class QCheckBox;class QLabel;class QLineE

Linux System Programming 学习笔记(五) 进程管理

1. 进程是unix系统中两个最重要的基础抽象之一(另一个是文件) A process is a running program A thread is the unit of activity inside of a process the virtualization of memory is associated with the process, the threads all share the same memory address space 2. pid The idle pro

Object C学习笔记26-文件管理(二)

上一篇简单的介绍了如何获取文件属性,删除,拷贝文件等,本文继续记录Object C中文件IO操作. 一. 获取文件的执行主目录 在Object C中提供了一个方法 NSHomeDirectory() 用于获得执行执行的主目录,使用如下代码测试: NSString *homePath=NSHomeDirectory(); NSLog(@"执行文件的主目录:%@",homePath); 通过以上代码可以正确的输出应用程序的执行目录,上一张也提到了文件的目录问题,这个和Windows系统的有