CentOS Linux服务器安全设置

2019-10-13 20:08:09于丽

用户登陆数据库后执行的SQL命令也会被MySQL记录在用户目录的.mysql_history文件里。
如果数据库用户用SQL语句修改了数据库密码,也会因.mysql_history文件而泄漏。
所以我们在shell登陆及备份的时候不要在-p后直接加密码,而是在提示后再输入数据库密码。
另外这两个文件我们也应该不让它记录我们的操作,以防万一。

cd
cp .bash_history .bash_historybak #备份
cp .mysql_history .mysql_historybak
rm .bash_history .mysql_history
ln -s /dev/null .bash_history
ln -s /dev/null .mysql_history

十一、修改history命令记录

cp /etc/profile /etc/profilebak
vi /etc/profile
找到 HISTSIZE=1000 改为 HISTSIZE=50

十二、隐藏服务器系统信息

在缺省情况下,当你登陆到linux系统,它会告诉你该linux发行版的名称、版本、内核版本、服务器的名称。
为了不让这些默认的信息泄露出来,我们要进行下面的操作,让它只显示一个"login:"提示符。
删除/etc/issue和/etc/issue.net这两个文件,或者把这2个文件改名,效果是一样的。
mv /etc/issue /etc/issuebak
mv /etc/issue.net /etc/issue.netbak

十三、优化Linux内核参数

cp /etc/sysctl.conf /etc/sysctl.confbak
vi /etc/sysctl.conf #在文件末尾添加以下内容

net.ipv4.ip_forward = 1 #修改为1
net.core.somaxconn = 262144
net.core.netdev_max_backlog = 262144
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.netfilter.ip_conntrack_max = 131072
net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 180
net.ipv4.route.gc_timeout = 20
net.ipv4.ip_conntrack_max = 819200
net.ipv4.ip_local_port_range = 10024 65535
net.ipv4.tcp_retries2 = 5
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_keepalive_time = 120
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_wmem = 8192 131072 16777216
net.ipv4.tcp_rmem = 32768 131072 16777216
net.ipv4.tcp_mem = 94500000 915000000 927000000

/sbin/sysctl -p #使配置立即生效

十四、CentOS 系统优化

cp /etc/profile /etc/profilebak2
vi /etc/profile  #在文件末尾添加以下内容
ulimit -c unlimited
ulimit -s unlimited
ulimit -SHn 65535
ulimit -S -c 0
export LC_ALL=C
source /etc/profile #使配置立即生效
ulimit -a #显示当前的各种用户进程限制

十五、服务器禁止ping

cp /etc/rc.d/rc.local /etc/rc.d/rc.localbak
vi /etc/rc.d/rc.local  #在文件末尾增加下面这一行
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
参数0表示允许 1表示禁止