1. Install sendEmail
Tar xvf sendEmail-v1.56.tar.gz
Music sendEmail-v1.56 sendEmail
2. Add the apache VM shell script:
Vi addVirtual. sh
#! /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-f xxx @ xxx-t xxx @ xxx-s smtp. xxx-u "An error occurred while starting apache !!! "-Xu USER-xp PASSWD-m" $ {ip} apache shutdown, Please contact the administrator"
Fi
Run the script to add a VM:
NameVirtualHost *: 80 #### account opening required ###
[Root @ 3 shell] # sh addVirtual. sh 2.test.com ### 2.test.com is the domain name entered by the user ####
Test:
Add the following in the local hosts file:
192.168.2.5 2.test.com
192.168.2.5 3.test.com
Access 2.test.com #### create a homepage under the generated/2.test.com file ####
#### Adding a VM is normal #####
Add 3.test.com VM
[Root @ 3 shell] # sh addVirtual. sh 3.test.com
Test:
Access 3.test.com #### create a homepage under the generated/3.test.com file ####
3. Delete the VM script:
Vi delvirtual. sh
#! /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}' ### obtain the port ###
Ip = 'ifconfig eth0 | sed-n 2p | awk '{print $2}' | awk-F: '{print $2 }''
If ["$ port "! = "80"] #### determine whether the email is equal to or equal to 80. If the email is not equal to 80 ####
Then
/Home/shell/sendEmail-f xxx @ xxx-t xxx @ xxx-s smtp.zhnews.net-u "An error occurred while starting apache !!! "-Xu USER-xp PASSWD-m" $ {ip} apache shutdown, Please contact the administrator"
Fi
Run the script to delete the VM:
[Root @ 3 shell] # sh delvirtual. sh 3.test.com
Check if it is normal to access 3.test.com again?
OK !! Access to 2.test.com because my default homepage is 2.test.com, which automatically jumps.
Under the test, when apache does not start the alarm (the script is only for the test, but not directly added to the test ):
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-f xxx @ xxx-t xxx @ xxx-s smtp. xxx-u "An error occurred while starting apache !!! "-Xu USER-xp PASSWD-m" $ {ip} apache shutdown, Please contact the administrator"
Fi
Test:
[Root @ 3 shell] # sh port. sh
Stop httpd: [OK]
December 13 18:17:41 3 sendEmail [3788]: Email was sent successfully!
View Email:
######### Using a simple script to configure multiple virtual hosts is fast. The above script can be used with PHP to configure virtual hosts on the PHP page for convenience ....
Address: http://youzao.blog.51cto.com/3946111/741077