day15 ntp时间的服务
day15_scp和npt服务
回顾systemctl
-
你的机器会有默认的软件,network管理软件的工具,还有sshd提供远程连接的软件,这些我们统称为
*服务* -
对这些服务进行管理
- 启动---start
- 停止-- stop
- 重载 -- reload
- 开机自启 -- enable
- 禁止开机自启 -- unable
- 查询是否开机自启 -- is-enabled
linux服务器一般使用systemctl 对于服务器的管理 systemctl start/stop/restart/reload/enable/unenable/is-enabled 服务的名字 这个命令属于对centos6提供的2个命令,做了一个整合 service 这个命令,linux的命令,大多数都是去机器上找到某个文件,然后读取文件配置,加载功能 service旧的命令,是默认去 /etc/init.d/目录下寻找(服务管理脚本文件) 然后根据你的指令 service start/stop network (/etc/init.d/network) service 服务名 启停指令 然后会去读取 /etc/init.d目录下的脚本 我们在用centos6的时候,自己安装了某软件,比如nginx网站,但是没有方便的启停管理脚本 自己写nginx启停脚本,然后放到/etc/init.d/nginx 然后就可以调用 serivce nginx start chkconfig 两个命令整合了 现在,都用这个指令了更方便,强大 systemctl 指令 服务的名字 例如 systemctl status network [root@linux-yzk ~]# systemctl status network ● network.service - LSB: Bring up/down networking Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled) Active: active (exited) since 二 2025-03-04 11:30:44 CST; 15min ago Docs: man:systemd-sysv-generator(8) Process: 955 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS) Tasks: 0 3月 04 11:30:44 linux-yzk systemd[1]: Starting LSB: Bring up/down networ.... 3月 04 11:30:44 linux-yzk network[955]: 正在打开环回接口: [ 确定 ] 3月 04 11:30:44 linux-yzk systemd[1]: Started LSB: Bring up/down networking. Hint: Some lines were ellipsized, use -l to show in full. [root@linux-yzk ~]#
关于systemctl命令其实是找到脚本

*其实你使用的是systemctl start stop restart *
都是去找到这个脚本,然后传入你的参数,在去start或者stop
例如service命令启动
[root@linux-yzk ~]# service network status
已配置设备:
lo ens33
当前活跃设备:
lo ens33 virbr0
[root@linux-yzk ~]#
例如脚本的启动
[root@linux-yzk ~]# /etc/init.d/network start
Starting network (via systemctl): [ 确定 ]
[root@linux-yzk ~]#
其实也等同于systemctl start network
刚才关注到 service是去读取 /etc/init.d/目录下的脚本
centos7中的脚本目录不一样
系统默认的所有服务,管理脚本的存放目录,以及你自己安装了某软件,也可以放入到这个目录下,就可以通过systemctl start/stop 去管理了
[root@linux-yzk ~]# yum install nginx
已加载插件:fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
epel | 4.3 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
软件包 1:nginx-1.20.1-10.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@linux-yzk ~]#
一个概念是通过yum安装程序,会自动的生成nginx的管理的脚本,并会在systemctl管理脚本的目录下
systemctl 统一管理脚本在/usr/lib/systemd/system
举个例子:如ssh 服务
[root@linux-yzk ~]# ll /usr/systemd/system/ssh*
ls: 无法访问/usr/systemd/system/ssh*: 没有那个文件或目录
[root@linux-yzk ~]# ll /usr/lib/systemd/system/ssh*
-rw-r--r--. 1 root root 313 8月 5 2023 /usr/lib/systemd/system/sshd-keygen.service
-rw-r--r--. 1 root root 373 8月 5 2023 /usr/lib/systemd/system/sshd.service
-rw-r--r--. 1 root root 260 8月 5 2023 /usr/lib/systemd/system/sshd@.service
-rw-r--r--. 1 root root 181 8月 5 2023 /usr/lib/systemd/system/sshd.socket
nginx 服务
[root@linux-yzk ~]# ll /usr/lib/systemd/system/ngin*
-rw-r--r--. 1 root root 653 11月 11 2022 /usr/lib/systemd/system/nginx.service
/usr/lib/systemd/system/nginx.service.d:
总用量 0
[root@linux-yzk ~]#

理解systemctl 管理脚本的流程

-
这是Linux的sshd 软件,的脚本的存放的位置
-
我们通过systemctl 管理服务,其实是调用的是这个脚本
-
这个脚本是帮我们启动程序的,
简单来说 对于执行服务的命令是执行这个脚本
因此我们不必去那么麻烦的执行脚本 太痛苦了
直接用systemctl 的命令即可,
ntp时间服务的部署
- 先理解时间对服务器的重要性
- 全世界的服务器,时间统一标准,可以以这个为准,cn.ntp.org.cn
- 学习linux的各种命令,对时间来修改,以及同步
- *查看当前的是时间 * timedatectl
[root@linux-yzk ~]# timedaectl
bash: timedaectl: 未找到命令...
[root@linux-yzk ~]# timedatectl
Local time: 二 2025-03-04 12:24:55 CST
Universal time: 二 2025-03-04 04:24:55 UTC
RTC time: 二 2025-03-04 04:24:55
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
[root@linux-yzk ~]#
ntp的时间的同步
- 强制性更新整个系统的时间,ntpdate,不友好的强制同步时间
- 搭建ntp服务,自动的,友好的更新,校准系统时间
强制更新时间的ntpdate命令
[root@linux-yzk ~]# ntpdate -u ntp.aliyun.com
4 Mar 12:27:27 ntpdate[4173]: adjust time server 203.107.6.88 offset 0.028749 sec
搭建ntpd 服务
所有linux的软件,用法都一样
- 安装
- 改配置
- 启动
- 使用
- 以后,就是继续改配置,重新加载,重启
- 继续使用
1.安装ntpd 服务
[root@linux-yzk ~]# yum install ntp -y
2.查看ntp服务的软件的信息
[root@linux-yzk ~]# ll /usr/lib/systemd/system/ntp*
-rw-r--r--. 1 root root 272 11月 28 2019 /usr/lib/systemd/system/ntpdate.service
-rw-r--r--. 1 root root 249 11月 28 2019 /usr/lib/systemd/system/ntpd.service
[root@linux-yzk ~]#
3.修改配置的文件
浙公网安备 33010602011771号