linux系统基本优化

2016-11-14 18:43:40 7124

linux系统基本优化

最小化原则:① 安装系统最小化
        ② 开启程序服务最小化
        ③ 操作最小化
        ④ 登录最小化,平时没有需求不用root登录
        ⑤ 权限最小化
        ⑥ 配置参数合理,不要最大化


更改ssh服务远程登录配置
/etc/ssh/sshd_conf
port    52113          修改ssh连接默认端口
permitRootLogin no        禁止root远程登录
permitEmptyPassWords  no   禁止空密码登录
UseDNS    no           不使用DNS
/etc/init.d/sshd reload 重新加载


将普通帐号加入sudo管理

su  -  root  切换用户(环境变量) 
sudo  让普通用户可以拥有指定的root权限功能
sudo su -
sudo +命令
visudo
用户       ALL=(ALL)    NOPASSWD:ALL
用户       机器=(授权哪个角色的权) /usr/sbin/useradd
%用户组


调整内核参数文件
/etc/sysctl.conf
net.ipv4.tcp_fin_timeout = 2
net.ipv4.tw_reuse = 1
net.ipv4.tw_recycle = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.ip_loval_port_range = 4000 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_ma_tw_buckets = 36000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1 
net.ipv4.tcp_synack_retries = 1
net.core.somaxconn = 16384
net.core.netdev_max_backlog = 16384
net.ipv4.tcp_max_orphans = 16384
iptalbes
net.nf_conntrack_max = 25 000 000
net.netfillter.nf_conntrack_max = 25 000 000
net.netfillter.nf_conntrack_tcp_timeout_established = 180
net.netfillter.nf_conntrack_tcp_timeout_time_wait = 120
net.netfillter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfillter.nf_conntrack_tcp_timeout_fin_wait  = 120
sysctl -p 生效

定时清理clientmqueue目录垃圾文件,防止占满磁盘空间
手动清理:
find /var/spool/clientmqueue/ - type f |xargs rm -f
ll /var/spool/clientmqueue |wc -l
定时清理:
echo "find /var/spool/client - type -f |xargs rm -f " >/server/scripts /del_sys_file.sh
echo "00 00 ** 0 /bin/sh/server/scripts/del_sys_file.sh >/dev/null 2>$1" >>/var/spool/cron/root



扩大文件描述符
ulimit -n -HSn 65535 当次生效
echo '*   -   nofile 65535' >>/etc/security/limits.conf


隐藏系统信息
cat /dev/null >/etc/issue


锁定关键系统文件
chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/inittab

提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: