Linux服务器参数调优最佳实践
目 录
为满足目前公司整体业务场景多样化发展需要,Linux服务器在不同业务场景需进行不同的业务配置,使服务器的发挥最佳性能。结合Linux服务器的内核特性和不同业务场景需求,统一支撑中心提供了标准化的内核调优脚本,使适用于不同种类的业务情况。
本文档编写目的是为规范公司统一标准化运维项目,以便未来形成相关知识库以及流水线的标准化操作。
系统类型 |
系统版本 |
内核 |
备注 |
Centos |
7.9 |
kernel-lt-5.4.188-1.el7.elrepo.x86_64 |
- linux服务器参数调优
- 更改yum源(如有外网)
更改yum源为国内,是因为为了提速,因默认的yum源会影响yum工具下载的速度,建议国内服务器如有外网都进行更改。
# 更改base源为阿里云的源
[root@hzl~]#curl -o /etc/ yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 更改添加epel源
[root@hzl ~]# yum install -y epel-release
[root@hzl ~]# yum install -y \
tree telnet lrzsz wget ntpdate vim nc namp dos2unix tcpdump expect sshpass elinks unzip \
lsof net-tools iproute bridge-utils \
bind-utils nscd \
gcc gcc-c++ make cmake libaio zlib-devel pcre-devel \
psmisclsof sysstat yum-utils
#注:
lrzsz #是上传下载的软件
sysstat #是用来检测系统性能及效率的工具
net-tools #没有ifconfig命令时候需要安装工具
SELinux 是 2.6 版本的 Linux 内核中提供的强制访问控制(MAC)系统,对于目前的linux系统来说基本都内置开启了该安全增强的selinux内核模块。但是它虽然安全,但是对于一般的用户来说,过于复杂。为防止因selinux造成的相关报错问题,建议对selinux进行关闭。
[root@hzl ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
[root@hzl ~]# setenforce 0
[root@hzl ~]# getenforce 0
Permissive
为防止Linux服务器乱码,建议对服务器设置zh_CN.UTF-8的中文字符。
[root@hzl ~]# echo "LANG=\"zh_CN.UTF-8\"" >/etc/locale.conf
## 创建/etc/sysconfig/clock文件
[root@hzl ~]# cat >>/etc/sysconfig/clock <<EOF
ZONE="Asia/Shanghai"
UTC=false
ARC=false
EOF
# 强制让其与/etc/localtime文件进行软链接
[root@hzl ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 同步阿里云时间
[root@hzl ~]#ntpdate ntp1.aliyun.com
# 设置硬件时间和系统时间一致并校准
[root@hzl ~]# /sbin/hwclock --systohc
[root@hzl ~]# hwclock --show
1>#输出当前时间
date +"%Y-%m-%d %H:%M:%S" # 2018-06-08 14:05:08输出指定时间
#参数:
-