#!/bin/bash#判断是否安装apacherpm -qa | grep httpdif [ $? -ne 0 ]then yum install -y httpd* &> /dev/nullfi#配置apache服务http_conf=/etc/httpd/conf/httpd.confmyweb=/var/www/html/vhost=/etc/httpd/conf/vhost/sed -i \'353aInclude conf/vhost/*.conf\' /etc/httpd/conf/httpd.conf[ -e $vhost ] || mkdir $vhostecho \"<VirtualHost 192.168.1.9>\" > ${vhost}test.confecho \"ServerName test.com\" >> ${vhost}test.confecho \"DocumentRoot /var/www/html/test/\" >> ${vhost}test.confecho \"<Directory “/var/www/html/test”>\" >> ${vhost}test.confecho \"Options Indexes FollowSymLinks\">> ${vhost}test.confecho \"AllowOverride NOne\" >> ${vhost}test.confecho \"Require all granted\" >> ${vhost}test.confecho \"</Directory>\" >> ${vhost}test.confecho \"</VirtualHost>\" >> ${vhost}test.conf#hosts文件修改sed -i \'2a192.168.1.9 www.test.com\' /etc/hosts#判断网站文件是否存在[ -e /var/www/html/test ] && echo \"网站存在\" || echo \"请上传网站到/var/www/html/ 网站文件夹名为test\"#重启服务systemctl restart httpd#防火墙开启80端口firewall-cmd --zone=public --add-port=80/tcp --permanentecho \"你的Apache启动成功\"