Deploying a Django App with fabric Deploying a Django App with fabric
This article is a script implementation of my website easy-to-read Chinese network automation deployment, the following code is tested in Ubuntu and Debian
Since the Web site uses Python technology, given the power of Python, there is a powerful tool for self-deployment with fabric, read this article in addition to a little understanding, python
fabric
but also need to install Fabtools, This was installed to simplify some basic operations (an excuse for people who don't know much about Linux), which encapsulates a lot of commands. I'll write down the automatic deployment process for my site step-by-step.
The first is the fabric file in the basic configuration, to get a VPS, there will be a default root account, everyone in the deployment of the site as far as possible not to use the root account, not too safe, in case of accidental deletion of the file how to do! So first you have to create a user, preferably with sudo permissions
from Import *from import require# Create user's code users == xxx def Add_user (): require.users.user (user, password) require.users.sudoer (user)
Run the function using the following code
fab-h [Email Protected]:host add_user
This creates a user with sudo permissions, after the user has been created, the root account and password will not be used later (in addition to you want to create a new user), directly using the creation of the users can be, and then configure a role in the script, So you don't have to enter your account password for each remote operation.
Env.roledefs = { "user"" username @ip:port", = { " username @ip:port":" password " }
Once configured, the following will be used
After creating the user, install the required software
@task @roles ("User")definstall_deb (): Require.deb.packages (["Python-dev", "Python-lxml", "python-imaging", "git", "Libffi-dev", "LIBXML2", "PYTHON-LIBXSLT1", "PYTHON-LIBXML2", "Libxslt1-dev", "Libxml2-dev", "Libmysqlclient-dev", "Libjpeg-dev", "Libfreetype6-dev" ])
You see this function with two adorners, one task, each fab function, and the other is roles (' user '), with this, the command to install the software becomes
Fab install_deb
This will not need to enter the account password, reduce the time to operate the keyboard, so each function will be brought with these two adorners
Configure MySQL
def create_mysql (): require.mysql.server (password=mysql_root_pw) with settings (Mysql_user =mysql_root, mysql_password=mysql_root_pw): require.mysql.user (Mysql_user, MYSQL_PW) Require.mysql.database (mysql_db, owner=mysql_user)
The variables inside are changed to use
Write so much first! I don't want to write today, but there are some behind it. Create Python environment, git Code, build database, configure static file, configure Gunicorn,supervisor,nginx
Then the website starts to run!
Finally attach a small station easy to read Chinese network
If you feel that this article has a little effect on you, reprint the time please keep the link! Thank you.
Fabric Automation Deploys Django