Linux学习&复盘(八):进程&服务
CentOS7.0 后不再使用service ,而是systemctl
service服务名[start | stop | restart | reload | status]
- 查看当前防火墙的状况,关闭防火墙和重启防火墙。
2)这种方式只是临时生效,当重启系统后,还是回归以前对服务的设置。
如果希望设置某个服务自启动或关闭永久生效,要使用chkconfig 指令,
查看服务名:
方式1:使用setup -> 系统服务就可以看到。
Linux 系统有7 种运行级别(runlevel):常用的是级别3 和5
- 运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动
- 运行级别1:单用户工作状态,root 权限,用于系统维护,禁止远程登陆
- 运行级别2:多用户状态(没有NFS),不支持网络
- 运行级别3:完全的多用户状态(有NFS),登陆后进入控制台命令行模式
- 运行级别4:系统未使用,保留
- 运行级别5:X11 控制台,登陆后进入图形GUI 模式
- 运行级别6:系统正常关闭并重启,默认运行级别不能设为6,否则不能正常启动
开机的流程说明
- chkconfig 指令介绍
通过chkconfig 命令可以给每个服务的各个运行级别设置自启动/关闭
1) chkconfig服务名--list
2) chkconfig--level5服务名on/off
14.5.8 应用实例:
- 案例1:请显示当前系统所有服务的各个运行级别的运行状态
bash> chkconfig --list
- 案例2 :请查看sshd 服务的运行状态
bash> service sshd status
6) 案例6:在所有运行级别下,开启防火墙
bash> chkconfigiptableson
14.5.9 • 使用细节
chkconfig 重新设置服务后自启动或关闭,需要重启机器reboot 才能生效
centos 7+
网络服务
启动、重启、停止、重载服务
-
# systemctl start httpd.service
-
# systemctl restart httpd.service
-
# systemctl stop httpd.service
-
# systemctl reload httpd.service
-
# systemctl status httpd.service
**/禁止自动启动
-
# systemctl enable httpd.service
-
# systemctl disable httpd.service
使用Systemctl控制并管理挂载点:
-
systemctl list-unit-files --type=mount
-
-
# systemctl start tmp.mount
-
# systemctl stop tmp.mount
-
# systemctl restart tmp.mount
-
# systemctl reload tmp.mount
-
# systemctl status tmp.mount
-
-
# systemctl is-active tmp.mount
-
# systemctl enable tmp.mount
-
# systemctl disable tmp.mount
-
-
# systemctl mask tmp.mount
使用Systemctl管理服务的CPU利用率
-
# systemctl show -p CPUShares httpd.service
-
-
# systemctl set-property httpd.service CPUShares=2000
-
# systemctl show -p CPUShares httpd.service
-
-
# systemctl show httpd
常用
启动防火墙——systemctl start firewalld.service
停止防火墙——systemctl stop firewalld.service
查看firewalld防火墙状态——firewall-cmd --state
禁止防火墙开机启动——systemctl disable firewalld.service
列出正在运行的服务状态——systemctl
启动一个服务——systemctl start postfix.service
关闭一个服务——
systemctl stop postfix.service
重启一个服务:——
systemctl restart postfix.service
显示一个服务的状态——
systemctl status postfix.service
在开机时启用一个服务——
systemctl enable postfix.service
在开机时禁用一个服务——
systemctl disable postfix.service
查看服务是否开机启动——
systemctl is-enabled postfix.service
查看已启动的服务列表——
systemctl list-unit-files|grep enabled
top 与ps 命令很相似。它们都用来显示正在执行的进程。Top 与ps 最大的不同之处,在于top 在执行一段时间可以更新正在运行的的进程。
指定系统状态更新的时间(每隔10 秒自动更新,默认是3 秒):
bash> top -d 10
top 系统当前时间 up 系统到目前为止运行的时间, 当前登陆系统的用户数量, load average后面分别表示距离现在1min,5min,15min的负载 |
tasks任务(进程),204 total:现在总共有204个进程,运行中:1个,休眠(挂起):203个,停止的进程:0,僵尸的进程:0个。 |
cpu状态:us:user 用户空间占用cpu的百分比 sy:system 内核空间占用cpu的百分比 ni:niced 改变过优先级的进程占用cpu的百分比 id:空闲cpu百分比 wa:IO wait IO等待占用cpu的百分比 hi:Hardware IRQ 硬中断 占用cpu的百分比 si:software 软中断 占用cpu的百分比 st:被hypervisor偷去的时间 |
内存状态:物理内存总量(2G),空闲内存总量(0.7G),使用中的内存总量(27M),缓冲内存量 |
swap交换分区:交换区总量(2G),使用的交换区总量(0G),可用交换取总量2G, 使用389M |
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND |
PID — 进程id
USER — 进程所有者
PR — 进程优先级
NI — nice值。负值表示高优先级,正值表示低优先级
VIRT — 进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
RES — 进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
SHR — 共享内存大小,单位kb
S — 进程状态。D=不可中断的睡眠状态 R=运行 S=睡眠 T=跟踪/停止 Z=僵尸进程
%CPU — 上次更新到现在的CPU时间占用百分比
%MEM — 进程使用的物理内存百分比
TIME+ — 进程使用的CPU时间总计,单位1/100秒
COMMAND — 进程名称(命令名/命令行)
终止指定的进程。
top:输入此命令,按回车键,查看执行的进程。
k:然后输入“k”回车,再输入要结束的进程ID 号
监视特定用户
top:输入此命令,按回车键,查看执行的进程。
u:然后输入“u”回车,再输入用户名,即可
netstat查看系统网络状态(重要)
基本语法netstat -anp
- 选项说明
-an按一定顺序排列输出
-p显示哪个进程在调用