centos7安装
net.ifnames=0 biosdevname=0
初始化系统
yum install wget -y
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
yum install lrzsz ntpdate sysstat dos2unix wget telnet tree bind-utils net-tools vim -y
ulimit -SHn 65535
echo '* - nofile 65535' >>/etc/security/limits.conf
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.ori
sed -i 's##UseDNS yes#UseDNS no#g' /etc/ssh/sshd_config
sed -i 's#GSSAPIAuthentication yes#GSSAPIAuthentication no#g' /etc/ssh/sshd_config
systemctl restart sshd
echo '*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2 >&1' >>/var/spool/cron/root
ntpdate ntp1.aliyun.com &&hwclock -w
echo 1 > /proc/sys/net/ipv4/ip_forward
sysctl -w net.ipv4.ip_forward=1
sed -i "s#keepcache=0#keepcache=1#g" /etc/yum.conf
systemctl stop postfix
systemctl disable postfix
设置vim
set nu
set cursorline
set nobackup
set ruler
set autoindent
set vb t_vb=
set ts=4
set expandtab
source /etc/vimrc
centos7改ip和主机名脚本
[root@node3 ~]# cat shell/init.sh
#!/bin/sh
################################################
# this script is created by chocolee.
# e_mail:781647046@qq.com
# qqinfo:781647046
# blog:http://www.cnblogs.com/iiiiher/
# version:1.1
# update_date:2016-10-8 09:48:04
################################################
#Source function library.
source /etc/init.d/functions
initHostnameIPADDRS(){
echo ""
echo "================配置主机名和ip地址====================="
sed -i "6c IPADDR=$IPADDRS_eth0" /etc/sysconfig/network-scripts/ifcfg-eth0
#sed -i "6c IPADDR=$IPADDRS_eth1" /etc/sysconfig/network-scripts/ifcfg-eth1
#sed -i "140c ListenAddress=$IPADDRS_eth0:52000" /etc/ssh/sshd_config
# sed -i "141c ListenAddress=$IPADDRS_eth1:22" /etc/ssh/sshd_config
echo "$HOSTNAME" > /etc/hostname
/bin/hostname $HOSTNAME
echo ""
echo "===================Debuging=============================="
echo '#grep "IPADDRS" /etc/sysconfig/network-scripts/ifcfg-eth0'
grep "IPADDR" /etc/sysconfig/network-scripts/ifcfg-eth0
echo ""
echo '#grep "HOSTNAME" /etc/sysconfig/network'
grep "HOSTNAME" /etc/sysconfig/network
echo ""
action "配置hostname和ip地址显示格式完成" /bin/true
echo "=======================notice========================="
echo " "
#echo "下次请用$IPADDRS_eth0:52000登录$HOSTNAME"
echo ""
sleep 2
}
#判断IP是否符合标准规则
function judge_ip(){
#这里local $1出错,用2>/dev/null屏蔽掉错误,暂未发现影响输出结果
local $1 2>/dev/null
TMP_TXT=/tmp/iptmp.txt
echo $1 > ${TMP_TXT}
IPADDRS=`grep -Eo '([0-9]{1,3}.){3}[0-9]{1,3}' ${TMP_TXT}`
#判断有没有符合***.***.***.***规则的IP
if [ ! -z "${IPADDRS}" ];then
local j=0;
#通过循环来检测每个点之前的数值是否符合要求
for ((i=1;i<=4;i++))
do
local IP_NUM=`echo "${IPADDRS}" |awk -F. "{print $"$i"}"`
#判断IP_NUM是否在0与255之间
if [ "${IP_NUM}" -ge 0 -a "${IP_NUM}" -le 255 ];then
((j++));
else
return 1
fi
done
#通过j的值来确定是否继续匹配规则,循环四次,若都正确j=4.
if [ "$j" -eq 4 ];then
#确认是否为自己想要输入的IP地址
read -n 1 -p "你输入的IP是${IPADDRS},确认输入:Y|y;重新输入:R|r:" OK
echo
case ${OK} in
Y|y) return 0;;
R|r) return 1;;
*) return 1;;
esac
else
return 1
fi
else
return 1
fi
}
echo "========================================"
echo ' Linux Optimization '
echo "========================================"
#hostname
read -p "Please enter HOSTNAME: " HOSTNAME
#ip
read -p "Please enter eth0:IPADDR 192.168.8.x: " IPADDRS_eth0
#read -p "Please enter eth1:IPADDR 10.1.1.x: " IPADDRS_eth1
judge_ip "${IPADDRS_eth0}";
#judge_ip "${IPADDRS_eth1}";
i=`echo $?`
#循环直到输入正确的IP为止
until [ "$i" -eq 0 ];do
echo -e "