#!/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!"
}
没有合适的资源?快使用搜索试试~ 我知道了~
Linux系统安装后,初始化优化脚本,适用于CentOS7、CentOS8,也可解压后自行修改。
资源推荐
资源详情
资源评论





























收起资源包目录









共 7 条
- 1
资源评论


zhengqiang2116
- 粉丝: 1
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
