#!/bin/bash
read -t 30 -p "hostname: " a
#variable
BACKUP_PATH=/root/backup
YUM_PATH=/etc/yum.repos.d
IPV6_CONFIG=/etc/sysctl.conf
RESOLV=/etc/resolv.conf
if [ $USER != "root" ]; then
echo "YOU need root implement"
exit 1
fi
echo "<============>manage resolv.conf<===============>"
RESOLV_1=$(grep "nameserver 127.0.0.1" ${RESOLV} | wc -l)
if [ $RESOLV_1 -ge 1 ]; then
echo "nameserver 127.0.0.1 is exits"
else
sed -i "1i nameserver 127.0.0.1" $RESOLV
echo "chanage yes"
fi
echo "<============>close NetworkManager<=============>"
systemctl stop NetworkManager && systemctl disable NetworkManager
echo "<============>close Filewalld<=============>"
systemctl stop firewalld && systemctl disable firewalld
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config && setenforce 0
echo "<============>close ipv_6<=============>"
echo "net.ipv6.conf.all.disable_ipv6 = 1" >> $IPV6_CONFIG
echo "net.ipv6.conf.default.disable_ipv6 = 1" >> $IPV6_CONFIG
sysctl -p
yum -y install epel-release
if [ $? -eq 0 ]; then
if [ ! -d $BACKUP_PATH ]; then
mkdir $BACKUP_PATH
mv $YUM_PATH/* $BACKUP_PATH
else
mv $YUM_PATH/* $BACKUP_PATH
fi
else
echo "install epel-release fail"
exit 1
fi
cd $YUM_PATH
echo "<============>modify yum<=============>"
curl -O http://mirrors.aliyun.com/repo/Centos-7.repo && mv ${YUM_PATH}/Centos-7.repo ${YUM_PATH}/CentOS-Base.repo
if [ $? -eq 0 ]; then
curl -O http://mirrors.aliyun.com/repo/epel-7.repo && mv ${YUM_PATH}/epel-7.repo ${YUM_PATH}/epel.repo
fi
echo "<============>clean cache<=============>"
yum clean all
echo "<============>make cache<=============>"
yum makecache fast
which rsync >> /dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "<============>rsync installed<=============>"
else
yum -y install rsync
echo "<============>installing rsync<=============>"
fi
which pssh >> /dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "<============>pssh installed<=============>"
else
yum -y install pssh
echo "<============>install pssh<=============>"
fi
echo "root soft nofile 102400" >> /etc/security/limits.conf
echo "root hard nofile 102400" >> /etc/security/limits.conf
yum -y install ntpdate > /dev/null 2>&1
echo "<============>update time<=============>"
if [ $? -eq 0 ]; then
ntpdate time.windows.com
echo "<============>update time yes<=============>"
else
echo "Time synchronization failure"
exit 1
fi
hostnamectl set-hostname $a
echo "<============>Ready to log out<=============>"
sleep 10
echo "success!"
初始化环境脚本
原创
©著作权归作者所有:来自51CTO博客作者全能动作X的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
内核初始化脚本
RHEL6.4 Kernel的初始化脚本
Kernel RHEL6.4 -
初始化项目脚本
天天配置项目,天天清理文件夹,天天重复着一些事情。
shell php 初始化 配置文件 #if -
单双向互信及初始化环境脚本
服务器一键互信脚本
linux 服务器 docker