瀏覽代碼

Support Tomcat virtualhost

lj2007331 9 年之前
父節點
當前提交
6b794b887d

+ 7 - 5
backup_setup.sh

@@ -71,7 +71,7 @@ do
 done
 sed -i "s@^expired_days=.*@expired_days=$expired_days@" ./options.conf
 
-databases=`$db_install_dir/bin/mysql -uroot -p$dbrootpwd -e "show databases\G" | grep Database | awk '{print $2}' | grep -Evw "(performance_schema|information_schema|mysql)"`
+databases=`$db_install_dir/bin/mysql -uroot -p$dbrootpwd -e "show databases\G" | grep Database | awk '{print $2}' | grep -Evw "(performance_schema|information_schema|mysql|sys)"`
 while :
 do
     echo
@@ -80,7 +80,6 @@ do
     db_name=`echo $db_name | tr -d ' '`
     [ -z "$db_name" ] && db_name="`echo $databases | tr ' ' ','`"
     D_tmp=0
-    echo $db_name
     for D in `echo $db_name | tr ',' ' '`
     do
         [ -z "`echo $databases | grep -w $D`" ] && { echo "${CWARNING}$D was not exist! ${CEND}" ; D_tmp=1; }
@@ -98,16 +97,19 @@ do
     website_name=`echo $website_name | tr -d ' '`
     [ -z "$website_name" ] && website_name="`echo $websites | tr ' ' ','`"
     W_tmp=0
-    echo $db_name
     for W in `echo $website_name | tr ',' ' '`
     do
-        [ ! -e "$wwwroot_dir/$W" ] && { echo -e "\033[31m$wwwroot_dir/$W not exist! \033[0m" ; W_tmp=1; }
+        [ ! -e "$wwwroot_dir/$W" ] && { echo "${CWARNING}$wwwroot_dir/$W not exist! ${CEND}" ; W_tmp=1; }
     done
     [ "$W_tmp" != '1' ] && break
 done
-echo $website_name
 sed -i "s@^website_name=.*@website_name=$website_name@" ./options.conf
 
+echo
+echo "You have to backup the content:"
+echo "Database: ${CMSG}$db_name${CEND}"
+echo "Website: ${CMSG}$website_name${CEND}"
+
 if [ "$remote_bankup_yn" == 'y' ];then
     > tools/iplist.txt
     while :

+ 4 - 10
config/server.xml

@@ -1,4 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE server-xml [
+<!ENTITY localhost-vhost SYSTEM "file:///usr/local/tomcat/conf/vhost/localhost.xml">
+]>
 <Server port="8006" shutdown="SHUTDOWN">
   <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
@@ -29,16 +32,7 @@
               enableLookups="false"
               URIEncoding="UTF-8" />
     <Engine name="Catalina" defaultHost="localhost">
-      <Realm className="org.apache.catalina.realm.LockOutRealm">
-        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
-               resourceName="UserDatabase"/>
-      </Realm>
-       <Host name="localhost"  appBase="webapps"
-             unpackWARs="true" autoDeploy="true">
-	<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
-               prefix="localhost_access_log." suffix=".txt"
-               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
-      </Host>
+      &localhost-vhost;
     </Engine>
   </Service>
 </Server>

+ 15 - 34
include/hhvm_CentOS.sh

@@ -31,13 +31,12 @@ EOF
     fi
     cat > /etc/yum.repos.d/hhvm.repo << EOF
 [hhvm]
-name=Copr repo for hhvm-repo owned by no1youknowz
-baseurl=https://copr-be.cloud.fedoraproject.org/results/no1youknowz/hhvm-repo/epel-7-\$basearch/
-skip_if_unavailable=True
+name=gleez hhvm-repo
+baseurl=http://mirrors.linuxeye.com/hhvm-repo/7/\$basearch/
+enabled=1
 gpgcheck=0
-enabled=0
 EOF
-    yum --enablerepo=hhvm -y install hhvm
+    yum -y install hhvm
     [ ! -e "/usr/bin/hhvm" -a "/usr/local/bin/hhvm" ] && ln -s /usr/local/bin/hhvm /usr/bin/hhvm
 fi
 
@@ -56,39 +55,22 @@ gpgcheck=0
 EOF
     fi
 
