Linux常用系统管理命令
-
netstat
-
-n
或--numeric
直接使用IP地址,而不通过域名服务器。 -
-t
或--tcp
显示TCP传输协议的连线状况。 -
-u
或--udp
显示UDP传输协议的连线状况。 -
-l
或--listening
显示监控中的服务器的Socket。 -
-p
或--programs
显示正在使用Socket的程序识别码和程序名称;-
netstat -ntulp
查看开放了哪些端口 -
netstat -a
显示详细网络状况 -
netstat -nu
查看当前活跃UDP连接状况 -
netstat -apu
显示UDP端口号使用情况 -
netstat -i
显示网卡列表 -
netstat -g
显示组播组的关系 -
netstat -s
显示网络统计信息 -
netstat -l
显示监听的套接字接口
-
-
-
lsof -i:80
显示与指定端口相关的网络信息
lsof -i 用以显示符合条件的进程情况
lsof -i[46] [protocol][@hostname|hostaddr][:service|port]
46 --> IPv4 or IPv6
protocol --> TCP or UDP
hostname --> Internet host name
hostaddr --> IPv4地址
service --> /etc/service中的 service name (可以不止一个)
port --> 端口号 (可以不止一个)
-
lsof -i 显示所有打开的端口
-
lsof -i:80
显示所有打开80端口的进程 -
lsof -i -U 显示所有打开的端口和UNIX domain文件
服务管理:
-
service ngix start
-
service apache2 start
启动服务 -
service apache2 restart
重启服务 -
service apache2 stop
停止服务 -
service apache2 reload
重新加载配置文件(不终止服务) -
service apache2 status
查看服务状态
-
-
systemctl
systemd是linux系统中最新的初始化系统(init),systemctl是一个systemd工具,主要负责控制systemd系统和服务管理器。
-
systemctl start ngix.service
启动服务 -
systemctl restart mysql
重启服务 -
systemctl stop mysql
停止服务 -
systemctl reload apache2
重新加载配置文件(不终止服务) -
systemctl status apache2
查看服务状态 -
systemctl enable mysql
开机自动启动 -
systemctl disable mysql
开机不自动启动 -
systemctl is-enabled apache2
查看特定服务是否为开机自动启动 -
systemctl list-unit-files --type=service
查看各个级别下服务的启动与禁用情况
-
-
/etc/ini.d/ngix start
init.d
目录包含许多系统各种服务的启动和停止脚本。为了能够使用init.d
目录下的脚本,需要有root权限或sudo权限。每个脚本都将被作为一个命令运行,该命令的结构大致如下:/etc/init.d/command 选项
command是实际运行的命令,选项有如下几种:
start
stop
reload
restart
force-reload
例子:
-
关闭网络
/etc/init.d/networking stop
-
改变网络设置,需要重启网络
/etc/init.d/networking restart
-
init.d
目录下常用初始化脚本- networking
- samba
- apache2
- ftpd
- sshd
- dovecot
- mysql
理解Linux系统/etc/init.d目录和/etc/rc.local脚本
-
ps
ps aux
可以查看系统中所有的进程ps -le
可以查看系统中所有的进程,而且还能看到进程的父进程的PID和进程的优先级ps -l
只能看到当前Shell产生的进程