CentOS 7 常用操作及常见问题处理以及防火墙处理

一、常用操作

1、启动防火墙:

systemctl start firewalld.service

2、关闭防火墙:

systemctl stop firewalld.service

3、添加放行端口:

firewall-cmd --zone=public --add-port=8161/tcp --permanent (--permanent永久生效,没有此参数重启后失效)

firewall-cmd --reload

4、锁定防火墙服务(防止添加端口等操作):

systemctl mask firewalld

5、取消锁定:

systemctl unmask firewalld

二、常见问题及解决办法

1、当出现如下 “firewalld.service: Unit is masked” 错误时,说明服务被锁定,此时我们取消锁定即可: CentOS 7 默认使用的是firewall作为防火墙,可通过如下操作改为iptables防火墙。

1、停止 firewall

systemctl stop firewalld.service

2、禁止 firewall 开机启动

systemctl disable firewalld.service

3、安装 iptables-services

yum install iptables-services

4、启用iptables-services

systemctl enable iptables

5、启动 iptables

service iptables start

centos7 修改ulimit

vi /etc/security/limits.conf 最后加入

* soft nofile 1000000
* hard nofile 1000000
root soft nofile 1000000
root hard nofile 1000000

CentOS7增加或修改SSH端口号的方法

vim /etc/ssh/sshd_config

找到“#Port 22”,这一行直接键入“yyp”复制该行到下一行,然后把两行的“#”号即注释去掉,修改成自己想要的端口

修改完成后重启服务

systemctl restart sshd

centos关闭selinux

setenforce 0   #临时关闭
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config   关闭 禁止重启生效
yum -y update   #安装系统升级命令

第二种方法 运行命令

sudo vim /etc/sysconfig/selinux

找到行

SELINUX=enforcing

替换为

SELINUX=disabled

保存退出

reboot

永久关闭selinux成功


CentOS7 开启路由转发

1.临时开启,(写入内存,在内存中开启)

echo "1" > /proc/sys/net/ipv4/ip_forward

 

2.永久开启,(写入内核)

echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf

 

3.加载,使得配置文件立即生效

sysctl -p 

Centos7 系统调优

新建文件 90-conntrack.conf

vi /etc/sysctl.d/90-conntrack.conf

添加一下内容并保存

net.netfilter.nf_conntrack_max=1048576
net.nf_conntrack_max=1048576
net.netfilter.nf_conntrack_tcp_timeout_fin_wait=30
net.netfilter.nf_conntrack_tcp_timeout_time_wait=30
net.netfilter.nf_conntrack_tcp_timeout_close_wait=15
net.netfilter.nf_conntrack_tcp_timeout_established=300

保存后运行一下保存的内容

sudo sysctl -p /etc/sysctl.d/90-conntrack.conf

安装系统网络工具命令

apt install net-tools -y    #系统工具安装命令

Centos7换源命令

1 备份本地yum源:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak

2 下载阿里yum源配置文件:

http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo   (利用Curl命令下载文件,重命名后替换阿里源)

3 更新所有软件命令:

yum update -y
阅读全文
除特别注明外,本站所有文章均基于CC-BY-NC-SA 4.0原创,转载请注明出处。
文章名称:《CentOS 7 常用操作及常见问题处理以及防火墙处理》
文章链接:https://www.mrgod.cn/211.html
分享到: 生成海报

评论 1

评论前必须登录!

立即登录   注册

  1. #1

    收藏了

    Angeleno4年前 (2020-07-09)国内网友登录以回复

简简单单,做好记录

切换注册

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

切换登录

注册

我们将发送一封验证邮件至你的邮箱, 请正确填写以完成账号注册和激活