centos 6.X 常见的一些安全或性能优化操作,这里记录一些简单的优化项目,高深的先不写。
Centos 6.X 系统优化
一、设置主机名
# vim /etc/sysconfig/network
HOSTNAME=hyq_db
二、关闭SELinux(个人不建议关闭)
# vim /etc/selinux/config
SELINUX=disabled
# getenforce #查看selinux状态
三、清空防火墙并设置规则
# iptables -F #清除防火墙规则
# iptables -L #查看防火墙规则
# iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# iptables -A INPUT -p icmp -j ACCEPT
# iptables -P INPUT DROP
# /etc/init.d/iptables save
四、添加普通用户并进行sudo授权管理
添加用户
# useradd mike
# echo "123456" | passwd --stdin mike
设置sudo方法一
# chmow u+w /etc/sudoers
# vim /etc/sudoers
root ALL=(ALL) ALL
mike ALL=(ALL) ALL
# chmow u-w /etc/sudoers
设置sudo方法二
# visudo
root ALL=(ALL) ALL
mike ALL=(ALL) ALL
五、禁用root远程登录
# vim /etc/ssh/sshd_config
PermitRootLogin no
PermitEmptyPasswords no #禁止空密码登录
UseDNS no #关闭DNS查询
六、关闭不必要开机自启动服务
编写脚本,运行后保留六个开机自启动项。
开机自启动项自己确定
#!/bin/bash
#关闭所有的开机自启动项
sys=`chkconfig --list | awk '{print $1}'`
for chk in sys
do
chkconfig $chk off
done
#开启crond、rsyslog、sshd、network、iptables、ip6tables六项开机自启动
list="crond rsyslog sshd network iptables ip6tables"
for chk in $list
do
chkconfig --level 3 $chk on
done