Linux 命令使用笔记【systemctl】

systemctl 命令

 

systemctl 命令是系统服务管理器指令,它实际上将 service 和 chkconfig 这两个命令组合到一起。

任务

旧指令

新指令

使某服务自动启动

chkconfig --level 3 httpd on

systemctl enable httpd.service

使某服务不自动启动

chkconfig --level 3 httpd off

systemctl disable httpd.service

检查服务状态

service httpd status

systemctl status httpd.service (服务详细信息) systemctl is-active httpd.service (仅显示是否 Active)

显示所有已启动的服务

chkconfig --list

systemctl list-units --type=service

启动某服务

service httpd start

systemctl start httpd.service

停止某服务

service httpd stop

systemctl stop httpd.service

重启某服务

service httpd restart

systemctl restart httpd.service

命令

  • -h --help Show this help
  • --version Show package version
  • --system Connect to system manager
  • -H --host=[USER@]HOST 在远程主机上操作
  • -M --machine=CONTAINER 本地集装箱操作
  • -t --type=TYPE 列出特定类型的单元
  • --state=STATE 列出具有特定负载或子状态或活动状态的单元
  • -p --property=NAME 仅以此名称显示属性
  • -a --all 显示所有加载的单位/属性,包括死亡/空的。要列出系统上安装的所有单元,请使用“list-unit-files”命令。
  • -l --full 不要在输出中使用椭圆表示单元名称
  • -r --递归显示主机和本地容器的单元列表
  • --reverse 使用“列表依赖”显示反向依赖关系
  • --job-mode=MODE Specify 如何处理已排队作业,当排队新作业
  • --show-types 在显示套接字时,显式地显示其类型
  • -i --ignore-inhibitors 当关闭或睡眠时,忽略抑制因素
  • --kill-who=WHO 向谁发送信号
  • -s --signal=SIGNAL 发送哪个信号
  • --now 启动或停止单元,除了启用或禁用它
  • -q --quiet 抑制输出
  • --no-block 不要等到操作完成
  • --no-wall 在停止/关闭/重启之前不要发送墙消息
  • --no-reload 不要在en-/ disabling单元文件后重新加载守护进程
  • --no-legend 不要打印图例(列标题和提示)
  • --no-pager 不将输出管道传输到分页器
  • --no-ask-password 不要求输入系统密码
  • --global 全局启用/禁用单元文件
  • --runtime 仅临时启用单元文件,直到下一次重新启动
  • -f --force 当启用单元文件时,覆盖现有的符号链接。当关闭时,立即执行动作
  • --preset-mode= 仅应用启用,仅禁用,或所有预设
  • --root=PATH 在指定的根目录中启用单元文件
  • -n --lines=INTEGER 要显示的日志条目数
  • -o --output=STRING 改变日志输出模式(short, short-iso,short-precise, short-monotonic, verbose,export, json, json-pretty, json-sse, cat)
  • --plain 以列表而不是树的形式打印单元依赖项

实例

1.启动 nfs 服务

systemctl start nfs-server.service

2.设置开机自启动

systemctl enable nfs-server.service

3.停止开机自启动

systemctl disable nfs-server.service

4.查看服务当前状态

systemctl status nfs-server.service

5.重新启动某服务

systemctl restart nfs-server.service

6.查看所有已启动的服务

systemctl list -units --type=service

开启防火墙22端口

iptables -I INPUT -p tcp --dport 22 -j accept

如果仍然有问题,就可能是SELinux导致的

关闭 SElinux:

修改 /etc/selinux/config 文件中的 SELINUX=””为disabled,然后重启。

彻底关闭防火墙:

sudo systemctl status firewalld.service 
sudo systemctl stop firewalld.service           
sudo systemctl disable firewalld.service

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章