学习服务管理(一)

查看服务管理

windows    
win键 + r快捷键,打开运行窗口,输入如下指令
services.msc
linux
systemctl list-units --type service --all

systemctl管理服务命令

在Centos7之前,通过service 和 chkconfig两个命令来管理服务
service命令用于对系统服务进行管理,比如启动(start)、停止(stop)、重启(restart)、重新加载配置(reload)、查看状态(status)等。

# service mysqld        #打印指定服务mysqld的命令行使用帮助。

# service mysqld start    #启动mysqld

# service mysqld stop    #停止mysqld

# service mysqld restart    #重启mysqld
chkconfig: 指定服务是否开机启动

提供了一个维护/etc/rc[0~6] d 文件夹的命令行工具,它减轻了系统直接管理这些文件夹中的符号连接的负担。chkconfig主要包括5个原始功能:为系统管理增加新的服务、为系统管理移除服务、列出单签服务的启动信息、改变服务的启动信息和检查特殊服务的启动状态。当单独运行chkconfig命令而不加任何参数时,他将显示服务的使用信息。

[root@localhost www]# chkconfig --list    #查看系统程序列表

[root@localhost www]# chkconfig httpd on  #将httpd加入开机启动

[root@localhost www]# chkconfig httpd off  #关闭httpd开机启动
从Centos7开始,统一使用systemctl来管理服务, systemctl同时具有service和chkconfig命令的功能。
systemctl(英文全拼:system control)用于控制 systemd 系统和管理服务。

语法
systemctl 选项  服务名

status:检查指定服务的运行状况

start:启动指定服务

stop:停止指定服务

restart:重启指定服务

reload:重新加载指定服务的配置文件(并非所有服务都支持reload,通常使用restart)

enable:指定服务开机自动启动

disable:取消服务开机自动启动

is-enabled :查看是否设置了开机自启

ntp时间同步服务

NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。

NTP就是用来解决这个问题的,NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。

它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。

timedatectl 命令

timedatectl(英文全拼:timedate control)命令用于在 Linux 中设置或查询系统时间、日期和时区等配置。
用法
timedatectl [OPTIONS...] COMMAND ...

命令command
status :显示当前的时间设置。
show :显示 systemd-timedated 的属性。
set-time TIME :设置系统时间。
set-timezone ZONE :设置系统时区。
list-timezones :显示已知时区。
set-local-rtc BOOL :控制 RTC 是否在当地时间。(BOOL 的值可以是 1 / true 或 0 / false)
set-ntp BOOL :启用或禁用网络时间同步。(BOOL 的值可以是 1 / true 或 0 / false)
timesync-status :显示 systemd-timesyncd 的状态。
show-timesync :显示 systemd-timesyncd 的属性。

使用timedatectl命令,修改系统时区为``阿姆斯特丹``(Europe/Amsterdam)

[root@localhost ~]# timedatectl set-timezone 'Europe/Amsterdam'
[root@localhost ~]# timedatectl show
Unknown operation show
[root@localhost ~]# timedatectl status
      Local time: Sat 2022-03-19 12:36:17 CET
  Universal time: Sat 2022-03-19 11:36:17 UTC
        RTC time: Sat 2022-03-19 19:36:16
       Time zone: Europe/Amsterdam (CET, +0100)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: no
 Last DST change: DST ended at
                  Sun 2021-10-31 02:59:59 CEST
                  Sun 2021-10-31 02:00:00 CET
 Next DST change: DST begins (the clock jumps one hour forward) at
                  Sun 2022-03-27 01:59:59 CET
                  Sun 2022-03-27 03:00:00 CEST

使用timedatectl命令,修改系统时区为上海,"Asia/Shanghai"

[root@localhost ~]# timedatectl show
Unknown operation show
[root@localhost ~]# timedatectl status
      Local time: Sat 2022-03-19 12:36:17 CET
  Universal time: Sat 2022-03-19 11:36:17 UTC
        RTC time: Sat 2022-03-19 19:36:16
       Time zone: Europe/Amsterdam (CET, +0100)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: no
 Last DST change: DST ended at
                  Sun 2021-10-31 02:59:59 CEST
                  Sun 2021-10-31 02:00:00 CET
 Next DST change: DST begins (the clock jumps one hour forward) at
                  Sun 2022-03-27 01:59:59 CET
                  Sun 2022-03-27 03:00:00 CEST
[root@localhost ~]# timedatectl set-timezone "Asia/Shanghai"
[root@localhost ~]#  timedatectl status
      Local time: Sat 2022-03-19 19:37:18 CST
  Universal time: Sat 2022-03-19 11:37:18 UTC
        RTC time: Sat 2022-03-19 19:37:17
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
[root@localhost ~]# 

如何同步系统时间到正确互联网。

[root@localhost ~]# timedatectl set-ntp true
[root@localhost ~]# date
Sat Mar 19 19:55:55 CST 2022
[root@localhost ~]# 

如何同步系统时间到硬件时间

[root@localhost ~]# timedatectl set-local-rtc 0
[root@localhost ~]# timedatectl | grep local
 RTC in local TZ: no
[root@localhost ~]#  timedatectl set-local-rtc 1
[root@localhost ~]# timedatectl | grep local
 RTC in local TZ: yes
Warning: The system is configured to read the RTC time in the local time zone.
         'timedatectl set-local-rtc 0'.
[root@localhost ~]# 

posted @ 2022-03-20 20:42  张开嘴  阅读(74)  评论(0编辑  收藏  举报