1关闭防火墙和SELINUX
2sshd优化
3ulimits优化
4内核参数优化
5修改history记录格式
6设置默认字符界面启动
7设置时区
8关闭无用服务
9配置chronyd服务

关闭防火墙和SELINUX
systemctl disable --now firewalld sed -i s#SELINUX=enforcing#SELINUX=disabled#g /etc/selinux/config setenforce 0
sshd优化
vi /etc/ssh/sshd_config UseDNS no GSSAPIAuthentication no # 重启sshd服务 systemctl restart sshd</div>
ulimits优化
每种操作系统的20-nproc.conf文件不同
vim /etc/security/limits.d/20-nproc.conf * soft nofile 65536 * hard nofile 65536 * soft nproc 65536 * hard nproc 65536 * soft core 50000000 * hard core 50000000

内核参数优化
vi /etc/sysctl.conf # 更积极的使用内存,而不是swap vm.swappiness=10 # 整个系统使用的文件描述符总数 fs.file-max = 2000000 kernel.shmmni = 32000 kernel.msgmnb = 163840 kernel.msgmax = 81920 # 保持长连接发送探测包时间,默认是2小时 net.ipv4.tcp_keepalive_time = 300 # 在tcp_keepalive_time之后,没有接收到对方确认,继续发送保活探测包次数,默认值为9 net.ipv4.tcp_keepalive_probes = 10 # KeepAlive探测包的发送间隔,默认值为75 net.ipv4.tcp_keepalive_intvl = 30 # 端口好范围,默认值32768~60999 net.ipv4.ip_local_port_range = 1024 65535 # TCP监听队列长度,默认是128 net.core.somaxconn = 4096 # 连接处于SYN_RECV状态的最大值 net.ipv4.tcp_max_syn_backlog = 8192 # 当接口接收到比内核处理速度更快的数据包时,在INPUT端排队的最大数据包数,默认1000 net.core.netdev_max_backlog = 30000 # 发送缓冲区的默认值 net.core.wmem_default = 16777216 # 接收缓冲区的最大值 net.core.rmem_max=16777216 # 发送缓冲区的最大值 net.core.wmem_max=16777216 # max(tcp_wmem) * 2 * 500 / 4096,可能同时有500个客户端 net.ipv4.tcp_mem = 4096000 4096000 4096000 # 每个socket占用的缓冲区的最小值、默认值和最大值 net.ipv4.tcp_rmem=4096 87380 16777216 net.ipv4.tcp_wmem=4096 87380 16777216 # 连接处于FIN_WAIT_2的时间,默认是60s net.ipv4.tcp_fin_timeout = 20 # 开启TIME-WAIT连接重用,默认为2 net.ipv4.tcp_tw_reuse = 1 # 回复SYN+ACK并等待对方ACK确认,如果超时重传的次数,默认值为5 net.ipv4.tcp_synack_retries = 2 # 在发送SYN后等待SYN+ACK,如果不回复再次发送的次数,默认值为6 net.ipv4.tcp_syn_retries = 2
立即生效
sysctl --system
修改history记录格式
vi /etc/profile USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S `whoami`@${USER_IP}: " export HISTFILESIZE=1000000 export PROMPT_COMMAND="history -a; history -r; $PROMPT_COMMAND" shopt -s histappend # 立即生效 source /etc/profile
设置默认字符界面启动
# 模式使用字符界面启动,如果需要图形界面可以手动切换 systemctl set-default multi-user.target # 查看启动模式systemctl get-default # 切换图形界面 systemctl set-default graphical.target # 登录到root用户执行startx命令
设置时区
# 设置时区为上海 timedatectl set-timezone Asia/Shanghai # 查看时区 timedatectl
关闭无用服务
重点查看服务是否可以关闭,是否还有其他服务可以关闭。 redhat8.9需要关闭4个服务 systemctl disable --now libvirtd-admin.socket systemctl disable --now libvirtd-ro.socket systemctl disable --now libvirtd.socket systemctl disable --now libvirtd.service # ABRT相关服务Automatic Bug Reporting Tool systemctl disable --now abrt-ccpp.service systemctl disable --now abrt-oops.service systemctl disable --now abrt-xorg.service systemctl disable --now abrtd.service service auditd stop systemctl disable auditd # 自动发现局域网中服务,例如打印机、共享 systemctl disable --now avahi-daemon.socket systemctl disable --now avahi-daemon.service # 蓝牙服务 systemctl disable --now bluetooth.service # kvm虚拟化服务 systemctl disable --now libvirtd.service # 调制解调服务 systemctl disable --now ModemManager.service # 邮件服务 systemctl disable --now postfix.service # 订阅升级服务服务 systemctl disable --now rhsmcertd.service # 性能调优服务 systemctl disable --now tuned.service # vdo磁盘服务,vdo是一个具有重删功能的磁盘 systemctl disable --now vdo.service
配置chronyd服务
# 如果需要保持冗余效果,建议配置3个服务器,如果无3个服务器可以配置一个,禁止配置两个。 vim /etc/chrony.conf server ntp1.aliyun.com iburst systemctl enable --now chronyd.service # 检查配置 chronyc sources -v
© 版权声明
文章版权归作者所有,未经允许请勿转载。