2 Star 1 Fork 0

zhrun8899 / learning-notes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
centos7 systemd 介绍.md 4.10 KB
一键复制 编辑 原始数据 按行查看 历史

centos7 systemd 介绍

启动服务:service NAME start --> systemctl start NAME.service
停止服务:service NAME stop --> systemctl stop NAME.service
重启服务:service NAME restart --> systemctl restart NAME.service
查看状态:service NAME status --> systemctl status NAME.service
条件式重启服务:service NAME condrestart--> systemctl try-restart-NAME.service
重载或重启服务:systemctl reload-or-restart NAME.service
重载或条件式重启:systemctl reload-or-try-restart NAME.service
查看某服务当前激活与否的状态: systemctl  is-active NAME.service   
查看所有已激活的服务:systemctl list-units -t service   
查看所有服务(激活和未激活):chkconfig --list-->systemctl list-units -t service -a
查看所有服务的开机自启状态:chkconfig --list --> systemctl list-unit-files --type service
设置服务开机自启:chkconfig NAME on --> systemctl enable NAME.service
禁止服务开机自启:chkconfig NAME off --> systemctl disable NAME.service
查看某服务是否能开机自启:chkconfig --list NAME --> systemctl is-enabled NAME.service
禁止某服务设定为开机自启或手动启动:systemctl mask NAME.service
取消禁止某服务设定为开机自启或手动启动:systemctl unmask NAME.service
查看服务的依赖关系:systemctl list-dependencies NAME.service
用来列出该服务在哪些运行级别下启用和禁用:chkconfig sshd –list ==>ls /etc/systemd/system/*.wants/sshd.service
杀掉进程:systemctl kill 进程名
查看服务状态:
systemctl list-units --type service --all显示状态
loaded:Unit配置文件已处理
active(running):一次或多次持续处理的运行
active(exited):成功完成一次性的配置
active(waiting):运行中,等待一个事件
inactive:不运行
enabled:开机启动
disabled:开机不启动
static:开机不启动,但可被另一个启用的服务激活

 

systemctl命令示例:

显示所有单元状态
    systemctl 或 systemctl list-units
只显示服务单元的状态
    systemctl --type=service
显示sshd服务单元
    systemctl status sshd.service -l
验证sshd服务当前是否活动
    systemctl is-active sshd
启动,停止和重启sshd服务
    systemctl start sshd.service
    systemctl stop sshd.service
    systemctl restart sshd.service
重新加载配置
    systemctl reload sshd.service
列出活动状态的所有服务单元
    systemctl list-units --type=service
列出所有服务单元
    systemctl list-units --type=service --all
查看服务单元的启用和禁用状态。
    systemctl list-unit-files --type=service
列出失败的服务
    systemctl --failed --type=service
列出依赖的单元
    systemctl list-dependencies sshd
验证sshd服务是否开机启动
    systemctl is-enabled sshd
禁用network,使之不能自动启动,但手动可以
    systemctl disable network
启用network
    systemctl enable network
禁用network,使之不能手动或自动启动
    systemclt mask network
启用network
    systemctl umask network

/etc/systemd/system:系统管理员和用户使用 /usr/lib/systemd/system:发行版打包者使用

登录信息 登录前:etc/issue 避免暴露系统版本信息 登录后:/etc/motd 内部信息 wall广播

groups //该命令可查看登录用户所支持的用户组

1)/etc/passwd 用户登记文件 2)/etc/shadow 密码文件 3)/etc/group 组信息 4)/var/spool/mail 邮件信息 5)/home

useradd -g 主组 -G 副组(逗号区分) 用户名 
userdel -r user1 

#如果userdel user1删除,会留下用户家目录和用户邮箱

1.把用户加入组

1).usermod -g grp1 user1
2).usermod -G grp1 user1
3).gpasswd -a user1 grp1
#把用户user1加入组grp1

2.把用户从组删除

1).gpasswd -d user1 grp1
#把用户user1从grp1组中删除

2.把用户从组删除 1).gpasswd -d user1 grp1 #把用户user1从grp1组中删除

五、用户与文件的关系-权限:

1.chmod 2.chown 3.setuid 4.setgid 5.sudo 6.acl

2)设置sudo 2-1)visudo 2-2)vi /etc/sudoers #不推荐第二种方法 user1 localhost=/usr/sbin/useradd user5,/usr/sbin/userdel -r user5,/sbin/service httpd restart

1
https://gitee.com/zhrun8899/learning-notes.git
git@gitee.com:zhrun8899/learning-notes.git
zhrun8899
learning-notes
learning-notes
master

搜索帮助