Linux常用命令(SELinux、Git、Systemd、Firewalld:
)
SELinux:
$ yum -y install policycoreutils-python.x86_64
# 安装Semanage工具(用来管理SELinux的工具)
$ chcon -R -t httpd_sys_rw_content_t /data/webapps/
# 把目录或文件的策略类型改成 httpd_sys_rw_content_t,一般是代码SELinux权限导致前端显示403可以执行这条命令
$ restorecon <file>
# 恢复文件SELinux上下文
# -i:忽略不存在的文件。
# -f:infilename 文件 infilename 中记录要处理的文件。
# -e:directory 排除目录。
# -R/-r:递归处理目录。
# -n:不改变文件标签。
# -o/outfilename:保存文件列表到 outfilename,在文件不正确情况下。
# -v:将过程显示到屏幕上。
# -F:强制恢复文件安全语境。
$ setsebool -P httpd_can_network_connect 1
# HTTP可以连接到网络(我之前部署WEB的时候HTTP连不数据库就敲了这条命令就可以了)
$ semanage port -l | grep http_port_t
$ semanage port -a -t http_port_t -p tcp <port>
$ semanage port -d -t http_port_t -p tcp <port>
# 查询SELinux的HTTP白名单规则
# 添加SELinux的HTTP白名单规则
# 删除SELinux的HTTP白名单规则
$ chcon --reference=<src> <obj>
# 参照源对象修改目标对象SELinux上下文
# -f:强制执行
# -R:递归修改
$ semanage permissive -a redis_t
# 指定该特定的程序运行Permissive,其他仍然运行Enforcing模式。
# 当时我Redis启动不起来,报错Creating Server TCP listening socket 127.0.0.1:6379: bind: Permission denied;我就执行了这条命令就可以了
未完待续···
Git:
$ git clone <giturl> #拉取项目代码到本地服务器
$ git pull #更新项目代码
$ git reflog #查看Git日志
$ git reset --hard <hash> #回滚到指定版本
$ git add . #递归地添加当前工作目录中的所有文件到缓存区
$ git rm <file> #删除文件
$ git commit -m "Description" #提交已经被add进来的改动并说明Description
$ git push origin (branchname) #提交代码到项目分支
$ git checkout (branchname) #切换分支
$ git checkout -b (branchname) #创建并切换到新的分支
未完待续···
->->->Git命令官方参考文档
Systemd:
$ systemctl daemon-reload
$ systemctl enable service
$ systemctl disable service
$ systemctl start service
$ systemctl stop service
$ systemctl restart service
$ systemctl status service
未完待续···
Firewalld:
$ firewall-cmd --state #显示当前状态
$ firewall-cmd --zone=public --list-ports #查看public允许进入的端口
$ firewall-cmd --reload #不重启立即加载
$ firewall-cmd --list-all-zones | more #查看区域信息情况
$ firewall-cmd --zone=public --list-interfaces #列出public所有网卡
$ firewall-cmd get-zone-of-interface=ens33 #查看指定接口所属区域
$ firewall-cmd panic-on/off #拒绝所有包/取消拒绝状态
$ firewall-cmd --query-panic #查看是否拒绝
$ firewall-cmd --permanent --add-icmp-block=echo-request #开启禁ping
$ firewall-cmd --permanent --remove-icmp-block=echo-request #删除禁ping
# 服务管理
$ firewall-cmd --zone=public --add-service=http --permanent
$ firewall-cmd --zone=public --remove-service=http --permanent
# 端口管理
$ firewall-cmd --zone=public --add-port=80/tcp --permanent
$ firewall-cmd --zone=public --remove-port=80/tcp --permanent
$ firewall-cmd --zone=public --add-port=80-8080/tcp --permanent
# 网卡管理
$ firewall-cmd --zone=public --add-interface=ens33 -permanent #将ens33网卡添加到public
$ firewall-cmd --zone=public --remove-interface=ens33 --permanent #将ens33网卡从public删除
$ firewall-cmd --zone=work --change-interface=ens33 --permanent #将ens33从public改成work(会从public删除)
# 端口转发
$ firewall-cmd --zone=public --add-masquerade #要打开端口转发则需要先敲这条命令
$ firewall-cmd --zone=public --add-forward-port=port=22:proto=tcp:toport=2222 #转发TCP22端口到2222
$ firewall-cmd --zone=public --add-forward-port=port=22:proto=tcp:toaddr=192.168.1.100 #转发22端口数据到另一个ip的相同端口上
$ firewall-cmd --zone=public --add-forward-port=port=22:proto=tcp:toport=2222:toaddr=192.168.1.100 #转发22端口数据到另外一个ip的2222端口上
# IP封禁(拒绝:reject 允许:accept)
$ firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='222.222.222.222' reject" #单个IP
$ firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='222.222.222.0/24' reject" #IP段
$ firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address=192.168.1.2 port port=80 protocol=tcp accept" #单个IP的某个端口
# 通过ipset来封禁IP
# 封禁IP
$ firewall-cmd --permanent --zone=public --new-ipset=blacklist --type=hash:ip
$ firewall-cmd --permanent --zone=public --ipset=blacklist --add-entry=222.222.222.222
# 封禁网段
$ firewall-cmd --permanent --zone=public --new-ipset=blacklist --type=hash:net
$ firewall-cmd --permanent --zone=public --ipset=blacklist --add-entry=222.222.222.0/24
# 倒入 ipset 规则
$ firewall-cmd --permanent --zone=public --new-ipset-from-file=/path/blacklist.xml
# 然后封禁 blacklist
$ firewall-cmd --permanent --zone=public --add-rich-rule='rule source ipset=blacklist drop'
# IP封禁和端口
$ firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address=192.168.1.2 port port=80 protocol=tcp accept"
# 只对192.168.1.2这个IP只能允许80端口访问 (拒绝访问只需把 accept 换成 reject、删除该规则把 –add-rich-rule 改成 –remove-rich-rule即可)
未完待续···