Linux_服务管理
一、服务的概念
操作系统中在后台持续运行的程序,本身并没有操作界面,需要通过端口号访问和操作。CentOS 6 和 CentOS 7 的服务管理有很大区别,我们分别来看。
二、CentOS6 服务
1、service 命令
启动服务:service 服务名 start
停止服务:service 服务名 stop
重启服务:service 服务名 restart
重新加载服务:service 服务名 reload
查看服务状态:service 服务名 status
2、chkconfig 命令
查看服务列表:chkconfig [–list]
设置具体服务开机自动启动状态:chkconfig 服务名 on/off
3、运行级别
vim /etc/inittab 查看系统配置。
CentOS6 系统使用 0~6 这 7 个数字来控制 Linux 系统的启动方式。
运行级别 0:系统停机状态,系统默认运行级别不能设为 0,否则不能正常启动
运行级别 1:单用户工作状态,root 权限,用于系统维护,禁止远程登陆
运行级别 2:多用户状态(没有 NFS),没有网络服务
运行级别 3:完全的多用户状态(有 NFS),登录后进入控制台命令行模式
运行级别 4:系统未使用,保留
运行级别 5:X11 表示控制台,进入图形界面
运行级别 6:系统正常关闭并重启,默认运行级别不能设为 6,否则不能正常启动
常用的是 3 或 5。
chkconfig 命令使用–level 参数和一个数值可以控制一个服务在某个运行级别的是否自动启动。
4、防火墙
防火墙默认会阻止绝大部分端口号的访问,在实际生产环境下,运维工程师需要为服务器设置详细的访问规则。在练习过程中,我们为了方便建议把防火墙直接关闭。由于防火墙服务默认开机自动启动,所以除了停止服务,还要设置为开机不自动启动。
服务名:iptables
停止防火墙
1 | service iptables stop |
设置开机不自动启动
1 | chkconfig iptables off |
三、CentOS7 服务
1、systemctl 命令
启动服务:systemctl start 服务名(xxxx.service)
重启服务:systemctl restart 服务名(xxxx.service)
停止服务:systemctl stop 服务名(xxxx.service)
重新加载服务:systemctl reload 服务名(xxxx.service)
查看服务状态:systemctl status 服务名(xxxx.service)
2、systemctl 命令代替 chkconfig 命令
查看服务状态
1 | systemctl list-unit-files |
设置或取消服务开机自动启动:
设置开机自动启动:systemctl enable 服务名
取消开机自动启动:systemctl disable 服务名
3、CentOS7 简化了运行级别
1 | cat /etc/inittab |
# inittab is no longer used when using systemd.
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
# systemd uses ‘targets’ instead of runlevels. By default, there are two main targets:
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5# To view current default target, run:
# systemctl get-default# To set a default target, run:
# systemctl set-default TARGET.target
4、关闭防火墙
1 | systemctl disable firewalld.service |