Fabric automated O & M tools for remote SSH deployment and system management

Source: Internet
Author: User

Fabric automated O & M tools for remote SSH deployment and system management

Fabric is a tool that implements SSH remote Application Deployment and system management based on the python (2.5-2.7) Library and command line. It is used to manage remote hosts in batches, you do not need to enter a password for login. You can write the host user name and password in a file. The following describes the specific instance.

Fabric Installation
Yum install python-setuptools python-dev * pycrypto
Wget https://pypi.python.org/packages/source/F/Fabric/Fabric-1.10.0.tar.gz -- no-check-certificate
Tar zxvf Fabric-1.10.0.tar.gz
Cd Fabric-1.10.0
Python setup. py install

Python
>>> Import fabric # Check the installation result. If no exception is reported in the import module, the installation is successful.

Run different commands on different hosts. A simple script is as follows: (each defined function can be executed as a parameter)
#! /Usr/bin/env
Python
From fabric. colors import *
From fabric. api import *

Env. user = 'root'
Env. roledefs = {
'Proxy': ['192. 168.199.113 '],
'Media ': ['192. 168.199.118']
}
Env. password = {
'Root @ 192.168.199.113: 22': '123 ',
'Root @ 192.168.199.118: 22': '123'
}

@ Roles ('proxy ')
Def proxytask ():
Run ("df-h ")

@ Roles ('Media ')
Def mediatask ():
Run ("free-m ")

# @ Roles ('Media ', 'proxy ')
Def run ():
Execute (proxytask)
Execute (mediatask)

 

Fab-f fabtest. py run
Fab-f fabtest. py mediatask
Fab-f fabtest. py proxytask # Compare the results of these three executions.

Remote File push script:

#! /Usr/bin/env python
# File tar upload check
From fabric. api import *
From fabric. context_managers import *
From fabric. contrib. console import confirm

Env. user = 'root'
Env. hosts = ['192. 168.199.118 ']
Env. passwords = {
'Root @ 192.168.199.118: 22': '123'
}


@ Task
Def put_task (): # upload file task
Run ("mkdir-p/root/test ")
With cd ("/root/test ")
With settings (warn_only = True): # when upload error, continue
Result = put ("/etc", "/root/test ")
If result. failed and not confirm ("put file failed, Continue [Y/N]? "):
About ("Aborting file put task! ")

SSH password-free login configuration in CentOS 6.0

How to Improve the SSH login authentication speed of Ubuntu

Enable the SSH service to allow Android phones to remotely access Ubuntu 14.04

How to add dual authentication for SSH in Linux

Configure the SFTP environment for non-SSH users in Linux

Configure and manage the SSH service on Linux

Basic SSH tutorial

This article permanently updates the link address:

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.