1 安装sendEmail
tar xvf sendEmail-v1.56.tar.gz
mv sendEmail-v1.56 sendEmail
2 添加apache虚拟主机shell脚本:
vi
#!/bin/bash
cat <<EOF>> /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerAdmin admin@$1
DocumentRoot /$1
ServerName $1
ErrorLog logs/$1-error_log
CustomLog logs/$1-access_log common
</VirtualHost>
EOF
mkdir /$1
chmod 755 /$1
service httpd restart
port=`netstat -anl|grep 80 |sed -n '1p' |awk '{print $4}'|awk -F: '{ print $2}'`
ip=`ifconfig eth0|sed -n 2p|awk '{ print $2 }'|awk -F : '{ print $2 }'`
if [ "$port" != "80" ]
then
/home/shell/sendEmail/sendEmail -f xxx@xxx -t xxx@xxx -s smtp.xxx -u "apache启动有问题!!!" -xu USER -xp PASSWD -m "${ip} apache shutdown,Please contact the administrator"
fi
执行脚本添加虚拟主机:
NameVirtualHost *:80 ####必须要开户###
[root@3 shell]# sh ###就是用户自己输入的域名####
测试:
在本地hosts文件添加:
192.168.2.5
192.168.2.5
访问 ####在生成的/文件下面创建个主页####
####说明添加虚拟主机正常#####
添加虚拟主机
[root@3 shell]# sh
测试:
访问 ####在生成的/文件下面创建个主页####
3 删除虚拟主机脚本:
vi
#!/bin/bash
i=$1
sed ':n;/ServerName '$i'[^\n]*$/{$!N;$!N;$!N;d};/\n.*\n.*\n/!{N;bn};P;D' /etc/httpd/conf/httpd.conf >httpd.conf.bak
>/etc/httpd/conf/httpd.conf
cat httpd.conf.bak>/etc/httpd/conf/httpd.conf
service httpd restart
port=`netstat -anl|grep 80 |sed -n '1p' |awk '{print $4}'|awk -F: '{ print $2}'` ###获取端口###
ip=`ifconfig eth0|sed -n 2p|awk '{ print $2 }'|awk -F : '{ print $2 }'`
if [ "$port" != "80" ] ####判断是否等于80,不等于就发送邮件####
then
/home/shell/sendEmail/sendEmail -f xxx@xxx -t xxx@xxx -s -u "apache启动有问题!!!" -xu USER -xp PASSWD -m "${ip} apache shutdown,Please contact the administrator"
fi
执行删除虚拟主机脚本:
[root@3 shell]# sh
再次访问看是否正常?
OK!!访问到那边去了,因为我默认的主页是,自动跳转。
测试下当apache没有启动的报警(脚本只为测试,没有直接加上面的测试):
vi port.sh
#!/bin/bash
service httpd stop
port=`netstat -anl|grep 80 |sed -n '1p' |awk '{print $4}'|awk -F: '{ print $2}'`
ip=`ifconfig eth0|sed -n 2p|awk '{ print $2 }'|awk -F : '{ print $2 }'`
if [ "$port" != "80" ]
then
/home/shell/sendEmail/sendEmail -f xxx@xxx -t xxx@xxx -s smtp.xxx -u "apache启动有问题!!!" -xu USER -xp PASSWD -m "${ip} apache shutdown,Please contact the administrator"
fi
测试:
[root@3 shell]# sh port.sh
停止 httpd:[确定]
Dec 13 18:17:41 3 sendEmail[3788]: Email was sent successfully!
查看邮件:
#########使用简单脚本配置多虚拟主机会快速,以上脚本可以配合PHP使用,从PHP页面上配置虚拟主机,方便。。。。。




















