In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to remotely deploy Fabric and support Python3", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to remotely deploy Fabric and support Python3" this article.
Install Fabric$ pip install fabric-- upgrade
Note that if you install the old version of Fabric, then the new version of Fabric is not compatible with the old version, there are currently three versions of Fabric, Fabric1 is the previous Fabric, only support Python2, is not recommended, and Fabric2 is now Fabric, while supporting Python2 and Python3, is also the official highly recommended version, and there is a Fabric3, which is an unofficial version cloned from the old version of Fabric1 by netizens, but it is compatible with Fabric1 and also supports Python2 and Python3.
The latest Fabric does not require fabfile.py files or fab commands, and now almost all tutorials and materials on the network are based on fabric1. When you are reading those tutorials, pay attention to discrimination. The API provided by the new version of Fabric is very simple.
Run command
Let's look at an example. Here's a deployment script.
# deploy.py
# 1. Create a remote connection
# 2. Enter the specified directory
# 3. Execute the restart command under the specified directory
From fabric import Connection
Def main ():
# ip, I filled it out casually.
# if your computer is equipped with ssh password-free login, you don't need connect_kwargs to specify the password.
C = Connection ("root@232.231.231.22", connect_kwargs= {"password": "youpassword"})
With c.cd ('/ var/www/youproject'):
C.run ("git pull origin master")
C.run ("/ usr/bin/supervisorctl-c.. / supervisor/supervisord.conf restart youproject")
If _ _ name__ = ='_ _ main__':
Main ()
Execution
Python deploy.py
After the execution, the latest code has been deployed to the formal environment and restarted the service, is it very convenient, mother no longer worry that I typed the wrong command in the formal environment to delete the database to run away.
Fabric not only supports Linux, but also runs well on the Windows platform. It is a very good operation and maintenance tool for small and medium-sized projects. With Frabic, it is not a problem to manage hundreds of servers.
Build a connection class Connection (Context):
Host = None
User = None
Port = None
Ssh_config = None
Connect_timeout = None
Connect_kwargs = None
...
There are different ways to build Connection objects. For example, you can write host as "root@192.168.101.1:22", or you can write it separately as three parameters. Connect_kwargs is a dictionary object, which usually fills in the login password or key of the server.
Upload files
The run method is used to execute commands, cd is used to enter the specified directory, and the put method is used to upload files, for example:
From fabric import Connection
C = Connection ('web1')
C.put ('myfiles.tgz',' / opt/mydata')
C.run ('tar-C / opt/mydata-xzvf / opt/mydata/myfiles.tgz') multiple servers
If you want to run commands on multiple servers, the simple way is to use iterations to execute commands one server at a time:
# web1,web2,mac1 is the name of the server, you can also use ip instead
> from fabric import Connection
> for host in ('web1',' web2', 'mac1'):
> result = Connection (host) .run ('uname-s')
... Print ("{}: {}" .format (host, result.stdout.strip ()
...
Web1: Linux
Web2: Linux
Mac1: Darwin
Or use SerialGroup
From fabric import SerialGroup as Group
Pool = Group ('web1',' web2', 'web3', connect_kwargs= {"password": "youpassword"})
Pool.put ('myfiles.tgz',' / opt/mydata')
Pool.run ('tar-C / opt/mydata-xzvf / opt/mydata/myfiles.tgz')
Parameter description of Group (* hosts, * * kwargs):
* hosts: multiple hostnames or IP can be passed in
* * kwargs can receive the same parameters as Connection, and you can specify a password
The above is all the contents of the article "how to deploy Fabric remotely and support Python3". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.