#!/bin/bash
#Author daruizheng
#This script is only for CentOS 7x64
Check_Network()
{
PingResult=`/usr/bin/ping -c 3 www.baidu.com | grep 'icmp_seq' | grep 'time' | wc -l`
if [[ ${PingResult} -eq 0 ]]; then
Echo_Red "Network check...failed, Chenk your network or resolv.conf"
#echo "Writing nameserver to /etc/resolv.conf ..."
#echo -e "nameserver 208.67.220.220\nnameserver 114.114.114.114" > /etc/resolv.conf
exit 1
else
echo "Network check...ok"
fi
}
Soft_Install()
{
Echo_Blue "[+] Installing software..."
yum install -y wget vim net-tools tree telnet unzip curl sysstat
}
Yum_Install()
{
Echo_Green "[CFG] Config epel resource && yum resource"
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
yum makecache
}
Firewalld_UNInstall()
{
Echo_Yellow "[-] Remove firewalld..."
systemctl stop firewalld.service
systemctl disable firewalld.service
}
Iptables_UNInstall()
{
Echo_Yellow "[-] Stop iptables Service..."
#yum install iptables.services -y
systemctl stop iptables
systemctl disable iptables
}
Disable_Selinux()
{
Echo_Green "[CFG] disable selinux..."
if [ -s /etc/selinux/config ]; then
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
fi
}
Check_Hostname()
{
Hname=`cat /etc/hostname`
Echo_Green "[CFG] This system's hostname is $Hname"
read -p "Reset the hostname? Y/n: " choi
case $choi in
Y|y)
echo
read -p "Please input new hostname: " hostname
echo $hostname > /etc/hostname
echo "The hostname is changed to "$hostname",remember to reboot the system."
;;
N|n)
echo "The hostname is not changed!"
;;
*)
echo
;;
esac
}
Limits_Modify()
{
Echo_Green "[CFG] Start to adjust the file size, modify limits.conf..."
sleep 1
echo "* soft nofile 65535" >> /etc/security/limits.conf
echo "* hard nofile 65535" >> /etc/security/limits.conf
echo "* soft nproc 65535" >> /etc/security/limits.conf
echo "* hard nproc 65535" >> /etc/security/limits.conf
echo ulimit -n 65535 >> /etc/profile
}
Kernel_Modify()
{
Echo_Green "[CFG] Start to adjust kernel parameters..."
cat >> /etc/sysctl.conf << EOF
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_keepalive_time = 1800
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_intvl =15
net.ipv4.tcp_retries2 = 5
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_max_orphans = 32768
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_wmem = 8192 131072 16777216
net.ipv4.tcp_rmem = 32768 131072 16777216
net.ipv4.tcp_mem = 786432 1048576 1572864
net.ipv4.ip_local_port_range = 1024 65000
net.core.somaxconn = 56384
net.core.netdev_max_backlog = 262144
fs.file-max = 65535
vm.swappiness = 0
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.sysrq = 0
kernel.core_uses_pid = 1
kernel.randomize_va_space = 2
vm.overcommit_memory = 1
vm.max_map_count = 262144
EOF
sysctl -p
}
Chronyd_Install()
{
Echo_Blue "[+] Installing chrony..."
yum install chrony -y
chronyd -q "server pool.ntp.org iburst"
systemctl start chronyd
systemctl enable chronyd
}
Set_Timezone()
{
if `ls -l /etc/localtime | grep -Eqi "Shanghai"`; then
Echo_Green "[CFG] Setting timezone..."
echo "Timezone is OK! Not changed!."
else
Echo_Green "[CFG] Setting timezone..."
rm -rf /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Echo_Green "Set_Timezone OK!!!"
fi
}
Set_Charactor()
{
Echo_Green "[CFG] Setting LANG, Modify profile && locale.conf..."
echo "export LANG=en_US.UTF-8" >> /etc/profile
echo "LANG=en_US.UTF-8" > /etc/locale.conf
source /etc/profile
Echo_Green "Setting LANG OK!!!"
}
Set_Monitor()
{
cat > /lib/systemd/system/node_exporter.service << EOF
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl enable node_exporter
systemctl start node_exporter
systemctl status node_exporter
}
Set_History()
{
Echo_Green "[CFG] Setting history numbers.."
sed -i 's/^HISTSIZE=1000/HISTSIZE=300/' /etc/profile
source /etc/profile
}
Test()
{
Color_Text "[CFG] TEST"
Echo_Blue "[CFG] TEST"
Echo_Red "[CFG] TEST"
Echo_Green "[CFG] TEST"
Echo_Yellow "[CFG] TEST"
echo "This' a test!"
}
CentOS系统初始化优化脚本
需积分: 5 127 浏览量
2024-05-11
16:32:41
上传
评论
收藏 3KB GZ 举报
zhengqiang2116
- 粉丝: 1
- 资源: 13
最新资源
- 《计算机网络-自顶向下方法》答案
- 基于pyqt5框架开发的demo项目 全栈开发,短小精悍,入门学习,上手简单
- 国内IP地址大全 站长资源 访问IP设置 Order allow,deny 使用方法
- 【JavaScript实现点击鼠标出现爱心特效脚本】直接引入index.html文件可用!!!
- OPC Core Components Redistributable (x86).msi
- 一套基于Python的交易量化框架,详细复现步骤
- 顺序表定义及12个基本操作实现
- xilinx vbyone IP 网表文件
- 【JavaScript实现点击鼠标出现爱心特效脚本】直接引入index.html文件可用!!!
- Erlang环境,26.1.0.0和Erlang环境,26.1.0.0
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