The birth of a website 10--automated deployment

Source: Internet
Author: User

The so-called automatic deployment means that if you run a tornado program with 10 machines to provide Web services, the code above is the same, which is also called a production environment. Write new code in company, write well, test pass, this is called development environment. Then execute the automatic deployment program, it submits the new code to the version Management Server, then connected to the production environment's 10 servers, lets them update the code, then restarts the Tornado program, the new code is on-line, the user sees is the newly published website.

the key to automatic deployment is two things, one version server and one remote operation.

recommended git version server, recommended Liao Xuefeng git tutorial, write very clear, is so far I see the easiest to start, link herehttp://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000.

remote operation with Python fabric is recommended,http://www.fabfile.org/.

To automate deployment, the first step is to create a git version server with a public IP, so that 10 Web servers can access the GIT server. Then commit the code to the GIT version server in the development environment. This process please refer to Liao's tutorial, here will not repeat.

in the second step, SSH logs into any Web server, executes the command manually, updates the code from the GIT server, and then opens the Tornado program, noting all the steps in the process.

third, using fabric to write the steps of the second step, fill in 10 Web server IP address, in the future you can update 10 machines at once.

Zuijiacanting.com's automated deployment script is similar to the following, remote_deploy.py:

#!/usr/bin/env python
#!-*-coding:utf-8-*-

From __future__ import with_statement
Import OS
From fabric.api Import *

#ip of Web server
env.hosts=[' 106.111.111.111 ']

def commit_to_remote ():
d = Os.path.abspath ("Xx/yy")
local ("CD%s;git push Origin master"% d)

def deploy_zjct ():
code_dir= "/home/xxx/yyy"
With CD (code_dir):
run ("sudo git pull Origin master")
run ("sudo reboot")
in the development environment, if the new code is ready, execute the command "fab-f remote_deploy.py commit_to_remote", commit the new code to the GIT version server, and then execute the "Fab-f remote_deploy.py Deploy_zjct ", fabric logs on to the Web server in SSH, updates the code, and then restarts. Reboot to run the new code. Do not restart, kill the tornado process, automatic monitoring will restart the tornado process, restart is also run new code. If you want to update more than one machine, add the IP address to the env.hosts.

fabric can do a lot of things, not just the above so simple, you can achieve a variety of cool special effects.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.