-    for Package in libmcrypt-devel glog-devel jemalloc-devel tbb-devel libdwarf-devel mysql-devel libxml2-devel libicu-devel pcre-devel gd-devel boost-devel sqlite-devel pam-devel bzip2-devel oniguruma-devel openldap-devel readline-devel libc-client-devel libcap-devel libevent-devel libcurl-devel libmemcached-devel lcms2 inotify-tools
+    for Package in libmcrypt-devel glog-devel jemalloc-devel tbb-devel libdwarf-devel libxml2-devel libicu-devel pcre-devel gd-devel boost-devel sqlite-devel pam-devel bzip2-devel oniguruma-devel openldap-devel readline-devel libc-client-devel libcap-devel libevent-devel libcurl-devel libmemcached-devel lcms2 inotify-tools
     do
         yum -y install $Package
     done
 
-    [ "$IPADDR_STATE"x == "CN"x ] && REMI_ADDR=http://mirrors.swu.edu.cn || REMI_ADDR=http://mirrors.mediatemple.net
-
-    cat > /etc/yum.repos.d/remi.repo << EOF
-[remi]
-name=Les RPM de remi pour Enterprise Linux 6 - \$basearch
-baseurl=$REMI_ADDR/remi/enterprise/6/remi/\$basearch/
-#mirrorlist=http://rpms.famillecollet.com/enterprise/6/remi/mirror
-enabled=0
-gpgcheck=0
-EOF
-
-    yum -y remove libwebp
-    src_url=http://mirrors.linuxeye.com/oneinstack/src/libwebp-0.3.1-2.el6.remi.x86_64.rpm && Download_src
-    src_url=http://mirrors.linuxeye.com/oneinstack/src/hhvm-3.5.0-4.el6.x86_64.rpm && Download_src
-    rpm -ivh libwebp-0.3.1-2.el6.remi.x86_64.rpm
-    yum --enablerepo=remi --disablerepo=epel -y install mysql mysql-devel mysql-libs
+    yum -y remove libwebp boost-system boost-filesystem
 
-    yum -y remove boost-system boost-filesystem
-
-    cat > /etc/yum.repos.d/gleez.repo << EOF
-[gleez]
-name=Gleez repo
-baseurl=http://yum.gleez.com/6/\$basearch/
-enabled=0
+    cat > /etc/yum.repos.d/hhvm.repo << EOF
+[hhvm]
+name=gleez hhvm-repo
+baseurl=http://mirrors.linuxeye.com/hhvm-repo/6/\$basearch/
+enabled=1
 gpgcheck=0
 EOF
-    ping yum.gleez.com -c 4 >/dev/null 2>&1
-    yum --enablerepo=gleez --disablerepo=epel -y install -R 2 ./hhvm-3.5.0-4.el6.x86_64.rpm
+    yum --disablerepo=epel -y install mysql mysql-devel mysql-libs
+    yum --disablerepo=epel -y install hhvm 
 fi
 
 userdel -r nginx;userdel -r saslauth
@@ -155,7 +137,7 @@ memory_limit = 400000000
 post_max_size = 50000000
 EOF
 
-if [ -e "/usr/bin/hhvm" -a ! -e "$php_install_dir" ];then
+if [ -e "$web_install_dir/sbin/nginx" -a -e "/usr/bin/hhvm" -a ! -e "$php_install_dir" ];then
     sed -i 's@/dev/shm/php-cgi.sock@/var/log/hhvm/sock@' $web_install_dir/conf/nginx.conf 
     [ -z "`grep 'fastcgi_param SCRIPT_FILENAME' $web_install_dir/conf/nginx.conf`" ] && sed -i "s@fastcgi_index index.php;@&\n\t\tfastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;@" $web_install_dir/conf/nginx.conf 
     sed -i 's@include fastcgi.conf;@include fastcgi_params;@' $web_install_dir/conf/nginx.conf 
@@ -179,8 +161,7 @@ autostart=true ; start at supervisord start (default: true)
 autorestart=unexpected ; whether/when to restart (default: unexpected)
 stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
 EOF
-src_url=https://github.com/Supervisor/initscripts/raw/master/redhat-init-mingalevme && Download_src
-/bin/mv redhat-init-mingalevme /etc/init.d/supervisord
+/bin/cp ../init.d/Supervisor-init-CentOS /etc/init.d/supervisord
 chmod +x /etc/init.d/supervisord
 chkconfig supervisord on
 service supervisord start

+ 1 - 1
include/mariadb-10.0.sh

@@ -192,7 +192,7 @@ $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.proxies
 $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "drop database test;"
 $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "reset master;"
 rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona}*.conf
