说明:
本地不需要登录服务器只需要一条命令即可管理远程服务器站点,管理项目包括:添加apache站点(含ftp、mysql)、停用站点、恢复站点、删除站点、查看用户配额、查看域名whois信息、查找站点绝对路径。
用法:
SiteRemoteManagerTool by upall.cn Ver20121107 用法: st option xxxx.xx 参数: site: 添加一个apache站点(含复制代码、FTP、MySQL) psite: 添加一个反向代理站点(用于免备案) remove: 删除一个由site参数创建的站点 stop: 停止一个站点 resume: 恢复由stop参数暂停的站点 find: 查找站点的DocumentRoot quota: 查看站点的磁盘配额 whois: 查看域名whois信息 例子(查找域名为upall.cn的网站的DocumentRoot): st find upall.cn
示例
Microsoft Windows [版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。 C:\Users\upall>st --> 查看帮助 SiteRemoteManagerTool by upall.cn Ver20121107 Usage: st option xxxx.xx Options: site: build webSite (include ftp, codes and database) psite: create ReverseProxyConf remove: Danger! remove webSite (include ftp, codes and database) stop: stop site, esite resume: resume site, esite find: search site path owner: view Code owner quota: show disk quotas and usage whois: show whois For example: st find upall.cn C:\Users\upall>st site itisademo.cn --> 添加一个站点 quota://204800bytes ftp://itisademo_cn:kp3WXpKRExcFhN@8.8.8.8:21/ mysql://itisademo_cn:3AzV1hS1IyRXhj@localhost:3306/itisademo_cn/ http://itisademo.cn.demo.upall.cn/ C:\Users\upall>st psite itisademo.cn --> 添加一个反向代理站点 Tip: Add ReverseProxySite successfully! C:\Users\upall>st stop itisademo.cn --> 停止一个网站 Stop operation is complete. C:\Users\upall>st resume itisademo.cn --> 恢复停止的网站 Resume operation is complete. C:\Users\upall>st find itisademo.cn --> 查找网站的DocumentRoot(有多种类型时候需要这个功能) DocumentRoot "/var/www/vhost/itisademo.cn" C:\Users\upall>st owner itisademo.cn --> 查找网站的运行用户 drwx------ 16 itisademo_cn webusers 4096 2012-01-13 www.itisademo.cn C:\Users\upall>st quota itisademo.cn --> 查看磁盘配额(含使用情况) itisademo_cn -- 4384 194560 204800 668 0 0 C:\Users\upall>st remove itisademo.cn --> 删除站点 Remove operation is complete. C:\Users\upall>st whois itisademo.cn --> 查看域名whois信息 Whois v1.01 - Domain information lookup utility Sysinternals - www.sysinternals.com Copyright (C) 2005 Mark Russinovich Connecting to CN.whois-servers.net... no matching record. C:\Users\upall>
文件列表:
本地:
a、st.bat
服务器:
1、addsite.sh(添加apache站点、FTP、MySQL、复制代码)
2、addpsite.sh(添加一个反向代理站点)
3、removesite.sh(移除由addsite.sh添加的站点及相关信息)
4、stopsite.sh(停止由addsite.sh添加的站点)
5、resumesite.sh(恢复运行由addsite.sh添加的站点)
6、findsite.sh(查找由addsite.sh添加的站点的站点根目录,即DocumentRoot)
7、quotasite.sh(查看站点的配额配额)
8、ownersite.sh(查看站点的运行身份)
代码:
:: 配置 @echo off setlocal set user=sshRuser set pwd=sshPwd set host=1.2.3.4 set port=2222 :: 选项 if "%2"=="" goto help if "%1"=="" goto help if "%1"=="site" goto site if "%1"=="psite" goto psite if "%1"=="stop" goto stop if "%1"=="resume" goto resume if "%1"=="remove" goto remove if "%1"=="quota" goto quota if "%1"=="whois" goto whois if "%1"=="find" goto find goto help :: 网站 :site plink.exe -pw %pwd% %user%@%host% -P %port% addsite.sh %2 goto end :: 反向代理 :psite plink.exe -pw %pwd% %user%@%host% -P %port% addpsite.sh %2 goto end :: 通过配置文件查找代码位置 :find plink.exe -pw %pwd% %user%@%host% -P %port% findsite.sh %2 goto end :: whois :whois whois.exe %2 goto end :remove plink.exe -pw %pwd% %user%@%host% -P %port% removesite.sh %2 goto end :quota plink.exe -pw %pwd% %user%@%host% -P %port% quotasite.sh %2 goto end :stop plink.exe -pw %pwd% %user%@%host% -P %port% stopsite.sh %2 goto end :resume plink.exe -pw %pwd% %user%@%host% -P %port% resumesite.sh %2 goto end :: 帮助 :help echo SiteRemoteManagerTool by upall.cn Ver20121107 echo Usage: %0 option xxxx.xx echo Options: echo site: build webSite (include ftp, codes and database) echo psite: create ReverseProxyConf echo remove: Danger! remove webSite (include ftp, codes and database) echo stop: stop site, esite echo resume: resume site, esite echo find: search site path echo owner: view Code owner echo quota: show disk quotas and usage echo whois: show whois echo For example: goto end :: 结束 :end endlocal
#!/bin/bash # 变量配置 HTTPD_CONF="/etc/httpd/conf/vhosts.conf" # 生成apache虚拟主机配置文件 echo "">> $HTTPD_CONF echo " ServerName www.$1">> $HTTPD_CONF echo " ServerAlias $1">> $HTTPD_CONF echo " ProxyRequests Off">> $HTTPD_CONF echo " ">> $HTTPD_CONF echo " Order deny,allow">> $HTTPD_CONF echo " Allow from all">> $HTTPD_CONF echo " ">> $HTTPD_CONF echo " ProxyPass / http://$1.demo.upall.cn/">> $HTTPD_CONF echo " ProxyPassReverse / http://$1.demo.upall.cn/">> $HTTPD_CONF echo "">> $HTTPD_CONF echo " Tip: Add ReverseProxySite successfully!" #echo "">> $HTTPD_CONF #echo " ServerName www.$1">> $HTTPD_CONF #echo " ServerAlias $1">> $HTTPD_CONF #echo " Redirect / http://$1.demo.upall.cn/">> $HTTPD_CONF #echo "">> $HTTPD_CONF # 重启httpd、vsftpd service httpd graceful
#!/bin/bash # 显示帮助 if [ -z "$1" ]; then echo " This tool use to remove a website, It will remove database, codes and .conf." echo " Tip: please manaual remove record in FTP chrootlist file." echo " Usage: `basename $0` domainName" echo " e.g. `basename $0` upall.cn" exit fi # 变量配置 HTTPD_CONF="/etc/httpd/vhost/"$1".conf" HTTPD_USER=${1//./_} HTTPD_USER=${HTTPD_USER//-/_} MYSQL_DB_USER="root" MYSQL_DB_PWD="root's password" # 删除用户 userdel -r $HTTPD_USER if [ $? -ne 0 ]; then #echo "user "$HTTPD_USER" delete failed." exit fi # 删除 apache 配置文件 rm -f $HTTPD_CONF # 删除 mysql 数据库及用户 SQL="DROP USER '$HTTPD_USER'@'localhost';" echo "$SQL" | mysql -u$MYSQL_DB_USER -p$MYSQL_DB_PWD -hlocalhost SQL="DROP DATABASE IF EXISTS $HTTPD_USER;" echo "$SQL"| mysql -u$MYSQL_DB_USER -p$MYSQL_DB_PWD -hlocalhost # 重启httpd、vsftpd service httpd graceful echo " Operation is complete." #END#
#!/bin/bash # 显示帮助 if [ -z "$1" ]; then echo " Stop a website." echo " Usage: `basename $0` domainName" echo " e.g. `basename $0` upall.cn" exit fi # 变量配置 HTTPD_CONF_PRE="/etc/httpd" TYPE="" # 修改配置 mv $HTTPD_CONF_PRE"/vhost/"$1".conf" $HTTPD_CONF_PRE"/vhost/"$1".conf.stop" # 重启httpd、vsftpd service httpd graceful echo " Stop operation is complete." #END#
#!/bin/bash # 显示帮助 if [ -z "$1" ]; then echo " Stop a website." echo " Usage: `basename $0` domainName" echo " e.g. `basename $0` upall.cn" exit fi # 变量配置 HTTPD_CONF_PRE="/etc/httpd" # 修改配置 mv $HTTPD_CONF_PRE"/vhost/"$1".conf.stop" $HTTPD_CONF_PRE"/vhost/"$1".conf" # 重启httpd、vsftpd service httpd graceful echo " Resume operation is complete." #END#
#!/bin/bash # 显示帮助 if [ -z "$1" ]; then echo " Stop a website." echo " Usage: `basename $0` domainName" echo " e.g. `basename $0` upall.cn" exit fi find /etc/httpd/ -name '*.conf' | xargs grep -Eh "DocumentRoot(.*)$1" | sed 's/^[[:space:]]*//' #END#
#!/bin/bash # 显示帮助 if [ -z "$1" ]; then echo " Stop a website." echo " Usage: `basename $0` domainName" echo " e.g. `basename $0` upall.cn" exit fi # 变量配置 HTTPD_USER=${1//./_} HTTPD_USER=${HTTPD_USER//-/_} # 显示配额 repquota -a | grep $HTTPD_USER #END#
#!/bin/bash # 查看目录的运行身份 # 显示帮助 if [ -z "$1" ]; then echo " Usage: `basename $0` domainName" echo " e.g. `basename $0` upall.cn" exit fi # 变量配置 FOLDER_PRE="/var/www" # 修改配置 if [ -d $FOLDER_PRE"/WebSite/"$1 ]; then #echo "Folder:"$FOLDER_PRE"/WebSite/"$1 ls -l $FOLDER_PRE"/WebSite/"$1 else echo " Can't found DocumentRoot: "$1 exit fi #END
<完>