CentOS-7.8最小化安装后系统优化

一、CentOS-7.8系统优化
1.1最大文件打开数/文件句柄优化

备份配置文件

cp -a /etc/security/limits.conf{,.bak}

添加以下两行配置到该文件最后

  • soft nofile 65536
  • hard nofile 65536
    1.2用户最大进程数

1.备份配置文件

cp -a /etc/security/limits.d/20-nproc.conf{,.bak}

2.修改配置文件

vim /etc/security/limits.d/20-nproc.conf

  • soft  nproc   65536
    
  • hard  nproc   65536
    

root soft nproc unlimited
1.3关闭防火墙
##依据实际生产情况管理
/usr/bin/systemctl stop firewalld.service &> /dev/null
/usr/bin/systemctl disable firewalld.service &> /dev/null
/usr/bin/systemctl mask firewalld.service &> /dev/null
1.4关闭安全机制SElinux
cp /etc/selinux/config{,.bak}
sed -r -i ‘/^SELINUX=/s/.*/SELINUX=disabled/’ /etc/selinux/config
setenforce 0
1.5操作系统时间同步

解锁配置文件

chattr -i ``/var/spool/cron/root

添加定时任务,定时从时间服务器同步时间

echo “*/5 * * * * /usr/sbin/ntpdate 10.137.9.9 >> /home/timedate.log > /dev/null 2>&1” >> /var/spool/cron/root

编辑后锁定配置文件

chattr +i /var/spool/cron/root
1.6系统参数优化(依据实际生成环境)

备份配置文件

cp -a /etc/sysctl.conf /etc/sysctl.conf.default

添加以下调优参数到该文件中

#kernel
kernel.sysrq = 0
kernel.core_uses_pid = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
#socket
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.ip_forward = 0
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
#socket mem
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
#conn
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
#Timewait
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
#sync
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_syncookies = 1
#fin
net.ipv4.tcp_fin_timeout = 1
#keepalive
net.ipv4.tcp_keepalive_time = 30

配置生效

/sbin/sysctl -p

二、CentOS系统安全加固
2.1操作系统密码策略(密码长度有效期)

备份配置文件:

cp -a /etc/login.defs /etc/login.defs.default

编辑配置文件

vim /etc/login.defs

将相关参数值改成如下:

PASS_MAX_DAYS 90 # 密码最长使用天数
PASS_MIN_DAYS 0 # 密码最短使用天数
PASS_MIN_LEN 8 # 密码最短长度
PASS_WARN_AGE 7 # 密码到期前多少天提醒

修改系统中当前已存在用户的密码策略

chage -m 0 -M 90 -I 5 -W 7 <用户名>

表示将此用户的密码最长使用天数设为90,最短使用天数设为0,密码过期后5天之后账户失效,过期前7天提醒用户。

2.2密码复杂度策略

备份配置文件:

cp -a /etc/pam.d/system-auth /etc/pam.d/system-auth.default## 编辑配置文件
vi /etc/pam.d/system-auth

将password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type= 修改为:

password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type= ucredit=-1 lcredit=-1 dcredit=-1 ocredit=-1
2.3密码重复使用次数限制
#设置密码重复前3次使用过的

修改配置文件

/etc/pam.d/system-auth
在password sufficient pam_unix.so xxxxx 一行后添加 remember=3,例如:
password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=3
2.4锁定不必要的系统默认账号

锁定无用帐号,降低安全风险

usermod -L gdm
usermod -L nobody

如有其他的不必要的系统用户,可以用此方法锁定

2.5特殊账号检查
awk -F: ‘($2"")’ /etc/shadow ## 查看空口令账号,找到之后,使用passwd命令为其设置密码。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值