云计算之linux系统优化(下)

之前讲述的是对安全方面的优化,今天整理一下性能调优方面

方向二:linux系统调优

1.关闭一些不需要开机启动的服务

         列出所有启动文件

         ]# systemctl list-unit-files | grep enabled

         编写脚本关闭禁止相应服务开机自启

         ]# vim targets.sh 

#!/bin/bash
# 此脚本为CentOS7的优化,CentOS6中无法使用
# services=('sshd' 'rsyslog' 'NetworkManager' 'crond' 'chronyd')
# 以上列表中的服务必须启动,其他则可以关闭
for service in `systemctl list-unit-files | awk '/enabled/{print $1}'`
do
	systemctl stop  $service &>/dev/null
	systemctl disable $service &>/dev/null
done
for i in 'sshd' 'rsyslog' 'NetworkManager' 'crond' 'chronyd'
do
	systemctl restart $i  &>/dev/null
	systemctl enable $i  &>/dev/null
done
# 列出所有启动的服务
systemctl list-unit-files | awk '/enabled/{print $1}'

2.服务器时间同步

如果是集群的话,会在集群中找一台服务器作为时间服务器,集群中其他服务器都使用该时间服务器,这台时间服务器可以同步华为、阿里等时间服务器。

         时间服务器操作:

         yum –y install chrony

         vim /etc/chrony.conf 

           server ntp.myhuaweicloud.com iburst  # 此处使用华为服务器

            allow 192.168.0.0/16       # 允许指定网段的服务器使用该时间服务器

            local stratum 10        # 该时间服务器级数

       其他集群服务器操作:

                  yum –y install chrony

                   vim /etc/chrony.conf

server 该时间服务器的ip地址 iburst

                   systemctl restart chronyd

                   systemctl enable chronyd

3.加大服务器文件描述符

         文件描述符大了,意味着并发量也会相应的提高

         vim /etc/security/limits.conf

 *       -       nofile  65535

         重启服务器后生效

4.调整内核参数文件 /etc/sysctl.conf

         ]# vim /etc/sysctl.conf # 在后面追加

net.ipv4.tcp_fin_timeout = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.ip_local_port_range = 4000  65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_max_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

 

猜你喜欢

转载自blog.csdn.net/mx_steve/article/details/85925774
今日推荐