-echo "$mariadb_install_dir/lib" > mariadb.conf 
+echo "$mariadb_install_dir/lib" > /etc/ld.so.conf.d/mariadb.conf 
 ldconfig
 service mysqld stop
 }

+ 1 - 1
include/mariadb-5.5.sh

@@ -192,7 +192,7 @@ $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.proxies
 $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "drop database test;"
 $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "reset master;"
 rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona}*.conf
-echo "$mariadb_install_dir/lib" > mariadb.conf 
+echo "$mariadb_install_dir/lib" > /etc/ld.so.conf.d/mariadb.conf 
 ldconfig
 service mysqld stop
 }

+ 1 - 1
include/mysql-5.5.sh

@@ -204,7 +204,7 @@ $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.proxies_p
 $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "drop database test;"
 $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "reset master;"
 rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona}*.conf
-echo "$mysql_install_dir/lib" > mysql.conf 
+echo "$mysql_install_dir/lib" > /etc/ld.so.conf.d/mysql.conf 
 ldconfig
 service mysqld stop
 }

+ 1 - 1
include/mysql-5.6.sh

@@ -203,7 +203,7 @@ $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.proxies_p
 $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "drop database test;"
 $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "reset master;"
 rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona}*.conf
-echo "$mysql_install_dir/lib" > mysql.conf 
+echo "$mysql_install_dir/lib" > /etc/ld.so.conf.d/mysql.conf 
 ldconfig
 service mysqld stop
 }

+ 1 - 1
include/percona-5.5.sh

@@ -204,7 +204,7 @@ $percona_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.proxies
 $percona_install_dir/bin/mysql -uroot -p$dbrootpwd -e "drop database test;"
 $percona_install_dir/bin/mysql -uroot -p$dbrootpwd -e "reset master;"
 rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona}*.conf
-echo "$percona_install_dir/lib" > percona.conf
+echo "$percona_install_dir/lib" > /etc/ld.so.conf.d/percona.conf
 ldconfig
 service mysqld stop
 }

+ 1 - 1
include/percona-5.6.sh

@@ -203,7 +203,7 @@ $percona_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.proxies
 $percona_install_dir/bin/mysql -uroot -p$dbrootpwd -e "drop database test;"
 $percona_install_dir/bin/mysql -uroot -p$dbrootpwd -e "reset master;"
 rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona}*.conf
-echo "$percona_install_dir/lib" > percona.conf
+echo "$percona_install_dir/lib" > /etc/ld.so.conf.d/percona.conf
 ldconfig
 service mysqld stop
 }

+ 21 - 0
include/tomcat-7.sh

@@ -58,6 +58,27 @@ EOF
         /bin/mv $tomcat_install_dir/conf/server.xml{,_bk} 
         cd $oneinstack_dir/src
         /bin/cp ../config/server.xml $tomcat_install_dir/conf
+        sed -i "s@/usr/local/tomcat@$tomcat_install_dir@" $tomcat_install_dir/conf
+        [ ! -d "$tomcat_install_dir/conf/vhost" ] && mkdir $tomcat_install_dir/conf/vhost
+        cat > $tomcat_install_dir/conf/vhost/localhost.xml << EOF
+<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
+  <Context path="" docBase="$wwwroot_dir/default" debug="0" reloadable="true" crossContext="true"/>
+  <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
+         prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
+</Host>
+EOF
+        # logrotate tomcat catalina.out 
+        cat > /etc/logrotate.d/tomcat << EOF
+$tomcat_install_dir/logs/catalina.out {
+daily
+rotate 5
+missingok
+dateext
+compress
+notifempty
+copytruncate
+}
+EOF
         cat > $tomcat_install_dir/conf/jmxremote.access << EOF
 monitorRole   readonly
 controlRole   readwrite \

+ 21 - 0
include/tomcat-8.sh

@@ -58,6 +58,27 @@ EOF
         /bin/mv $tomcat_install_dir/conf/server.xml{,_bk} 
         cd $oneinstack_dir/src
         /bin/cp ../config/server.xml $tomcat_install_dir/conf
