系统初始化脚本可以统一、自动配置,减少人力。
这里浅谈一下yum安装与源码编译安装,请各位不吝指正。我一直坚持yum安装,原因如下
一、安装方便,不需要再花精力考虑依赖问题
二、配置统一,方便后期维护,自动化等
三、方便升级
#!/bin/sh #判断用户身份 username=`whoami`; if [ $username != "root" ] then echo "当前用户权限不足,即将退出脚本"; exit 2; fi #验证用户网络 echo "检测网络中..."; /bin/ping www.baidu.com -c 2 >> /dev/null if [ $? != 0 ] then echo "网络无法正常通信,请检查网络配置"; exit 3; fi echo "网络正常"; sleep 1; #安装yum remi php源 if rpm -qa|grep remi-release >> /dev/null;then echo "remi resource is installed"; else yum_changes="a"; version=`cat /etc/issue|head -n 1|awk {‘print $3‘}|tr "." "\n"|head -n 1` if [ $version == 5 ] then rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm http://rpms.famillecollet.com/enterprise/remi-release-5.rpm 2>&1 >> /tmp/sys_log.txt elif [ $version == 6 ] then rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm http://rpms.famillecollet.com/enterprise/remi-release-6.rpm 2>&1 >> /tmp/sys_log.txt fi if [ $? != 0 ] then echo "安装yum 源失败,请检查tmp下的日志"; else echo "yum源已经安装完毕,请自行配置remi源配置文件,选择PHP的版本"; fi fi #询问用户是否关闭selinux selinux_st=`sestatus | awk {‘print $3‘}` if [ $selinux_st != "disabled" ] then se_changes="a"; until [ $se_changes == "yes" ] && [ $se_changes == "no" ] do read -p "当前selinux状态为开启,是否要关闭(输入yes关闭,输入no不关闭):"se_changes done if [ $se_changes == "yes" ] then sed -i ‘s/^SELINUX=enforcing$/SELINUX=disables/‘ /etc/selinux/config 2>&1 >> /tmp/sys_log.txt if [$? != 0] then echo "关闭selinux中出错,请查看tmp下的日志"; fi elif [ $se_changes == "no" ] then echo "你选择了不关闭selinux"; fi else echo "检测到selinux已经关闭"; fi
说下脚本的业务逻辑吧:
- 判断用户身份 [非root退出脚本]
- 检测服务器网络是否正常 [出错退出脚本]
- 安装remi yum源
- 关闭selinux
- 关闭iptables
- 变更SSH端口
- 更改linux网络内核参数
#其中关闭iptables,变更SSH端口,更改linux网络内核参数,暂时没写逻辑代码,周末会更新上
时间: 2024-11-09 16:56:46