__都非拉得的博客

Posted on 08 Dec 2017

网络命令

$ ip link show                  # 显示网络接口信息
$ ip link set eth0 upi          # 开启网卡
$ ip link set eth0 down         # 关闭网卡
$ ip link set eth0 promisc on   # 开启网卡的混合模式
$ ip link set eth0 promisc offi # 关闭网卡的混个模式
$ ip link set eth0 txqueuelen 1200    # 设置网卡队列长度
$ ip link set eth0 mtu 1400     # 设置网卡最大传输单元
$ ip addr show                  # 显示网卡IP信息
$ ip addr add 192.168.0.1/24 dev eth0 # 设置eth0网卡IP地址192.168.0.1
$ ip addr del 192.168.0.1/24 dev eth0 # 删除eth0网卡IP地址

$ ip route list                 # 查看路由信息
$ ip route add 192.168.4.0/24  via  192.168.0.254 dev eth0 # 设置192.168.4.0网段的网关为192.168.0.254,数据走eth0接口
$ ip route add default via  192.168.0.254  dev eth0    # 设置默认网关为192.168.0.254
$ ip route del 192.168.4.0/24    # 删除192.168.4.0网段的网关
$ ip route del default    # 删除默认路由

systemctl命令

$ systemctl --version # 版本
$ systemd-analyze # 分析systemd启动进程
$ systemd-analyze blame #分析启动时各个进程花费的时间
$ systemd-analyze critical-chain # 分析启动时的关键链
$ systemctl list-unit-files #列出所有可用单元
$ systemctl list-units # 列出所有运行中单元
$ systemctl --failed # 列出所有失败单元
$ systemctl is-enabled crond.service # 检查某个单元是否启用
$ systemctl status firewalld.service # 检查某个单元或服务是否运行

使用Systemctl控制并管理服务

# 列出所有服务(包括启用的和禁用的)
$ systemctl list-unit-files --type=service 

# Linux中如何启动、重启、停止、重载服务以及检查服务(如 httpd.service)状态
$ systemctl start httpd.service # 启动
$ systemctl restart httpd.service # 重启
$ systemctl stop httpd.service # 停止
$ systemctl reload httpd.service # 重载
$ systemctl status httpd.service # 检查服务状态
# 当我们使用systemctl的start,restart,stop和reload命令时,我们不会从终端获取到任何输出内容,只有status命令可以打印输出。


# 如何激活服务并在启动时启用或禁用服务(即系统启动时自动启动服务)
$ systemctl is-active httpd.service # 激活服务
$ systemctl enable httpd.service # 启用服务
$ systemctl disable httpd.service # 禁用服务

# 如何屏蔽(让它不能启动)或显示服务(如 httpd.service)
$ systemctl mask httpd.service
ln -s '/dev/null' '/etc/systemd/system/httpd.service'
$ systemctl unmask httpd.service
rm '/etc/systemd/system/httpd.service'

# 使用systemctl命令杀死服务
$ systemctl kill httpd
$ systemctl status httpd

# 列出所有系统挂载点
$ 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

# 在Linux中屏蔽(让它不能启用)或可见挂载点
$ systemctl mask tmp.mount
ln -s '/dev/null' '/etc/systemd/system/tmp.mount'
$ systemctl unmask tmp.mount
rm '/etc/systemd/system/tmp.mount'

使用Systemctl控制并管理套接口

# 列出所有可用系统套接口
$ systemctl list-unit-files --type=socket

# 在Linux中启动、重启、停止、重载套接口并检查其状态
$ systemctl start cups.socket
$ systemctl restart cups.socket
$ systemctl stop cups.socket
$ systemctl reload cups.socket
$ systemctl status cups.socket

# 在启动时激活套接口,并启用或禁用它(系统启动时自启动)
$ systemctl is-active cups.socket
$ systemctl enable cups.socket
$ systemctl disable cups.socket

# 屏蔽(使它不能启动)或显示套接口
$ systemctl mask cups.socket
ln -s '/dev/null' '/etc/systemd/system/cups.socket'
$ systemctl unmask cups.socket
rm '/etc/systemd/system/cups.socket'

服务的CPU利用率(分配额)

# 获取当前某个服务的CPU分配额(如httpd)
$ systemctl show -p CPUShares httpd.service
CPUShares=1024
# 注意:各个服务的默认CPU分配份额=1024,你可以增加/减少某个进程的CPU分配份额。

#将某个服务(httpd.service)的CPU分配份额限制为2000 CPUShares/
$ systemctl set-property httpd.service CPUShares=2000
$ systemctl show -p CPUShares httpd.service
CPUShares=2000

#注意:当你为某个服务设置CPUShares,会自动创建一个以服务名命名的目录(如 httpd.service),里面包含了一个名为90-CPUShares.conf的文件,该文件含有CPUShare限制信息,你可以通过以下方式查看该文件:
$ vi /etc/systemd/system/httpd.service.d/90-CPUShares.conf 
[Service]
CPUShares=2000 


#检查某个服务的所有配置细节
$ systemctl show httpd

# 分析某个服务(httpd)的关键链
$ systemd-analyze critical-chain httpd.service

# 获取某个服务(httpd)的依赖性列表
$ systemctl list-dependencies httpd.service

#  按等级列出控制组
$ systemd-cgls

# 按CPU、内存、输入和输出列出控制组
$ systemd-cgtop

控制系统运行等级

# 启动系统救援模式
$ systemctl rescue

# 进入紧急模式
$ systemctl emergency

# 列出当前使用的运行等级
$ systemctl get-default

# 启动运行等级5,即图形模式
$ systemctl isolate runlevel5.target
或
$ systemctl isolate graphical.target

# 启动运行等级3,即多用户模式(命令行)
$ systemctl isolate runlevel3.target
或
$ systemctl isolate multiuser.target

# 设置多用户模式或图形模式为默认运行等级
$ systemctl set-default runlevel3.target
$ systemctl set-default runlevel5.target

# 重启、停止、挂起、休眠系统或使系统进入混合睡眠
$ systemctl reboot
$ systemctl halt
$ systemctl suspend
$ systemctl hibernate
$ systemctl hybrid-sleep

Runlevel 0 : 关闭系统
Runlevel 1 : 救援?维护模式
Runlevel 3 : 多用户,无图形系统
Runlevel 4 : 多用户,无图形系统
Runlevel 5 : 多用户,图形化系统
Runlevel 6 : 关闭并重启机器

网络接口命名规则:

如:enp0s3

* 基于接口类型的两个字母前缀:
*   en -- 以太网
*   sl -- 串行线路IP (slip)
*   wl -- wlan
*   ww -- wwan
*
* 名字类型:
*   b<number>                             -- BCMA总线和新书
*   ccw<name>                             -- CCW总线组名
*   o<index>                              -- 车载设备的索引号
*   s<slot>[f<function>][d<dev_port>]     -- 热插拔插槽索引号
*   x<MAC>                                -- MAC 地址
*   [P<domain>]p<bus>s<slot>[f<function>][d<dev_port>]
*                                         -- PCI 位置
*   [P<domain>]p<bus>s<slot>[f<function>][u<port>][..]1[i<interface>]
*                                         -- USB端口号链