+        sed -i "s@/usr/local/tomcat@$tomcat_install_dir@" $tomcat_install_dir/conf
+        [ ! -d "$tomcat_install_dir/conf/vhost" ] && mkdir $tomcat_install_dir/conf/vhost
+        cat > $tomcat_install_dir/conf/vhost/localhost.xml << EOF
+<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
+  <Context path="" docBase="$wwwroot_dir/default" debug="0" reloadable="true" crossContext="true"/>
+  <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 
+         prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
+</Host>
+EOF
+        # logrotate tomcat catalina.out
+        cat > /etc/logrotate.d/tomcat << EOF
+$tomcat_install_dir/logs/catalina.out {
+daily
+rotate 5
+missingok
+dateext
+compress
+notifempty
+copytruncate
+}
+EOF
         cat > $tomcat_install_dir/conf/jmxremote.access << EOF
 monitorRole   readonly
 controlRole   readwrite \

+ 153 - 0
init.d/Supervisor-init-CentOS

@@ -0,0 +1,153 @@
+#!/bin/bash
+#
+# supervisord   This scripts turns supervisord on
+#
+# Author:       Mike McGrath <mmcgrath@redhat.com> (based off yumupdatesd)
+#               Jason Koppe <jkoppe@indeed.com> adjusted to read sysconfig,
+#                   use supervisord tools to start/stop, conditionally wait
+#                   for child processes to shutdown, and startup later
+#               Mikhail Mingalev <mingalevme@gmail.com> Merged
+#                   redhat-init-jkoppe and redhat-sysconfig-jkoppe, and
+#                   made the script "simple customizable".
+#               Brendan Maguire <maguire.brendan@gmail.com> Added OPTIONS to
+#                   SUPERVISORCTL status call
+#
+# chkconfig:    345 83 04
+#
+# description:  supervisor is a process control utility.  It has a web based
+#               xmlrpc interface as well as a few other nifty features.
+#               Script was originally written by Jason Koppe <jkoppe@indeed.com>.
+#
+
+# source function library
+. /etc/rc.d/init.d/functions
+
+set -a
+
+PREFIX=/usr
+
+SUPERVISORD=$PREFIX/bin/supervisord
+SUPERVISORCTL=$PREFIX/bin/supervisorctl
+
+PIDFILE=/var/run/supervisord.pid
+LOCKFILE=/var/lock/subsys/supervisord
+
+OPTIONS="-c /etc/supervisord.conf"
+
+# unset this variable if you don't care to wait for child processes to shutdown before removing the $LOCKFILE-lock
+WAIT_FOR_SUBPROCESSES=yes
+
+# remove this if you manage number of open files in some other fashion
+ulimit -n 96000
+
+RETVAL=0
+
+
+running_pid()
+{
+    # Check if a given process pid's cmdline matches a given name
+    pid=$1
+    name=$2
+    [ -z "$pid" ] && return 1
+    [ ! -d /proc/$pid ] && return 1
+    (cat /proc/$pid/cmdline | tr "\000" "\n"|grep -q $name) || return 1
+    return 0
+}
+
+running()
+{
+# Check if the process is running looking at /proc
+# (works for all users)
+
+    # No pidfile, probably no daemon present
+    [ ! -f "$PIDFILE" ] && return 1
+    # Obtain the pid and check it against the binary name
+    pid=`cat $PIDFILE`
+    running_pid $pid $SUPERVISORD || return 1
+    return 0
+}
+
+start() {
+        echo "Starting supervisord: "
+	
+        if [ -e $PIDFILE ]; then 
+		echo "ALREADY STARTED"
+		return 1
+	fi
+
+	# start supervisord with options from sysconfig (stuff like -c)
+        $SUPERVISORD $OPTIONS
+	
+	# show initial startup status
+	$SUPERVISORCTL $OPTIONS status
+	
+	# only create the subsyslock if we created the PIDFILE
+        [ -e $PIDFILE ] && touch $LOCKFILE
+}
+
+stop() {
+        echo -n "Stopping supervisord: "
+        $SUPERVISORCTL $OPTIONS shutdown
+	if [ -n "$WAIT_FOR_SUBPROCESSES" ]; then 
+            echo "Waiting roughly 60 seconds for $PIDFILE to be removed after child processes exit"
+            for sleep in  2 2 2 2 4 4 4 4 8 8 8 8 last; do
+                if [ ! -e $PIDFILE ] ; then
+                    echo "Supervisord exited as expected in under $total_sleep seconds"
+                    break
+                else
+                    if [[ $sleep -eq "last" ]] ; then
+                        echo "Supervisord still working on shutting down. We've waited roughly 60 seconds, we'll let it do its thing from here"
+                        return 1
+                    else
+                        sleep $sleep
+                        total_sleep=$(( $total_sleep + $sleep ))
+                    fi
+
+                fi
+            done
+        fi
+
+        # always remove the subsys. We might have waited a while, but just remove it at this point.
+        rm -f $LOCKFILE
+}
+
+restart() {
+        stop
+        start
+}
+
+case "$1" in
+    start)
+        start
+        RETVAL=$?
+        ;;
+    stop)
+        stop
+        RETVAL=$?
+        ;;
+    restart|force-reload)
+        restart
+        RETVAL=$?
+        ;;
+    reload)
+        $SUPERVISORCTL $OPTIONS reload
+        RETVAL=$?
+        ;;
+    condrestart)
+        [ -f $LOCKFILE ] && restart
+        RETVAL=$?
+        ;;
+    status)
+        $SUPERVISORCTL $OPTIONS status
+        if running ; then
+            RETVAL=0
+        else
+            RETVAL=1
+        fi
+        ;;
+    *)
+        echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
+        exit 1
+esac
+
+exit $RETVAL

