shell自动化脚本—apache安装

安装apache

首先挂载光盘,把源码包拖进桌面home文件夹中

#创建httpd日志文件
touch /httpdlog.txt
#创建php日志文件
touch /phplog.txt


#关闭防火墙沙盒
systemctl stop firewalld
setenforce 0

#搭建本地yum库
cd /etc/yum.repos.d/
rm -rf *
touch yum.repo
echo "[yum]" > yum.repo
echo "baseurl=file:///media" >>yum.repo
echo "enabled=1" >>yum.repo
echo "gpgcheck=0" >> yum.repo

#配置IP
read -p "输入网卡接口名称:" ens
read -p "输入IP地址:" ip
read -p "输入子网掩码:" mask
read -p "输入网关地址:" route
read -p "输入首选DNS地址:" dns
ifc="/etc/sysconfig/network-scripts/ifcfg-"
echo "DEVICE=$ens" > $ifc$ens
echo "TYPE=Ethernet" >> $ifc$ens
echo "BOOTPROTO=static" >> $ifc$ens
echo "ONBOOT=yes" >> $ifc$ens
echo "IPADDR=$ip" >> $ifc$ens
echo "NETMASK=$mask" >> $ifc$ens
echo "GATEWAY=$route" >> $ifc$ens
echo "DNS1=$dns" >> $ifc$ens
systemctl restart network
echo "IP配置完成"

#挂载光盘
mount /dev/sr0 /media &> /httpdlog.txt
echo "光盘以挂载"

echo "正在编译安装请耐心等待..."
#卸载之前版本的httpd
rpm -e httpd --nodeps &>> /httpdlog.txt

#安装
yum -y install  apr apr-devel cyrus-sasl-devel  expat-devel   libdb-devel  openldap-devel  apr-util  apr-util-devel  pcre-devel  pcre &> /httpdlog.txt

#编译安装httpd
cd
tar -zxvf httpd-2.4.25.tar.gz  -C /usr/src/ &> /httpdlog.txt
cd /usr/src/httpd-2.4.25/
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi --enable-sockets &>> /httpdlog.txt
yum -y install gcc gcc-c++ &>> /httpdlog.txt

make &>> /httpdlog.txt
make install &>> /httpdlog.txt

ln -s /usr/local/httpd/bin/*   /usr/local/bin
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
chmod a+x /etc/init.d/httpd

#添加注释
sed -i '1a#chkconfig:35 85 21' /etc/init.d/httpd
sed -i '2a#description:apache http server' /etc/init.d/httpd

chkconfig --add httpd
chkconfig httpd on

#编辑主配置文件
read -p "请输入监听端口:" a
read -p "请输入ServerName:"  b
read -p "请输入端口号:" c

sed -i "/Listen /{s/80/$a/g}" /usr/local/httpd/conf/httpd.conf
sed -i "/#ServerName/{s/#ServerName/ServerName/;s/www.example.com/$b/;s/80/$c/g}" /usr/local/httpd/conf/httpd.conf

/usr/local/httpd/bin/apachectl  start
systemctl start httpd
#测试页面
firefox $b

源码包获取:

网盘链接:https://pan.baidu.com/s/1IRXKKOjMcmJFj51Xt_5cWA
提取码:629h

你可能感兴趣的:(shell,linux,centos,apache,shell,web)