shell脚本--一键配置服务器的基本配置

在实际工作中,服务部署安装程序之前总是要进行服务器的基础配置,手动配置呢既麻烦又浪费时间,这里编写一个shell脚本来完成,主要完成工作:

(1)修改服务器的最大连接数为65535
(2)关闭selinux
(3)关闭防火墙
(4)修改服务器字符集–已注释代码
(5)配置hostname

#!/bin/bash
#create  skyfans
#version  v1.0
#注意:49行请修改你时间的网卡的名字
function  pluge()
{
	#修改文件最大连接数为65534
	check_limit=`grep  "65534" /etc/security/limits.conf|wc -l`
	#关闭selinux
	check_SELINUX=`grep "SELINUX=disabled" /etc/sysconfig/selinux |wc -l`
	#根据实际要求修改字符集,这里默认为UTF-8,所有注释掉
	#check_LANG=`grep  "zh_CN.GB18030" /etc/sysconfig/i18n|wc -l  `
    #    if [ $check_LANG -lt 1 ]
	#	then
	#   		sed   -i   's/en_US.UTF-8/zh_CN.GB18030/'  /etc/sysconfig/i18n   
	#		source   /etc/sysconfig/i18n
	#		echo  $LANG
 	#	else
	#		echo  "LANG alreay pluge"
	#	fi
	if  [ $check_limit -lt 1 ]
		then
			cat  >>/etc/security/limits.conf<<EOF
			* soft nofile 65534
			* hard nofile 65534
EOF
			tail    /etc/security/limits.conf
		else
 			echo  "limits  already  pluge"
		fi
	if [ $check_SELINUX -lt 1 ]
		then
			sed -i  's/SELINUX=enforcing/SELINUX=disabled/'  /etc/sysconfig/selinux
		else
 			echo  "SELINUX  alreay  pluge"
	fi
    #关闭防火墙 
    service iptables stop
	chkconfig  iptables  off
	service ip6tables stop
	chkconfig  ip6tables  off
	setenforce 0
        echo  "iptables  already  closed,please input  'service iptables status  ' check"
         
            
}
function pluge_nameserver() {
    #注意修改服务器实际的网卡地址
	getIp=`ifconfig   eth0 | grep  "inet addr"  | awk -F: '{print  $2}' | awk  '{print $1}'`      
    gethostname=`hostname`
	check_nameserver=`grep $getIp  /etc/hosts |wc -l`
        if [ $check_nameserver -lt  0 ]
 	then
        	echo   "$getIp  $gethostname " >> /etc/hosts
	else  
		echo   "nameserver  alreay  pluge"
	fi
}
function  check_nameserver(){
       gethostname=`hostname`
       ping  $gethostname -c  4 
     if  [ $? -eq  0 ]
     then
 	echo  "nameserver  pluge  susccess"
     else
	echo  "nameserver  pluge  failed"
    fi
}

pluge
pluge_nameserver
check_nameserver

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的示例脚本,可以使用sed命令更改配置文件中的IP地址和其他参数来部署DNS服务器和PXE服务器。 ```bash #!/bin/bash # 安装所需软件 apt-get update apt-get install -y isc-dhcp-server dnsmasq # 配置DNS服务器 sed -i 's/#listen-on port 53/listen-on port 53/' /etc/bind/named.conf.options sed -i 's/#allow-query/allow-query/' /etc/bind/named.conf.options sed -i 's/#forwarders {/forwarders {/' /etc/bind/named.conf.options sed -i 's/#\t0.0.0.0;/\t8.8.8.8;/g' /etc/bind/named.conf.options sed -i 's/#\t0.0.0.0;/\t8.8.4.4;/g' /etc/bind/named.conf.options sed -i 's/#};/};/' /etc/bind/named.conf.options # 配置PXE服务器 sed -i 's/#dhcp-range=/dhcp-range=/' /etc/dnsmasq.conf sed -i 's/#dhcp-boot=/dhcp-boot=/' /etc/dnsmasq.conf sed -i 's/#pxe-service=X86PC/pxe-service=X86PC/' /etc/dnsmasq.conf sed -i 's/#pxe-prompt/pxe-prompt/' /etc/dnsmasq.conf sed -i 's/#enable-tftp/enable-tftp/' /etc/dnsmasq.conf sed -i 's/#tftp-root/tftp-root/' /etc/dnsmasq.conf # 启动服务 systemctl restart isc-dhcp-server systemctl restart dnsmasq ``` 此脚本假设您已经安装了必要的软件包,如`isc-dhcp-server`和`dnsmasq`。在此示例中,我们使用sed命令来修改DNS和PXE服务器配置文件,以使用正确的IP地址和其他参数。最后,我们重启了两个服务,以使更改生效。 请注意,此脚本并不完整,并且可能需要根据您的环境进行更改。此外,您可能需要根据您的网络设置和服务器配置文件进行更改。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值