运行yum时出现/var/run/yum.pid已被锁定
PID为xxxx的另一个程序正在运行的问题解决:
rm -f /var/run/yum.pid
关闭CentOS7的firewalld并启用iptables操作
systemctl stop firewalld ##停止防火墙 firewalld
systemctl disable firewalld ##禁用防火墙 firewalld
systemctl status firewalld ##查看防火墙状态
yum install -y iptables-services iptables-devel.x86_64 iptables.x86_64
systemctl enable iptables ##启用iptables
systemctl start iptables ##启动iptables
systemctl status iptables ##查看iptables状态
SELinux服务有三种配置模式:
enforcing:强制启用安全策略模式,将拦截服务的不合法请求。
permissive:遇到服务越权访问时,只发出警告而不强制拦截。
disabled:对于越权的行为不警告也不拦截。把SELinux当前的运行模式修改为禁用
(通过命令 setenforce [0|1],0代表禁用、1代表启用),
该修改在重启系统后失效,可以通过 getenforce 命令查看 SELinux服务的运行状态。
SELinux服务主配置文件中定义的默认状态
vim /etc/selinux/config
SELINUX=enforcing
永久关闭selinux:
vi /etc/selinux/config
将SELINUX=enforcing 改成 SELINUX=disabled,保存。
重启系统 reboot
service /etc/init.d chkconfig systemctl
service命令,分析脚本可知此命令的作用是去/etc/init.d目录下寻找相应的服务,进行开启和关闭等操作。一些linux的版本不支持service,service命令可以替换为/etc/init.d/ service_name command。
chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。
systemctl命令,它融合之前service和chkconfig的功能于一体。可以使用它永久性或只在当前会话中启用/禁用服务。
任务 旧指令 新指令
使某服务自动启动 chkconfig –level 3 httpd on systemctl enable httpd.service
使某服务不自动启动 chkconfig –level 3 httpd off systemctl disable httpd.service
检查服务状态 service httpd status systemctl status httpd.service
显示所有已启动的服务 chkconfig –list systemctl list-units –type=service
启动某服务 service httpd start systemctl start httpd.service
停止某服务 service httpd stop systemctl stop httpd.service
重启某服务 service httpd restart systemctl restart httpd.service
本地的文件上传到服务器或者从服务器上下载文件到本地
yum provides “*/rz”
yum install lrzsz
sz 下载
rz 上传
ifconfig、route、ip route、ip addr、 ip link
旧命令ifconfig route新命令ip addr ip route ip link
ifconfig
配置地址:比如修改eth0网卡的ip为192.168.174.100,子网掩码为255.255.255.0
ifconfig eth0 192.168.174.100/24
具有查看功能:显示网卡信息,被禁用的网卡看不到.(拔了网线断开连接不算禁用,仍 然能看到该网卡)
启用、禁用网卡:ifconfig eth1 up 启用eth1网卡,ifconfig eth1 down 禁用eth1网卡 这种禁用是从数据链路层断掉,但是网络层ip还在,也就是仍然能ping通
扫描eth0接口的数据:ifconfig -s eth0
网卡别名:ifconfig eth1:1 192.168.174.100/24 起网卡别名
route
查看路由表:route -n
添加路由记录:是临时添加的记录,重启network服务就失效。
添加到达目标主机的路由 route add -host 目标主机 gw 网关 dev 接口。
添加到达目标网络的路由 route add -net 目标网络 netmask 子网掩码 gw 网关 dev 接口或者 route add -net 目标网络/子 网掩码 gw 网关 dev 接口。
添加默认路由route add default gw 网关
删除路由记录:删除路由记录只需要把添加路由记录命令中的add改成del就可以了, 不过删除路由记录可以省略接口,删除到达目标主机的路由记录route del -host 主机 名。删除到达目标网络的路由记录 route del -net 目标网络/子网掩码。删除默认路由 route del default
ip route
显示路由:ip route [show | list]
添加路由:添加到达目标主机的路由记录ip route add 目标主机 via 网关。
添加到达网络的路由记录ip route add 目标网络/掩码 via 网关。
添加默认路由ip route add default via 网关
删除路由:ip route del 目标网络/掩码,ip route del default [via 网关]
清空路由表:ip route flush
ip link
查看:只能看链路层的状态,看不到ip地址
启用、禁用接口:ip link set device down 禁用指定接口, ip link set device up 启用指 定接口
ip link不支持tab键补齐
ip addr
查看:ip addr 即ip a ,可以查看网卡的ip、mac等,即使网卡处于down状态,也能 显示出网卡状态,但是ifconfig查看就看不到。ip addr show device 查看指定网卡的信 息。
作用域:scope {global|link|host}]:指明作用域
global: 全局可用,即两个接口进来的数据我都可以响应。是默认状态。
link: 仅链接可用,进来的数据只有直接相连的那个接口能够响应
host: 本机可用,即只能自己访问
增加ip:ip addr add ip/netmask dev 接口
删除ip:ip addr del ip/netmask dev 接口
清空指定网卡的所有ip:ip addr flush dev 接口
给网卡起别名:起别名相当于给网卡多绑定了一个ip
用法: 比如给网卡eth0增加别名ip addr add 3.3.3.3/16 dev eth0 label eth0:1
删除别名:ip addr del ip/netmask dev eth0 [label eth0:1]
修改默认网卡名为eth0
vi /etc/sysconfig/network-scripts/ifcfg-ens37
修改网卡配置文件中的 DEVICE=eth0
mv /etc/sysconfig/network-scripts/ifcfg-ens37 /etc/sysconfig/network-scripts/ifcfg-eth0
网卡配置文件名称改为 ifcfg-eth0
因 CentOS7 采用 grub2 引导,还需要对 grub2 进行修改
vi /etc/default/grub
在GRUB_CMDLINE_LINUX 这个参数后面加入 net.ifnames=0 biosdevname=0
grub2-mkconfig -o /boot/grub2/grub.cfg
重新生成GRUB配置并更新内核
centos7 tmp目录出现systemd-private
原因:为目录名称中提到的服务启用了安全Tmp系统功能。
解决方案:禁用服务的安全Tmp SystemD
grep -R PrivateTmp /etc/systemd/ //查看 使用了 tmp SystemD 的服务
vim /etc/systemd/system/multi-user.target.wants/httpd.service //以 http 为例
PrivateTmp=false //将 PrivateTmp=true 改为false
systemctl daemon-reload //重启Tmp SystemD
systemctl restart httpd.service //重启 httpd
查看网卡名称
ip a s | grep BROADCAST | awk ‘{print $2}’ | sed ‘s/?/g’