在开启一天的学习的时候先做好快照过程中如果出现意外的报错解决不了的就立即恢复快照作为初学者省时省力不要过于纠结哪里错了浪费时间windows 开机的时候有些程序自动启动了。命令行运行services.msc查看相关服务的启动情况1.systemd 介绍1.1 基本概念CentOS 7 使用 Systemd 引导系统启动速度最快所有进程无论有无依赖关系则都是并行启动很多时候进程没有真正启动而是只有一个信号或者说是标记而已在真正利用的时候才会真正启动。Systemd为了解决上文的问题而诞生。它的目标是为系统的启动和管理提供一套完整的解决方案。系统引导程序用户空间systemdpid为1内核空间kthreaddpid为2服务从业务角度来称呼例如 web 服务数据库服务。守护进程daemonweb 服务器对外提供 web 服务由 web 相关的进程提供支持。以web服务为例服务web服务守护进程httpd万和提供培训服务服务培训云计算守护进程课程顾问、代课老师、就业老师等。例如# 安装软件包 [rootcentos7 ~ 11:12:41]# yum install -y httpd # 启动服务 [rootcentos7 ~ 11:12:59]# systemctl start httpd # 查看进程 [rootcentos7 ~ 11:13:31]# ps -C httpd f PID TTY STAT TIME COMMAND 4706 ? Ss 0:00 /usr/sbin/httpd -DFOREGROUND 4709 ? S 0:00 \_ /usr/sbin/httpd -DFOREGROUND 4710 ? S 0:00 \_ /usr/sbin/httpd -DFOREGROUND 4711 ? S 0:00 \_ /usr/sbin/httpd -DFOREGROUND 4712 ? S 0:00 \_ /usr/sbin/httpd -DFOREGROUND 4713 ? S 0:00 \_ /usr/sbin/httpd -DFOREGROUNDhttpd 服务对应的守护进程是4706、4709...47131.2 systemd 架构守护进程systemd由守护进程干活。工具systemctl提供给用户用来跟机器交互的工具。1.3 unit 类型systemctl 命令用于管理不同类型的系统对象这些对象称之为units。Service unit用于定义系统服务文件扩展名为.service例如httpd.serviceSocket unit用于标识进程间通信用的 socket文件文件扩展名为.socketTarget unit用于模拟实现“运行级别”文件扩展名为.targetTimer unit用于管理计划任务文件扩展名为.timerDevice unit用于定义内核识别的设备文件扩展名为.deviceMount unit用于定义文件系统挂载点文件扩展名为.mountSnapshot unit管理系统快照文件扩展名为.snapshotSwap unit用于标识swap设备文件扩展名为.swapAutomount unit文件系统的自动挂载点文件扩展名为.automountPath unit用于根据文件系统上特定对象的变化来启动其他服务文件扩展名为.pathSlice unit用于资源管理文件扩展名为.slice1.4 查看 unit 列表信息# 列出状态为loaded units [rootcentos7 ~ 11:32:38]# systemctl list-unitssystemctl list-units命令输出说明UNIT服务单元名称。LOADsystemd是否正确解析了单元的配置并将该单元加载到内存中。ACTIVE单元的高级别激活状态。此信息表明单元是否已成功启动。SUB单元的低级别激活状态。此信息指示有关该单元的更多详细信息。信息视单元类型、 状态以及单元的执行方式而异。DESCRIPTION单元的简短描述。# -t选项查看特定类型unit 清单 [rootcentos7 ~ 11:34:55]# systemctl list-units -t timer UNIT LOAD ACTIVE SUB DESCRIPTION systemd-tmpfiles-clean.timer loaded active waiting Daily Cleanup of Temporary Direc unbound-anchor.timer loaded active waiting daily update of the root trust a LOAD Reflects whether the unit definition was properly loaded. ACTIVE The high-level unit activation state, i.e. generalization of SUB. SUB The low-level unit activation state, values depend on unit type. 2 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use systemctl list-unit-files. # 列出类型为service状态为active和inactive unit [rootcentos7 ~ 11:35:58]# systemctl list-units --type service --all UNIT LOAD ACTIVE SUB DESCRIPTION abrt-ccpp.service loaded active exited Install ABRT coredump hoo abrt-oops.service loaded active running ABRT kernel log watcher abrt-vmcore.service loaded inactive dead Harvest vmcores for ABRT abrt-xorg.service loaded active running ABRT Xorg log watcher abrtd.service loaded active running ABRT Automated Bug Report accounts-daemon.service loaded active running Accounts Service alsa-restore.service loaded inactive dead Save/Restore Sound Card S alsa-state.service loaded active running Manage Sound Card State ( ● apparmor.service not-found inactive dead apparmor.service atd.service loaded active running Job spooling tools ·········· # 列出系统中所有unit包括未loaded的unit [rootcentos7 ~ 11:35:03]# systemctl list-unit-files UNIT FILE STATE proc-sys-fs-binfmt_misc.automount static dev-hugepages.mount static dev-mqueue.mount static proc-fs-nfsd.mount static proc-sys-fs-binfmt_misc.mount static run-vmblock\x2dfuse.mount disabled sys-fs-fuse-connections.mount static sys-kernel-config.mount static sys-kernel-debug.mount static tmp.mount disabled var-lib-nfs-rpc_pipefs.mount static brandbot.path disabled cups.path enabled systemd-ask-password-console.path static ············· # 查看失败的服务 [rootcentos7 ~ 11:37:34]# systemctl --failed --type service 0 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use systemctl list-unit-files.1.5 查看单个 unit 信息[fengkaicentos7 ~ 13:35:31]$ systemctl status sshd.service ● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since 三 2026-07-22 08:31:31 CST; 5h 7min ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 1205 (sshd) Tasks: 1 CGroup: /system.slice/sshd.service └─1205 /usr/sbin/sshd -D 7月 22 08:31:31 centos7.cloud systemd[1]: Starting OpenSSH server daemon... 7月 22 08:31:31 centos7.cloud sshd[1205]: Server listening on 0.0.0.0 port 22. 7月 22 08:31:31 centos7.cloud sshd[1205]: Server listening on :: port 22. 7月 22 08:31:31 centos7.cloud systemd[1]: Started OpenSSH server daemon. 7月 22 08:34:09 centos7.cloud sshd[2194]: Accepted password for fengkai from 10.1.8.1 port 51023 ssh2 7月 22 09:07:30 centos7.cloud sshd[2607]: Accepted password for fengkai from 10.1.8.1 port 58696 ssh2 7月 22 09:09:12 centos7.cloud sshd[2664]: Accepted password for fengkai from 10.1.8.1 port 58848 ssh2 7月 22 09:13:03 centos7.cloud sshd[2785]: Accepted password for fengkai from 10.1.8.1 port 59005 ssh2 7月 22 09:57:31 centos7.cloud sshd[3320]: Accepted password for fengkai from 10.1.8.1 port 60996 ssh2关键字概述loaded单元配置文件已处理active(running)正在运行active(exited)已成功完成一次性配置active(waiting)运行中正在等待事件inactive不再运行enabled系统引导时启动disabled系统引导时不启动static无法启动依赖其他单元启动2.控制系统服务命令任务systemctl statusUNIT查看单元状态的详细信息。systemctl stopUNIT在运行中的系统上停止一项服务。systemctl startUNIT在运行中的系统上启动一项服务。systemctl restartUNIT在运行中的系统上重新启动一项服务。systemctl reloadUNIT重新加载运行中服务的配置文件。systemctl maskUNIT禁用服务使其无法手动启动或在系统引导时启动。systemctl unmaskUNIT使屏蔽的服务变为可用。systemctl enableUNIT将服务配置为在系统引导时启动。使用--now选项也会启动该服务。systemctl disableUNIT禁止服务在系统引导时启动。使用--now选项也会停止该服务。# 停止服务 [rootcentos7 ~ 13:36:48]# systemctl stop sshd.service [rootcentos7 ~ 13:56:23]# systemctl status sshd ● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: inactive (dead) since 三 2026-07-22 13:56:23 CST; 43s ago Docs: man:sshd(8) man:sshd_config(5) Process: 1205 ExecStart/usr/sbin/sshd -D $OPTIONS (codeexited, status0/SUCCESS) Main PID: 1205 (codeexited, status0/SUCCESS) 7月 22 08:31:31 centos7.cloud sshd[1205]: Server listening on :: port 22. 7月 22 08:31:31 centos7.cloud systemd[1]: Started OpenSSH server daemon. 7月 22 08:34:09 centos7.cloud sshd[2194]: Accepted password for fengkai from 10.1.8.1 port 51023 ssh2 7月 22 09:07:30 centos7.cloud sshd[2607]: Accepted password for fengkai from 10.1.8.1 port 58696 ssh2 7月 22 09:09:12 centos7.cloud sshd[2664]: Accepted password for fengkai from 10.1.8.1 port 58848 ssh2 7月 22 09:13:03 centos7.cloud sshd[2785]: Accepted password for fengkai from 10.1.8.1 port 59005 ssh2 7月 22 09:57:31 centos7.cloud sshd[3320]: Accepted password for fengkai from 10.1.8.1 port 60996 ssh2 7月 22 13:56:23 centos7.cloud sshd[1205]: Received signal 15; terminating. 7月 22 13:56:23 centos7.cloud systemd[1]: Stopping OpenSSH server daemon... 7月 22 13:56:23 centos7.cloud systemd[1]: Stopped OpenSSH server daemon. # 客户端连接测试 [rootcentos7 ~ 13:57:07]# ssh fengkailocalhost ssh: connect to host localhost port 22: Connection refused # 启动服务 [rootcentos7 ~ 13:57:48]# systemctl start sshd.service # 客户端连接测试 [rootcentos7 ~ 13:58:20]# ssh fengkailocalhost The authenticity of host localhost (::1) cant be established. ECDSA key fingerprint is SHA256:5KkrnsINIP6anjuKXNFLmX2lITpgeyRlv6uEWtvRkgU. ECDSA key fingerprint is MD5:70:76:1e:4b:c6:85:44:ff:03:02:07:29:53:d9:1a:f8. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added localhost (ECDSA) to the list of known hosts. fengkailocalhosts password: Last login: Wed Jul 22 09:57:32 2026 from 10.1.8.1 [fengkaicentos7 ~ 13:58:33]$ # 重启服务相当于stop再startPID由6727变为6799 [rootcentos7 ~ 14:00:32]# systemctl status sshd ● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since 三 2026-07-22 14:00:22 CST; 17s ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 6727 (sshd) Tasks: 1 CGroup: /system.slice/sshd.service └─6727 /usr/sbin/sshd -D 7月 22 14:00:22 centos7.cloud systemd[1]: Stopped OpenSSH server daemon. 7月 22 14:00:22 centos7.cloud systemd[1]: Starting OpenSSH server daemon... 7月 22 14:00:22 centos7.cloud sshd[6727]: Server listening on 0.0.0.0 port 22. 7月 22 14:00:22 centos7.cloud sshd[6727]: Server listening on :: port 22. 7月 22 14:00:22 centos7.cloud systemd[1]: Started OpenSSH server daemon. [rootcentos7 ~ 14:00:39]# systemctl restart sshd [rootcentos7 ~ 14:01:23]# systemctl status sshd ● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since 三 2026-07-22 14:01:23 CST; 3s ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 6799 (sshd) Tasks: 1 CGroup: /system.slice/sshd.service └─6799 /usr/sbin/sshd -D 7月 22 14:01:23 centos7.cloud systemd[1]: Stopped OpenSSH server daemon. 7月 22 14:01:23 centos7.cloud systemd[1]: Starting OpenSSH server daemon... 7月 22 14:01:23 centos7.cloud sshd[6799]: Server listening on 0.0.0.0 port 22. 7月 22 14:01:23 centos7.cloud sshd[6799]: Server listening on :: port 22. 7月 22 14:01:23 centos7.cloud systemd[1]: Started OpenSSH server daemon. # 一般用于配置文件变动后重新加载PID还是6799不变 [rootcentos7 ~ 14:01:26]# systemctl reload sshd.service [rootcentos7 ~ 14:03:05]# systemctl status sshd ● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since 三 2026-07-22 14:01:23 CST; 1min 44s ago Docs: man:sshd(8) man:sshd_config(5) Process: 6836 ExecReload/bin/kill -HUP $MAINPID (codeexited, status0/SUCCESS) Main PID: 6799 (sshd) Tasks: 1 CGroup: /system.slice/sshd.service └─6799 /usr/sbin/sshd -D 7月 22 14:01:23 centos7.cloud systemd[1]: Stopped OpenSSH server daemon. 7月 22 14:01:23 centos7.cloud systemd[1]: Starting OpenSSH server daemon... 7月 22 14:01:23 centos7.cloud sshd[6799]: Server listening on 0.0.0.0 port 22. 7月 22 14:01:23 centos7.cloud sshd[6799]: Server listening on :: port 22. 7月 22 14:01:23 centos7.cloud systemd[1]: Started OpenSSH server daemon. 7月 22 14:03:05 centos7.cloud systemd[1]: Reloading OpenSSH server daemon. 7月 22 14:03:05 centos7.cloud sshd[6799]: Received SIGHUP; restarting. 7月 22 14:03:05 centos7.cloud systemd[1]: Reloaded OpenSSH server daemon. 7月 22 14:03:05 centos7.cloud sshd[6799]: Server listening on 0.0.0.0 port 22. 7月 22 14:03:05 centos7.cloud sshd[6799]: Server listening on :: port 22. # 重新加载服务服务对应的主进程不会重启只会重新加载一次配置文件。 # 禁止服务开机自启 [rootcentos7 ~ 14:03:07]# systemctl disable sshd.service Removed symlink /etc/systemd/system/multi-user.target.wants/sshd.service. [rootcentos7 ~ 14:04:10]# systemctl is-enabled sshd disabled [rootcentos7 ~ 14:04:25]# systemctl status sshd ● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; disabled; vendor preset: enabled) Active: active (running) since 三 2026-07-22 14:01:23 CST; 3min 17s ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 6799 (sshd) CGroup: /system.slice/sshd.service └─6799 /usr/sbin/sshd -D 7月 22 14:01:23 centos7.cloud systemd[1]: Stopped OpenSSH server daemon. 7月 22 14:01:23 centos7.cloud systemd[1]: Starting OpenSSH server daemon... 7月 22 14:01:23 centos7.cloud sshd[6799]: Server listening on 0.0.0.0 port 22. 7月 22 14:01:23 centos7.cloud sshd[6799]: Server listening on :: port 22. 7月 22 14:01:23 centos7.cloud systemd[1]: Started OpenSSH server daemon. 7月 22 14:03:05 centos7.cloud systemd[1]: Reloading OpenSSH server daemon. 7月 22 14:03:05 centos7.cloud sshd[6799]: Received SIGHUP; restarting. 7月 22 14:03:05 centos7.cloud systemd[1]: Reloaded OpenSSH server daemon. 7月 22 14:03:05 centos7.cloud sshd[6799]: Server listening on 0.0.0.0 port 22. 7月 22 14:03:05 centos7.cloud sshd[6799]: Server listening on :: port 22. # 重启系统验证 [rootcentos7 ~ 14:04:03]# reboot # 通过Xshell连接不上 Connecting to 10.1.8.10:22... Could not connect to 10.1.8.10 (port 22): Connection failed. Type help to learn how to use Xshell prompt. # 设置服务开机自启通过VMware直接连接 [rootcentos7 ~ 14:07:51]# systemctl enable sshd.service Created symlink from /etc/systemd/system/multi-user.target.wants/sshd.service to /usr/lib/systemd/system/sshd.service. [rootcentos7 ~ 14:08:03]# systemctl is-enabled sshd enabled # 重启系统验证 [rootcentos7 ~ 14:08:10]# reboot # 通通过Xshell可以连接 Connecting to 10.1.8.10:22... Connection established. To escape to local shell, press CtrlAlt]. Last login: Wed Jul 22 14:07:04 2026 [fengkaicentos7 ~ 14:09:46]$ # 禁用服务服务被禁用后将无法start因为服务的配置文件指向/dev/null [rootcentos7 ~ 14:10:32]# systemctl status sshd ● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since 三 2026-07-22 14:09:03 CST; 1min 43s ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 1171 (sshd) Tasks: 1 CGroup: /system.slice/sshd.service └─1171 /usr/sbin/sshd -D 7月 22 14:09:03 centos7.cloud systemd[1]: Starting OpenSSH server daemon... 7月 22 14:09:03 centos7.cloud sshd[1171]: Server listening on 0.0.0.0 port 22. 7月 22 14:09:03 centos7.cloud sshd[1171]: Server listening on :: port 22. 7月 22 14:09:03 centos7.cloud systemd[1]: Started OpenSSH server daemon. 7月 22 14:09:45 centos7.cloud sshd[2126]: Accepted password for fengkai from 10.1.8.1 port 56569 ssh2 [rootcentos7 ~ 14:10:47]# systemctl mask sshd.service Created symlink from /etc/systemd/system/sshd.service to /dev/null. [rootcentos7 ~ 14:11:02]# systemctl status sshd ● sshd.service Loaded: masked (/dev/null; bad) Active: active (running) since 三 2026-07-22 14:09:03 CST; 2min 0s ago Main PID: 1171 (sshd) CGroup: /system.slice/sshd.service └─1171 /usr/sbin/sshd -D 7月 22 14:09:03 centos7.cloud systemd[1]: Starting OpenSSH server daemon... 7月 22 14:09:03 centos7.cloud sshd[1171]: Server listening on 0.0.0.0 port 22. 7月 22 14:09:03 centos7.cloud sshd[1171]: Server listening on :: port 22. 7月 22 14:09:03 centos7.cloud systemd[1]: Started OpenSSH server daemon. 7月 22 14:09:45 centos7.cloud sshd[2126]: Accepted password for fengkai from 10.1.8.1 port 56569 ssh2 7月 22 14:11:02 centos7.cloud systemd[1]: Current command vanished from the unit file, execution of the com...umed. Hint: Some lines were ellipsized, use -l to show in full. # 取消禁用 [rootcentos7 ~ 14:14:18]# systemctl unmask sshd.service3.unit 配置文件unit 配置文件存放在多个位置/etc /systemd/system/unit.service优先生效。一般是管理员自定义的配置。/usr/lib /systemd/system/unit.service其次生效。软件包自带的默认配置。3.1 配置文件说明示例单元文件/usr/lib/systemd/system/sshd.service说明# 标识该部分为 Unit 配置用于描述服务的基本信息、依赖关系等。 [Unit] # 服务的描述信息说明这是 OpenSSH 服务器守护进程便于管理员识别服务用途。 DescriptionOpenSSH server daemon # 指定服务的文档路径这里指向 sshd 命令的手册页man 8 sshd和配置文件的手册页man 5 sshd_config方便用户查阅帮助。 Documentationman:sshd(8) man:sshd_config(5) # 定义服务的启动顺序sshd 服务必须在 network.target网络服务就绪和 sshd-keygen.serviceSSH 密钥生成服务之后启动确保依赖的资源已准备好。 Afternetwork.target sshd-keygen.service # 表示 sshd 服务 希望 sshd-keygen.service 运行但不是强制依赖。如果 sshd-keygen.service 启动失败sshd 仍会尝试启动通常用于生成初始 SSH 密钥若密钥已存在则不影响。 Wantssshd-keygen.service # 标识该部分为 Service 配置用于定义服务的启动方式、执行命令、重启策略等。 [Service] # 定义服务的类型为 notify表示服务启动后会主动通知 systemd 自己已就绪通过 sd_notify() 函数systemd 会等待这个通知后再继续后续流程确保服务真正可用。 Typenotify # 指定环境变量文件的路径/etc/sysconfig/sshd 中通常定义 OPTIONS 等变量如额外的 sshd 启动参数这些变量会被后续的 ExecStart 引用。 EnvironmentFile/etc/sysconfig/sshd # 服务启动时执行的命令 ExecStart/usr/sbin/sshd -D $OPTIONS # /usr/sbin/sshdsshd 守护进程的可执行文件路径。 # -D表示 sshd 以非守护进程模式运行前台运行因为 systemd 通常管理前台进程便于监控。 # $OPTIONS引用 EnvironmentFile 中定义的额外参数如 -p 2222 指定端口。 # 服务重载配置时执行的命令 ExecReload/bin/kill -HUP $MAINPID # kill -HUP 发送 SIGHUP 信号给 sshd 主进程使其重新加载配置文件无需重启服务。 # $MAINPID 是 systemd 自动维护的服务主进程 ID。 # 定义服务停止时的杀死模式process 表示只杀死服务的主进程sshd 主进程其子进程如已建立的 SSH 连接会被保留避免强制中断现有连接。 KillModeprocess # 定义服务的重启策略当服务因非正常退出如崩溃、信号终止时systemd 会自动重启服务正常退出如主动停止则不重启。 Restarton-failure # 服务重启前的等待时间这里设置为 42 秒避免频繁重启导致资源耗尽。 RestartSec42s # 标识该部分为 Install 配置用于定义服务如何被 启用即系统启动时自动运行。 [Install] # 表示当系统启动到 multi-user.target多用户命令行模式非图形界面时该服务会被自动启动。这是服务器的默认运行级别确保 SSH 服务在系统启动后可用。 WantedBymulti-user.target3.2 开发一个 study 服务3.2.1 开发 studyd 服务主程序 study脚本说明这是一个无限循环的脚本每 5 秒会向/var/log/study.log文件中追加一行包含当前时间的日志内容为[时间]: IM studying [ Linux ]。[rootcentos7 ~ 14:27:30]# vim /usr/local/bin/study#!/bin/bash # 第一行内容是脚本的 解释器声明shebang指定该脚本使用 /bin/bash 作为解释器执行。系统会根据这一行找到对应的 shell 程序来解析后续命令。 # 启动一个无限循环while 是循环关键字true 是一个永远为真的条件因此这个循环会一直执行下去直到被外部终止如 CtrlC。 while true # 循环体的开始标记do 和后面的 done 之间的内容是循环中重复执行的命令。 do # 执行 date 命令获取当前系统时间并通过 $(...) 捕获其输出将结果赋值给变量 DATE。 DATE$(date) # echo 命令输出字符串其中 $DATE 会被替换为变量的值 # 是追加重定向符号将输出内容追加到 /var/log/study.log 文件中 # 最终输出内容类似 Fri Oct 31 10:00:00 CST 2025: IM studying [ Linux ]。 echo $DATE: IM studying [ Linux ] /var/log/study.log # 让脚本暂停执行 5 秒sleep 命令用于延迟单位默认为秒避免循环执行过快。 sleep 5 # 循环体的结束标记与前面的 while 和 do 配合标志着一次循环的结束。 done[rootcentos7 ~ 16:24:17]# chmod x /usr/local/bin/study [rootcentos7 ~ 14:56:07]# ls -l /usr/local/bin/study -rwxr-xr-x. 1 root root 1185 7月 22 14:55 /usr/local/bin/study3.2.2 创建 studyd 服务单元文件# 参考 sshd.service [rootcentos7 ~ 14:56:07]# cp /usr/lib/systemd/system/sshd.service /etc/systemd/system/studyd.service [rootcentos7 ~ 14:57:38]# vim /etc/systemd/system/studyd.service[Unit] Descriptionstudy server daemon [Service] ExecStart/usr/local/bin/study [Install] WantedBymulti-user.target# 通知 systemd 读取 unit 变化 [rootcentos7 ~ 15:01:38]# systemctl daemon-reload # 启用并启动服务 [rootcentos7 ~ 15:02:00]# systemctl enable studyd.service --now Created symlink from /etc/systemd/system/multi-user.target.wants/studyd.service to /etc/systemd/system/studyd.service. # 查看服务状态 [rootcentos7 ~ 15:02:23]# systemctl status studyd.service ● studyd.service - Study server daemon Loaded: loaded (/etc/systemd/system/studyd.service; enabled; vendor preset: disabled) Active: active (running) since 三 2026-07-22 15:02:23 CST; 22s ago Main PID: 3185 (study) Tasks: 2 CGroup: /system.slice/studyd.service ├─3185 /bin/bash /usr/local/bin/study └─3198 sleep 5 7月 22 15:02:23 centos7.cloud systemd[1]: Started Study server daemon.3.2.3 验证日志[rootcentos7 ~ 15:02:46]# tail -f /var/log/study.log 2026年 07月 22日 星期三 15:02:53 CST: IM studying [ Linux ] 2026年 07月 22日 星期三 15:02:58 CST: IM studying [ Linux ] 2026年 07月 22日 星期三 15:03:03 CST: IM studying [ Linux ] 2026年 07月 22日 星期三 15:03:08 CST: IM studying [ Linux ] 2026年 07月 22日 星期三 15:03:13 CST: IM studying [ Linux ] 2026年 07月 22日 星期三 15:03:18 CST: IM studying [ Linux ] 2026年 07月 22日 星期三 15:03:23 CST: IM studying [ Linux ] 2026年 07月 22日 星期三 15:03:28 CST: IM studying [ Linux ] 2026年 07月 22日 星期三 15:03:34 CST: IM studying [ Linux ] 2026年 07月 22日 星期三 15:03:39 CST: IM studying [ Linux ] 2026年 07月 22日 星期三 15:03:44 CST: IM studying [ Linux ] 2026年 07月 22日 星期三 15:03:49 CST: IM studying [ Linux ] ......3.2.4 修改配置自我研究[rootcentos7 ~ 15:13:44]# vim /usr/local/bin/study # 在配置文件中将Linux改为LinuxPthon # 修改配置文件需要重新开启服务 [rootcentos7 ~ 15:17:42]# systemctl restart studyd.service # 如果修改了配置文件里面的文件地址ExecStart/usr/local/bin/study改为ExecStart/usr/ # 需要重新启动daemon [rootcentos7 ~ 15:17:42]# vim /etc/systemd/system/studyd.service [rootcentos7 ~ 15:17:42]# systemctl daemon-reload # 再次查看日志文件内容 [rootcentos7 ~ 15:02:46]# tail -f /var/log/study.log 2026年 07月 22日 星期三 15:35:56 CST: IM studying [ Linux Python ] 2026年 07月 22日 星期三 15:36:01 CST: IM studying [ Linux Python ] 2026年 07月 22日 星期三 15:36:06 CST: IM studying [ Linux Python ] 2026年 07月 22日 星期三 15:36:11 CST: IM studying [ Linux Python ] 2026年 07月 22日 星期三 15:36:16 CST: IM studying [ Linux Python ] 2026年 07月 22日 星期三 15:36:21 CST: IM studying [ Linux Python ] 2026年 07月 22日 星期三 15:36:26 CST: IM studying [ Linux Python ] 2026年 07月 22日 星期三 15:36:31 CST: IM studying [ Linux Python ] 2026年 07月 22日 星期三 15:36:36 CST: IM studying [ Linux Python ] ···········