新机必备

#!/bin/bash

check_net(){
	echo "正在检查网络通信"
	ip=`ip a |grep inet|awk NR==3'{print $2}'|cut -d. -f-3`.1
	ping -c1 $ip &>/dev/null
	if [ $? -eq 0 ];then
		echo "连接正常"
	else
		echo "请检查网络"
		exit 2
	fi
}

check_Chinses_yum(){
	cat /etc/yum.repos.d/CentOS-Base.repo |grep centos.org &>/dev/null
	if [ $? -eq 0 ];then
		echo "正在修改为国内源"
		change_yum
	else
		echo "okay,你的yum国内源"
	fi
}

change_yum(){
		echo "正在安装国内yum源"
		rm -rf /etc/yum.repos.d/* &>/dev/null
		curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo &>/dev/null
		yum clean all &>/dev/null
		yum makecache  &>/dev/null
		echo "yum源安装成功"
}

check_yum(){
	echo "正在检查yum源是否可用"
	yum repolist &>/dev/null
	if [ $? -eq 0 ] ;then
		echo "你的yum源可以正常使用"
	else
		echo "yum源不可用"
	fi
}

check_epel(){
	rpm -qa | grep epel-release &>/dev/null
	if [ $? -eq 0 ] ;then
		echo "已存在扩展源"
	else
		echo "正在安装扩展源"
		yum -y install epel-release  &>/dev/null
	fi
}

yum () {
	check_net
	check_Chinses_yum
	check_yum
	check_epel
	check_epel
}

ntp(){
	yum -y install ntp-4.2.6p5-29.el7.centos.x86_64 &>/dev/null
	ntpdate -s ntp.api.bz  &>/dev/null
	if [ $? -eq 0 ] ;then
		echo "ntp设置成功"
	else
		echo "不明原因,请手动设置"
	fi
}

firewalld(){
	systemctl stop firewalld
	if [ $? -eq 0 ] ;then
		echo "防火墙关闭成功"
	else
		echo "防火墙关闭失败,请重新关闭"
	fi

	systemctl disable firewalld
	if [ $? -eq 0 ] ;then
		echo "防火墙永久关闭成功"
	else
		echo "防火墙永久关闭失败,请重新关闭"
	fi
}

selinux(){
	setenforce 0 &>/dev/null
	sed -i 's/SELINUX=enforcing/SELINUX=disabeled/g' /etc/selinux/config
	cat /etc/selinux/config |grep SELINUX=disabled &>/dev/null
	if [ $? -eq 0 ] ;then
		echo "SELinux关闭成功"
	else
		echo "SELinux关闭失败,请重新关闭"
	fi
}

kernel(){
	
	echo "* soft nofile 65535
		  * hard nofile 65535 " >>/etc/security/limits.conf
	
	echo "sessionrequired /lib/security/pam_limits.so" >> /etc/pam.d/login

	echo "	net.ipv4.tcp_syncookies= 1
			net.ipv4.tcp_tw_reuse= 1
			net.ipv4.tcp_tw_recycle= 1
			net.ipv4.tcp_fin_timeout= 30" >>/etc/sysctl.conf


	cat /etc/security/limits.conf | grep '* soft nofile 65535' &>/dev/null
	if [ $? -eq 0 ] ;then
		echo "修改/etc/security/limits.conf文件成功"
	else
		echo "修改/etc/security/limits.conf文件失败,请重新修改"
	fi

	cat /etc/pam.d/login | grep 'sessionrequired /lib/security/pam_limits.so' &>/dev/null
	if [ $? -eq 0 ] ;then
		echo "修改/etc/pam.d/login文件成功"
	else
		echo "修改/etc/pam.d/login文件失败,请重新修改"
	fi

	cat /etc/sysctl.conf | grep 'net.ipv4.tcp_syncookies= 1' &>/dev/null
	if [ $? -eq 0 ] ;then
		echo "修改l/etc/sysctl.conf文件成功"
	else
		echo "修改/etc/sysctl.conf文件失败,请重新修改"
	fi


	sysctl -p &>/dev/null

	if [ $? -eq 0 ] ;then
		echo "内核参数已生效"
	else
		echo "内核参数未生效,请重新执行"
	fi

}

name(){
	hostname PC-1
	if [ $? -eq 0 ] ;then
		echo "主机名已修改"
	else
		echo "主机名未修改,请重新执行"
	fi
}

dns(){
	 	cat /etc/resolv.conf |grep 8.8.8.8 &>/dev/null
		if [ $? -eq 0 ];then
			echo "DNS已存在"
		else
			echo "DNS不存在,正在添加"
			echo "nameserver 8.8.8.8" >>/etc/resolv.conf &>/dev/null
			echo "DNS已添加"
		fi
}

check_lsof(){
	rpm -qa | grep lsof &>/dev/null
	if [ $? -eq 0 ] ;then
		echo "成功安装lsof"
	else
		echo "lsof安装失败,请重新安装"
	fi
}

check_tools(){
	rpm -qa | grep net-tools &>/dev/null
	if [ $? -eq 0 ] ;then
		echo "成功安装工具"
	else
		echo "工具安装失败,请重新安装"
	fi
}

tools(){
	yum -y install lsof net-tools
	check_lsof
	check_tools
}

while :
do
	cat <<-EOF

	|----------------装机小工具----- |
	|				           	   |
	|  [1]  一键初始                | 
	|  [2]  国内源且&&扩展源         | 
	|  [3]  时间对时				|
	|  [4]  防火墙永久关闭 	      |
	|  [5]  永久关闭SLinux 			|
	|  [6]  内核调优 				|
	|  [7]  改主机名                |
	|  [8]  DNS配置 			      |
	|  [9]  小工具包 lsof啥的        |
    |				             	|
	|  任意键退出 	                 |
   	|					            |
	|---------路漫漫其修远兮---------|

	EOF

	read -p "请选择您想进行的操作: " a

	case $a in
	1)
		yum
		ntp
		firewalld
		selinux

		name
		dns
		tools
		;;

	2)	
		yum
		;;

	3)	
		ntp
		;;

	4)
		firewalld
		;;

	5)
		selinux
		;;

	6)
		kernel	
		;;

	7)
		name
		;;

	8)
		dns
		;;

	9)
		tools
		;;
	*)
		exit
		;;
	esac
echo "吾将上下而求索"
done
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值