+ 4 - 4
install.sh

@@ -229,8 +229,8 @@ do
                 echo -e "\t${CMSG}3${CEND}. Install php-5.5"
                 echo -e "\t${CMSG}4${CEND}. Install php-5.6"
                 echo -e "\t${CMSG}5${CEND}. Install php-7/phpng(RC)"
-                read -p "Please input a number:(Default 1 press Enter) " PHP_version
-                [ -z "$PHP_version" ] && PHP_version=1
+                read -p "Please input a number:(Default 3 press Enter) " PHP_version
+                [ -z "$PHP_version" ] && PHP_version=3
                 if [ $PHP_version != 1 -a $PHP_version != 2 -a $PHP_version != 3 -a $PHP_version != 4 -a $PHP_version != 5 ];then
                     echo "${CWARNING}input error! Please only input number 1,2,3,4,5${CEND}"
                 else
@@ -709,9 +709,9 @@ do
         echo "${CMSG}Please restart the server and see if the services start up fine.${CEND}"
         read -p "Do you want to restart OS ? [y/n]: " restart_yn
         if [ "$restart_yn" != 'y' -a "$restart_yn" != 'n' ];then
-		echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
+            echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
         else
-                break
+            break
         fi
 done
 [ "$restart_yn" == 'y' ] && reboot

+ 3 - 3
tools/mssh.exp

