kghjtyhyt 发表于 2015-9-2 08:46:35

apache自动更新站点内容脚本

实现思路:
通过软链接的方式更改网站目录对应的站点目录
准备工作:

[*]先将网站内容的两个版本上传到服务器上面,存放路径为/server/www


1
2
3
4
# ll
总用量 8
-rw-r--r-- 1 root root 167 9月   1 12:54 html1.1.tar.gz
-rw-r--r-- 1 root root 166 9月   1 12:57 html1.2.tar.gz





[*]配置Apache虚拟主机,网站访问路径为/alidata/xx/webapps/xx


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# tail -15 /usr/local/apache2/conf/extra/httpd-vhosts.conf
………
<VirtualHost *:80>
    ServerAdmin admin@dyb.com
    DocumentRoot/alidata/xx/webapps/xx
    <Directory"/alidata/xx/webapps/xx">
      Options IndexesFollowSymLinks
      AllowOverride None
      Order allow,deny
      Allow from all
    </Directory>
    ServerName xx.dyb.com
    DirectoryIndex index.htmlindex.htm index.jsp
    ErrorLoglogs/uh.dyb.com_error_log
    CustomLoglogs/uh.dyb.com_access_log common
</VirtualHost>




实现脚本:
通过脚本实现自动更新站点内容(脚本需要加网站版本号参数即可)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# cat change_html.sh
#!/bin/bash
#this script create at 2015-09-01
#author:hao123
#this script is use to change html version

#版本存放目录
html_ver_dir=/server/www
#web访问目录
html_acc_dir=/alidata/xx/webapps

         if [ $# -ne 1 ];then
                   echo"you need add html version id,like 1.1"
         else
                   num=`find $html_ver_dir -type f -name "html$1.tar.gz"|wc -l`
                   if [ $num-eq 1 ];then
                            cd $html_ver_dir
                            find $html_ver_dir -type d ! -name "html$1" -a ! -name"www"|xargs rm -rf
                            tar zxf html$1.tar.gz
                            cd $html_acc_dir
                            rm -f xx
                            ln -s $html_ver_dir/html$1 xx
                   else
                            echo"Don't find the html version"
                   fi
         fi





结果展示:

1
2
3
4
5
6
# sh change_html.sh 1.2
# ll /server/www/
总用量 12
-rw-r--r-- 1 root root167 9月   1 13:55 html1.1.tar.gz
drwxr-xr-x 2 root root 4096 9月   1 13:54 html1.2
-rw-r--r-- 1 root root167 9月   1 13:55 html1.2.tar.gz





1
2
3
4
5
6
# sh change_html.sh 1.1
# ll /server/www/
总用量 12
drwxr-xr-x 2 root root 4096 9月   1 13:54 html1.1
-rw-r--r-- 1 root root167 9月   1 13:55 html1.1.tar.gz
-rw-r--r-- 1 root root167 9月   1 13:55 html1.2.tar.gz





问题说明:

[*]如果使用软链接访问网站报错,可参考http://www.iyunv.com/thread-108550-1-1.html解决

[*]后期可以和svn配合,开发将网站代表打包传到svn上,然后通过脚本实现自动更新网站版本



页: [1]
查看完整版本: apache自动更新站点内容脚本