环境信息
可安装系统
Cnetos 7.9
Rocky 8.7
Ubuntu
Debian
设置环境变量
hosts="127.0.0.1"
下载 ansible 脚本
git clone https://gitlab.com/cn2linux/ansible.git
cd ansible
运行 Ansible
ansible-playbook -i "${hosts}," main.yml --tags init
网卡配置-更换为eth0:
cd /etc/sysconfig/network-scripts/
mv ifcfg-eno16777736 ifcfg-eth0
编辑网卡
vi ifcfg-eth0
NAME=eth0
DEVICE=eth0
#退出保存
编辑grub配置
vi /etc/default/grub
#在GRUB_CMDLINE_LINUX 带lv=centos/root 后面插入
net.ifnames=0 biosdevname=0
#退出保存
重新生成grub配置文件
grub2-mkconfig -o /boot/grub2/grub.cfg
网卡配置-配置静态IP:
注:以下IP地址是根据自己网络段来进行添加,如果你是192.168.1 的网段请添加 192.168.1 的IP。
vim /etc/sysconfig/network-scripts/ifcfg-eno16777736 ifcfg-eth0
#修改
BOOTPROTO=static
ONBOOT=yes
#添加
IPADDR=10.0.1.200
NETMASK=255.255.255.0
GATEWAY=10.0.1.2
DNS1=8.8.8.8
DNS2=8.8.4.4
重启网卡
/etc/init.d/network restart
启动YUM源加速:
cat >>/etc/yum/pluginconf.d/fastestmirror.conf <<EOF
include_only=.nl,.de,.uk,.ie,.net,.cn,.org,.jp,.sg,.hk,.ph
EOF
优化及关闭开机启动服务器:
sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
systemctl disable firewalld
systemctl disable tuned
systemctl disable postfix
systemctl disable NetworkManager
systemctl stop firewalld
systemctl stop tuned
systemctl stop postfix
systemctl stop NetworkManager
setenforce 0
优化SSH服务:
更换换SSH端口(可选):
sed -i 's/#Port 22/Port 9158/' /etc/ssh/sshd_config
修改时区及同步时间:
timedatectl set-timezone Asia/Shanghai
ntpdate 2.cn.pool.ntp.org
echo "*/10 ntpdate 2.cn.pool.ntp.org" >> /var/spool/cron/root
优化打开的文件和进程
echo "ulimit -SHn 204800" >> /etc/rc.local
echo "ulimit -SHu 204800" >> /etc/rc.local
##### 配置THP开机自动关闭:
echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local
更换主机名:
hostnamectl set-hostname 主机名
修改PS1 编辑/etc/profile 末尾添加:
vim /etc/profile
export PS1='\n\e[1;37m[\e[m\e[1;32m\u\e[m\e[1;33m@\e[m\e[1;35m\H\e[1;31m#\t\e[m\e[m:\e[4m`pwd`\e[m\e[1;37m]\e[m\e[1;36m\e[m\n\$
执行生效环境变量:
source /etc/profile
关闭numa
编辑/etc/grub2.cfg 100行,在末尾添加numa=off
linux16 ... rhgb quiet numa=off
磁盘IO调度优化:
SSD磁盘配置
echo noop >/sys/block/sda/queue/scheduler
echo 'echo noop >/sys/block/sda/queue/scheduler' >>/etc/rc.local
SAS磁盘配置
echo deadline >/sys/block/sda/queue/scheduler
echo 'echo deadline >/sys/block/sda/queue/scheduler' >>/etc/rc.local
评论区