@@ -107,7 +107,7 @@ if { $yesnoflag == 2 } {
 }
 
 expect {
-	"#" {send "$commands \r"}
+	"@" {send "$commands \r"}
 	"assword:" {
 		send "$passwd\r"
 		puts "\nPASSWORDERROR: $ip Password error!!!\n"
@@ -116,11 +116,11 @@ expect {
 }
 
 expect {
-	"#" {send "sleep 1 \r"}
+	"@" {send "sleep 1\r"}
 }
 
 expect {
-	"#" {send "exit\r"}
+	"@" {send "exit\r"}
 }
 
 expect eof {

+ 54 - 53
vhost.sh

@@ -34,8 +34,7 @@ ${CMSG}del${CEND}    --->Delete Virtualhost
 "
 }
 
-Choose_env()
-{
+Choose_env() {
 if [ -e "$php_install_dir/bin/phpize" -a -e "$tomcat_install_dir/conf/server.xml" -a -e "/usr/bin/hhvm" ];then
     Number=111
     while :
@@ -133,8 +132,7 @@ elif [ "$NGX_FLAG" == 'hhvm' ];then
 fi
 }
 
-Input_Add_domain()
-{
+Input_Add_domain() {
 while :
 do
     echo
@@ -146,9 +144,10 @@ do
     fi
 done
 
-if [ -e "$web_install_dir/conf/vhost/$domain.conf" -o -e "$apache_install_dir/conf/vhost/$domain.conf" ]; then
-    [ -e "$web_install_dir/conf/vhost/$domain.conf" ] && echo -e "$domain in the Nginx/Tengine already exist! \nYou can delete \033[32m$web_install_dir/conf/vhost/$domain.conf\033[0m and re-create"
-    [ -e "$apache_install_dir/conf/vhost/$domain.conf" ] && echo -e "$domain in the Apache already exist! \nYou can delete \033[32m$apache_install_dir/conf/vhost/$domain.conf\033[0m and re-create"
+if [ -e "$web_install_dir/conf/vhost/$domain.conf" -o -e "$apache_install_dir/conf/vhost/$domain.conf" -o -e "$tomcat_install_dir/conf/vhost/$domain.xml" ]; then
+    [ -e "$web_install_dir/conf/vhost/$domain.conf" ] && echo -e "$domain in the Nginx/Tengine already exist! \nYou can delete ${CMSG}$web_install_dir/conf/vhost/$domain.conf${CEND} and re-create"
+    [ -e "$apache_install_dir/conf/vhost/$domain.conf" ] && echo -e "$domain in the Apache already exist! \nYou can delete ${CMSG}$apache_install_dir/conf/vhost/$domain.conf${CEND} and re-create"
+    [ -e "$tomcat_install_dir/conf/vhost/$domain.xml" ] && echo -e "$domain in the Tomcat already exist! \nYou can delete ${CMSG}$tomcat_install_dir/conf/vhost/$domain.xml${CEND} and re-create"
     exit
 else
     echo "domain=$domain"
@@ -179,7 +178,8 @@ if [ "$moredomainame_yn" == 'y' ]; then
             break
         fi
     done
-    Domain_alias=ServerAlias$moredomainame
+    Apache_Domain_alias=ServerAlias$moredomainame
+    Tomcat_Domain_alias=$(for D in `echo $moredomainame`; do echo "<Alias>$D</Alias>"; done)
 fi
 
 echo
@@ -196,8 +196,7 @@ echo "set permissions of Virtual Host directory......"
 chown -R ${run_user}.$run_user $vhostdir
 }
 
-Nginx_anti_hotlinking()
-{
+Nginx_anti_hotlinking() {
 while :
 do
     echo
@@ -227,8 +226,7 @@ else
 fi
 }
 
-Nginx_rewrite()
-{
+Nginx_rewrite() {
 while :
 do
     echo
@@ -259,8 +257,7 @@ else
 fi
 }
 
-Nginx_log()
-{
+Nginx_log() {
 while :
 do
     echo
@@ -279,17 +276,14 @@ else
 fi
 }
 
-Create_nginx_tomcat_conf()
-{
-[ -n "`grep $vhostdir $tomcat_install_dir/conf/server.xml`" ] && { echo -e "\n$vhostdir in the tomcat already exist! \nYou must manually modify the file=${MSG}$tomcat_install_dir/conf/server.xml${CEND}"; exit; }
-
+Create_nginx_tomcat_conf() {
 [ ! -d $web_install_dir/conf/vhost ] && mkdir $web_install_dir/conf/vhost
 cat > $web_install_dir/conf/vhost/$domain.conf << EOF
 server {
 listen 80;
 server_name $domain$moredomainame;
 $N_log
-index index.html index.htm index.jsp index.php;
+index index.html index.htm index.jsp;
 root $vhostdir;
 $anti_hotlinking
 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
@@ -304,13 +298,22 @@ $NGX_CONF
 }
 EOF
 
-sed -i "s@autoDeploy=\"true\">@autoDeploy=\"true\">\n\t<Context path=\"\" docBase=\"$vhostdir\" debug=\"0\" reloadable=\"true\" crossContext=\"true\"/>@" $tomcat_install_dir/conf/server.xml
+cat > $tomcat_install_dir/conf/vhost/$domain.xml << EOF
+<Host name="$domain" appBase="webapps" unpackWARs="true" autoDeploy="true"> $Tomcat_Domain_alias
+  <Context path="" docBase="$vhostdir" debug="0" reloadable="true" crossContext="true"/>
+  <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
+         prefix="${domain}_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
+</Host>
+EOF
+[ -z "`grep -o "${domain}-vhost SYSTEM" $tomcat_install_dir/conf/server.xml`" ] && sed -i "/localhost-vhost SYSTEM/a<\!ENTITY ${domain}-vhost SYSTEM \"file://$tomcat_install_dir/conf/vhost/$domain.xml\">" $tomcat_install_dir/conf/server.xml
+[ -z "`grep -o "${domain}-vhost;" $tomcat_install_dir/conf/server.xml`" ] && sed -i "s@localhost-vhost;@&\n      \&${domain}-vhost;@" $tomcat_install_dir/conf/server.xml
 
 echo
 $web_install_dir/sbin/nginx -t
 if [ $? == 0 ];then
-    echo "Restart Nginx......"
+    echo "Reload Nginx......"
     $web_install_dir/sbin/nginx -s reload
+    /etc/init.d/tomcat restart
 else
     rm -rf $web_install_dir/conf/vhost/$domain.conf
     echo "Create virtualhost ... [${CFAILURE}FAILED${CEND}]"
@@ -323,21 +326,21 @@ printf "
 #       For more information please visit http://oneinstack.com       #
 #######################################################################
 "
-echo "`printf "%-32s" "Your domain:"`${CMSG}$domain${CEND}"
-echo "`printf "%-32s" "Virtualhost conf:"`${CMSG}$web_install_dir/conf/vhost/$domain.conf${CEND}"
-echo "`printf "%-32s" "Directory of:"`${CMSG}$vhostdir${CEND}"
+echo "`printf "%-28s" "Your domain:"`${CMSG}$domain${CEND}"
+echo "`printf "%-28s" "Nginx Virtualhost conf:"`${CMSG}$web_install_dir/conf/vhost/$domain.conf${CEND}"
+echo "`printf "%-28s" "Tomcat Virtualhost conf:"`${CMSG}$tomcat_install_dir/conf/vhost/$domain.xml${CEND}"
+echo "`printf "%-28s" "Directory of:"`${CMSG}$vhostdir${CEND}"
 
 }
 
-Create_nginx_php-fpm_hhvm_conf()
-{
+Create_nginx_php-fpm_hhvm_conf() {
 [ ! -d $web_install_dir/conf/vhost ] && mkdir $web_install_dir/conf/vhost
 cat > $web_install_dir/conf/vhost/$domain.conf << EOF
 server {
 listen 80;
 server_name $domain$moredomainame;
 $N_log
-index index.html index.htm index.jsp index.php;
+index index.html index.htm index.php;
 include $rewrite.conf;
 root $vhostdir;
 $anti_hotlinking
@@ -356,7 +359,7 @@ EOF
 echo
 $web_install_dir/sbin/nginx -t
 if [ $? == 0 ];then
-    echo "Restart Nginx......"
+    echo "Reload Nginx......"
     $web_install_dir/sbin/nginx -s reload
 else
     rm -rf $web_install_dir/conf/vhost/$domain.conf
@@ -370,14 +373,13 @@ printf "
 #       For more information please visit http://oneinstack.com       #
 #######################################################################
 "
-echo "`printf "%-32s" "Your domain:"`${CMSG}$domain${CEND}"
-echo "`printf "%-32s" "Virtualhost conf:"`${CMSG}$web_install_dir/conf/vhost/$domain.conf${CEND}"
-echo "`printf "%-32s" "Directory of:"`${CMSG}$vhostdir${CEND}"
-[ "$rewrite_yn" == 'y' ] && echo "`printf "%-32s" "Rewrite rule:"`${CMSG}$rewrite${CEND}" 
+echo "`printf "%-20s" "Your domain:"`${CMSG}$domain${CEND}"
+echo "`printf "%-20s" "Virtualhost conf:"`${CMSG}$web_install_dir/conf/vhost/$domain.conf${CEND}"
+echo "`printf "%-20s" "Directory of:"`${CMSG}$vhostdir${CEND}"
+[ "$rewrite_yn" == 'y' ] && echo "`printf "%-20s" "Rewrite rule:"`${CMSG}$rewrite${CEND}" 
 }
 
-Apache_log()
-{
+Apache_log() {
 while :
 do
     echo
@@ -397,8 +399,7 @@ else
 fi
 }
 
-Create_apache_conf()
-{
+Create_apache_conf() {
 [ "`$apache_install_dir/bin/apachectl -v | awk -F'.' /version/'{print $2}'`" == '4' ] && R_TMP='Require all granted' || R_TMP=
 [ ! -d $apache_install_dir/conf/vhost ] && mkdir $apache_install_dir/conf/vhost
 cat > $apache_install_dir/conf/vhost/$domain.conf << EOF
@@ -406,7 +407,7 @@ cat > $apache_install_dir/conf/vhost/$domain.conf << EOF
     ServerAdmin admin@linuxeye.com 
     DocumentRoot "$vhostdir"
     ServerName $domain
-    $Domain_alias
+    $Apache_Domain_alias
     ErrorLog "$wwwlogs_dir/${domain}_error_apache.log"
     $A_log
 <Directory "$vhostdir">
@@ -438,13 +439,12 @@ printf "
 #       For more information please visit http://oneinstack.com       #
 #######################################################################
 "
-echo "`printf "%-32s" "Your domain:"`${CMSG}$domain${CEND}"
-echo "`printf "%-32s" "Virtualhost conf:"`${CMSG}$apache_install_dir/conf/vhost/$domain.conf${CEND}"
-echo "`printf "%-32s" "Directory of $domain:"`${CMSG}$vhostdir${CEND}"
+echo "`printf "%-20s" "Your domain:"`${CMSG}$domain${CEND}"
+echo "`printf "%-20s" "Virtualhost conf:"`${CMSG}$apache_install_dir/conf/vhost/$domain.conf${CEND}"
+echo "`printf "%-20s" "Directory of:"`${CMSG}$vhostdir${CEND}"
 }
 
-Create_nginx_apache_mod-php_conf()
-{
+Create_nginx_apache_mod-php_conf() {
 # Nginx/Tengine
 [ ! -d $web_install_dir/conf/vhost ] && mkdir $web_install_dir/conf/vhost
 cat > $web_install_dir/conf/vhost/$domain.conf << EOF
@@ -452,7 +452,7 @@ server {
 listen 80;
 server_name $domain$moredomainame;
 $N_log
-index index.html index.htm index.jsp index.php;
+index index.html index.htm index.php;
 root $vhostdir;
 $anti_hotlinking
 location / {
@@ -480,7 +480,7 @@ EOF
 echo
 $web_install_dir/sbin/nginx -t
 if [ $? == 0 ];then
-    echo "Restart Nginx......"
+    echo "Reload Nginx......"
     $web_install_dir/sbin/nginx -s reload
 else
     rm -rf $web_install_dir/conf/vhost/$domain.conf
@@ -495,7 +495,7 @@ cat > $apache_install_dir/conf/vhost/$domain.conf << EOF
     ServerAdmin admin@linuxeye.com
     DocumentRoot "$vhostdir"
     ServerName $domain
-    $Domain_alias
+    $Apache_Domain_alias
     ErrorLog "$wwwlogs_dir/${domain}_error_apache.log"
     $A_log
 <Directory "$vhostdir">
@@ -526,11 +526,11 @@ printf "
 #       For more information please visit http://oneinstack.com       #
 #######################################################################
 "
-echo "`printf "%-32s" "Your domain:"`${CMSG}$domain${CEND}"
-echo "`printf "%-32s" "Nginx Virtualhost conf:"`${CMSG}$web_install_dir/conf/vhost/$domain.conf${CEND}"
-echo "`printf "%-32s" "Apache Virtualhost conf:"`${CMSG}$apache_install_dir/conf/vhost/$domain.conf${CEND}"
-echo "`printf "%-32s" "Directory of:"`${CMSG}$vhostdir${CEND}"
-[ "$rewrite_yn" == 'y' ] && echo "`printf "%-32s" "Rewrite rule:"`${CMSG}$rewrite${CEND}" 
+echo "`printf "%-28s" "Your domain:"`${CMSG}$domain${CEND}"
+echo "`printf "%-28s" "Nginx Virtualhost conf:"`${CMSG}$web_install_dir/conf/vhost/$domain.conf${CEND}"
+echo "`printf "%-28s" "Apache Virtualhost conf:"`${CMSG}$apache_install_dir/conf/vhost/$domain.conf${CEND}"
+echo "`printf "%-28s" "Directory of:"`${CMSG}$vhostdir${CEND}"
+[ "$rewrite_yn" == 'y' ] && echo "`printf "%-28s" "Rewrite rule:"`${CMSG}$rewrite${CEND}" 
 }
 
 Add_Vhost() {
@@ -672,9 +672,10 @@ Del_Apache_Vhost() {
 }
 
 Del_Tomcat_Vhost() {
-    if [ -e "$tomcat_install_dir/conf/server.xml" ];then
-        Num=`grep -n "docBase=\"$Directory\"" $tomcat_install_dir/conf/server.xml | awk -F: '{print $1}'`
-        [ -n "$Num" ] && { sed -i ${Num}d $tomcat_install_dir/conf/server.xml; /etc/init.d/tomcat restart; }
+    if [ -n "`grep ${domain}-vhost $tomcat_install_dir/conf/server.xml`" ];then
+        sed -i /${domain}-vhost/d $tomcat_install_dir/conf/server.xml 
+        rm -rf $tomcat_install_dir/conf/vhost/${domain}.xml
+        /etc/init.d/tomcat restart
     fi
 }