快速搭建內網測試網絡,簡單模擬WEB集羣

svn項目

模擬WEB集羣

後端WEB集羣192.168.1.231:8080和192.168.1.232:8080.WEB後端能夠按照須要增長,不一樣目錄啓動不一樣端口,經過使用192.168.1.231:80做爲負載均衡訪問.git

upstream  www.front.com
{
    server   192.168.1.232:8080;
    server   192.168.1.231:8080;
}

server
{
    listen  80;
    server_name  192.168.1.231;

    location / {
        proxy_pass        http://www.front.com;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}
SVN自動發佈

使用SVN提交時,註釋中輸入"auto_deploy",自動發佈到231,232的項目測試服務器.svn鉤子文件post-commitweb

#!/bin/bash

REPOS="$1"
REV="$2"
if ( svnlook log -r $REV /data/www/svn/gtl/ |grep "auto_deploy" )
then

    echo "`date` auto_deploy">> /tmp/testsvn.log
#front1
    ssh root@192.168.1.231 'svn revert -R /data/wwwroot/gtl --username "sylar" --password "gtl1023"'
    ssh root@192.168.1.231 'svn update /data/wwwroot/gtl/ --username "sylar" --password "gtl1023"'
    ssh root@192.168.1.231 'chown www.www -R /data/wwwroot/gtl'

#front2
    ssh root@192.168.1.232 'svn revert -R /data/wwwroot/gtl --username "sylar" --password "gtl1023"'
    ssh root@192.168.1.232 'svn update /data/wwwroot/gtl/ --username "sylar" --password "gtl1023"'
    ssh root@192.168.1.232 'chown www.www -R /data/wwwroot/gtl'

#admin
    ssh root@192.168.1.232 'svn revert -R /data/wwwroot/admin/ --username "sylar" --password "gtl1023"'
    ssh root@192.168.1.232 'svn update /data/wwwroot/admin/ --username "sylar" --password "gtl1023"'
    ssh root@192.168.1.232 'chown www.www -R /data/wwwroot/admin'


#API
    ssh root@192.168.1.235 'svn revert -R /data/wwwroot/api/ --username "sylar" --password "gtl1023"'
    ssh root@192.168.1.235 'svn update /data/wwwroot/api/ --username "sylar" --password "gtl1023"'
    ssh root@192.168.1.235 'chown www.www -R /data/wwwroot/api'
fi
另一個SVN鉤子,強制SVN提交時輸入註釋
#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c)
if [ "$LOGMSG" -lt 10 ]; then
echo -e "\n 提交文件時必須添加註釋,提交停止."1>&2
exit 1
fi

git項目

GIT鉤子post-receive

代碼服務器的git用戶須要對目標機器作ssh密鑰受權,而且保證可以以目標機器的sudo用戶登陸後端

#!/bin/sh

IS_BARE=$(git rev-parse --is-bare-repository)
if [ -z "$IS_BARE" ]; then
echo >&2 "fatal: post-receive: IS_NOT_BARE"
exit 1
fi

unset GIT_DIR

echo "==============================================="

ssh gtl@xxx.xxx.xxx.xxx '/bin/bash /home/project/local.sh'
ssh gtl@xxx.xxx.xxx.xxx '/bin/bash /home/project/local.sh'
ssh gtl@xxx.xxx.xxx.xxx '/bin/bash /home/project/local.sh'

echo "====================done======================="
目標機local.sh

目標機器須要首先克隆倉庫到本地/data/source_code/. /data/backup/settings.py爲項目的配置文件,先備份再cp,而後重啓項目.目標機器的git須要cp,chown權限api

#!/bin/bash
cd /data/source_code/
sudo git pull
sudo cp /data/wwwroot/project/bcdemo/settings.py /data/backup/settings.py -f
sudo cp /data/source_code/* /data/wwwroot/project/ -a
sudo cp /data/backup/settings.py /data/wwwroot/project/bcdemo/settings.py -f
sudo chown www.www /data/wwwroot/project/ -R
sudo systemctl stop demo
sudo systemctl restart demo
sudo echo "update done,`date -d today +"%Y-%m-%d %T"`" >> /home/project/test.txt
相關文章
相關標籤/搜索