Application of fab modules in Python

Source: Internet
Author: User
Tags i18n openssl install redis yum repolist

Cases:
Import Getpass
Import OS

From collections Import Ordereddict
From FABRIC.API Import *

def HelloWorld ():
Print "helloworld!"

def hello (name, age):
print "Hello!" I am%s, my age=%s "% (name, age)

def ls ():
Local ("Ls/usr/local")
Output = local (' Echo hello ', capture=true)
Print output

Def setroles ():
Env.roledefs = {
' Hadoop1 ': [' [email protected] ',
' Hadoop2 ': [' [email protected] ',
' HADOOP3 ': [' [email protected] ',
' HADOOP4 ': [' [email protected] ']
}
Env.passwords = {
' [Email protected]:22 ': ' A8285310 ',
' [Email protected]:22 ': ' A8285310 ',
' [Email protected]:22 ': ' A2885310 ',
' [Email protected]:22 ': ' A8285310 '
}

@roles (' Hadoop2 ')
Def setbaseenv ():

HADOOP1 = str (env.roledefs["HADOOP1"]). Split (' @ ', 1) [1]
HADOOP2 = str (env.roledefs["HADOOP2"]). Split (' @ ', 1) [1]
HADOOP3 = str (env.roledefs["HADOOP3"]). Split (' @ ', 1) [1]
HADOOP4 = str (env.roledefs["HADOOP4"]). Split (' @ ', 1) [1]
#set etc hosts
With CD (' etc '):
Run (' echo-e ' {0} hadoop1.cbas\n{1} hadoop2.cbas\n{2} hadoop3.cbas\n{3} Hadoop4.cbas ">> hosts". Format ( Hadoop1.split ("'", 1) [0], Hadoop2.split ("'", 1) [0], Hadoop3.split ("'", 1) [0], Hadoop4.split ("'", 1) [0]))
Run ("Cat hosts")
Run ("Echo----------------------------------------------------------------------------------------------------- ------")

#set language
Run ("Echo Lang=en_us. UTF-8 >/etc/sysconfig/i18n ")
Run ("source/etc/sysconfig/i18n")
Run ("Echo $LANG")
Run ("Echo----------------------------------------------------------------------------------------------------- ------")

#close the iptables and SELinux forever
Run ("Chkconfig iptables off")
Run ("Chkconfig--list iptables")
Run ("Sed-i ' s/enforcing/disabled/g '/etc/selinux/config")
Run ("Cat/etc/selinux/config")
Run ("Echo----------------------------------------------------------------------------------------------------- ------")

#set localtime
Run ("\cp/usr/share/zoneinfo/asia/shanghai/etc/localtime")
Run ("Cat/etc/localtime")
Run ("Echo----------------------------------------------------------------------------------------------------- ------")

#set file Limit
Run (' echo-e ' * soft nofile 65536\n* hard nofile 65536 ">>/etc/security/limits.conf ')
Run ("cat/etc/security/limits.conf")
Run ("Sed-i '/1024/s/^/#/'/etc/security/limits.d/90-nproc.conf")
Run ("Echo----------------------------------------------------------------------------------------------------- ------")

#set ntpd and httpd start with the system
Run ("Chkconfig ntpd on")
Run ("Chkconfig httpd on")
Run ("Chkconfig--list ntpd")
Run ("Chkconfig--list httpd")
Run ("Echo----------------------------------------------------------------------------------------------------- ------")

#mkdir
Run ("Mkdir-p/data/apps")
Run (' Mkdir-p/software ')
Run ("Echo----------------------------------------------------------------------------------------------------- ------")

#move CentOS Repo
Run ("Mv/etc/yum.repos.d/*.repo/etc")
Run ("Echo----------------------------------------------------------------------------------------------------- ------")

#reboot
Run ("reboot")

@roles (' Hadoop1 ')
Def Installbasepak ():

#check SELinux
Run ("/usr/sbin/sestatus-v")

#close THP
Run ("Echo Never >/sys/kernel/mm/redhat_transparent_hugepage/defrag")
Run ("Echo Never >/sys/kernel/mm/redhat_transparent_hugepage/enabled")
Run ("Echo Never >/sys/kernel/mm/transparent_hugepage/defrag")
Run ("Echo Never >/sys/kernel/mm/transparent_hugepage/enabled")
Run ("Echo----------------------------------------------------------------------------------------------------- ------")

With CD ('/software '):
Run (' Unzip Basepackage.zip ')
#install Base Package
Run ("Rpm-uvh nc-1.84-24.el6.x86_64.rpm")
Run ("Rpm-uvh snappy-1.1.0-1.el6.x86_64.rpm")
Run ("Rpm-uvh snappy-devel-1.1.0-1.el6.x86_64.rpm")
Run ("Rpm-uvh mpfr-2.4.1-6.el6.x86_64.rpm")
Run ("Rpm-uvh ppl-0.10.2-11.el6.x86_64.rpm")
Run ("Rpm-uvh cloog-ppl-0.15.7-1.2.el6.x86_64.rpm")
Run ("Rpm-uvh cpp-4.4.7-18.el6.x86_64.rpm")
Run ("Rpm-uvh gcc-4.4.7-18.el6.x86_64.rpm")
Run ("Rpm-uvh libstdc++-devel-4.4.7-18.el6.x86_64.rpm")
Run ("Rpm-uvh gcc-c++-4.4.7-18.el6.x86_64.rpm")
Run ("Rpm-uvh zlib-devel-1.2.3-29.el6.x86_64.rpm")
Run ("Rpm-uvh python-devel-2.6.6-66.el6_8.x86_64.rpm")
Run ("Rpm-uvh perl-5.10.1-144.el6.x86_64.rpm")
Run ("Rpm-uvh perl-dbi-1.609-4.el6.x86_64.rpm")
Run ("Rpm-uvh perl-dbd-mysql-4.013-3.el6.x86_64.rpm")
Run ("Rpm-uvh mysql-5.1.73-8.el6_8.x86_64.rpm")
Run ("Rpm-uvh mysql-server-5.1.73-8.el6_8.x86_64.rpm")
Run ("Echo----------------------------------------------------------------------------------------------------- ------")

@roles (' Hadoop1 ')
Def Sendpak ():
With CD ('/software '):
Run (' SCP basepackage.zip mysql.zip redis.zip [email protected]:/software ')
Run (' SCP basepackage.zip redis.zip nginx.zip [email protected]:/software ')
Run (' SCP basepackage.zip redis.zip nginx.zip ruby.zip ftp.zip hue.tar [email protected]:/software ')

@roles (' Hadoop2 ')
def test ():
With CD ('/software/ruby-2.4.1/ext/openssl '):
Run (' Ruby extconf.rb--with-openssl-include=/software/openssl1f/include--with-openssl-lib=/software/openssl1f/ Lib ')
Run (' Rm-rf Makefile ')
Run (' Cp/software/makefile_openssl/software/ruby-2.4.1/ext/openssl/makefile ')
Run (' Make ')
Run (' Make install ')
With CD ('/software '):
Run (' Gem install Redis-4.0.1.gem ')
Run (' Gem list ')
@roles (' Hadoop1 ')
Def buildhdpmirrorcenter ():
With CD ('/software '):
Run (' tar-xf Ambari-2.4.1.0.tar ')
Run (' tar-xf Hdp-2.5.0.0.tar ')
Run (' tar-xf Hdp-utils-1.1.0.21.tar ')
Run (' \CP ambari-2.4.1.0/centos6/2.4.1.0-22/ambari.repo/etc/yum.repos.d ')
Run (' \CP hdp/centos6/hdp.repo/etc/yum.repos.d ')
Run (' Ln-s/software/ambari-2.4.1.0/var/www/html/ambari-2.4.1.0 ')
Run (' Ln-s/SOFTWARE/HDP/VAR/WWW/HTML/HDP ')
Run (' Ln-s/software/hdp-utils-1.1.0.21/var/www/html/hdp-utils-1.1.0.21 ')
Run (' Service httpd restart ')
Run (' Yum clean All ')
Run (' Yum Makecache ')
Run (' Yum repolist ')
Run (' Curl Http://hadoop1.cbas/HDP ')
Run (' Curl http://hadoop1.cbas/HDP-UTILS-1.1.0.21 ')
Run (' Curl http://hadoop1.cbas/AMBARI-2.4.1.0 ')

@roles (' Hadoop1 ')
Def deployambariserver ():
Run (' Yum install-y ambari-server ')

@roles (' HADOOP4 ')
Def Deployhue ():
With CD ('/software '):
Run (' Mkdir/hue ')
Run (' MV Hue.tar/hue ')
Run (' Groupadd hue ')
Run (' useradd-g hue Hue ')
With CD ('/hue '):
Run (' tar-xf Hue.tar ')
Run (' Chown hue:hue/hue-r ')

@roles (' Hadoop1 ', ' hadoop2 ')
Def deployjdk ():
With CD ('/software '):
Run (' tar-xf jdk-8u144-linux-x64.tar.gz ')
Run (' MV jdk1.8.0_144 jdk1.8 ')
With CD (' etc '):
Run (' Echo-e ' java_home=/software/jdk1.8\nclasspath=.:/ Software/jdk1.8/lib:/software/jdk1.8/jre/lib\npath=/software/jdk1.8/bin: $PATH:/software/jdk1.8/jre/bin\nexport Java_home CLASSPATH PATH ">> profile")
Run (' Source profile ')
Run (' java-version ')

@roles (' Hadoop1 ', ' hadoop2 ')
Def Deploynginx ():
With CD ('/software '):
Run (' Service httpd stop ')
Run (' Chkconfig httpd off ')
Run (' Unzip Nginx.zip ')
Run (' tar-xf nginx-1.8.1.tar.gz ')
Run (' tar-xf openssl-1.0.2j.tar.gz ')
Run (' tar-xf pcre-8.21.tar.gz ')
Run (' tar-xf zlib-1.2.7.tar.gz ')
Run (' Unzip Nginx-http-concat-master.zip ')
Run (' Unzip Nginx_upstream_check_module-master.zip ')
With CD ('/software/nginx-1.8.1 '):
Run ('./configure--prefix=/software/nginx--with-pcre=/software/pcre-8.21--with-zlib=/software/zlib-1.2.7-- Add-module=/software/nginx-http-concat-master--add-module=/software/nginx_upstream_check_module-master-- With-http_ssl_module--with-openssl=/software/openssl-1.0.2j--with-http_realip_module ')
Run (' Make ')
Run (' Make install ')
Run ('/software/nginx/sbin/nginx-t ')
Run ('/software/nginx/sbin/nginx ')

@roles (' Hadoop1 ', ' hadoop2 ')
Def Deployredis ():
With CD ('/software '):
Run (' Unzip Redis.zip ')
Run (' tar-xf redis-3.2.8.tar.gz ')
With CD ('/software/redis-3.2.8 '):
Run (' Make ')
Run (' Make install Prefix=/software/redis ')
Run (' Mkdir/software/redis-cluster ')
Run (' mkdir/software/redis-cluster/redis6371 ')
Run (' mkdir/software/redis-cluster/redis6372 ')
Run (' cp/software/redis/bin/*/software/redis-cluster/redis6371 ')
Run (' cp/software/redis/bin/*/software/redis-cluster/redis6372 ')
Run (' cp/software/redis6371.conf/software/redis-cluster/redis6371 ')
Run (' cp/software/redis6372.conf/software/redis-cluster/redis6372 ')
Run (' Cp/software/redis-3.2.8/src/redis-trib.rb/software/redis-cluster ')
Run ('/software/redis-cluster/redis6371/redis-server/software/redis-cluster/redis6371/redis6371.conf ')
Run ('/software/redis-cluster/redis6372/redis-server/software/redis-cluster/redis6372/redis6372.conf ')
Run (' NETSTAT-NTLP | grep redis ')

@roles (' Hadoop2 ')
Def Deployruby ():
With CD ('/software '):
Run (' mkdir Ruby ')
Run (' Unzip Ruby.zip ')
Run (' tar-xf ruby-2.4.1.tar.gz ')
Run (' tar-xf openssl-1.0.1f.tar.gz ')
With CD ('/software/ruby-2.4.1 '):
Run ('./configure--prefix=/software/ruby ')
Run (' Make ')
Run (' Make install ')
Run (' Ln-s/software/ruby/bin/ruby/usr/bin/ruby ')
Run (' Ln-s/software/ruby/bin/gem/usr/bin/gem ')
With CD ('/software/openssl-1.0.1f '):
Run ('./config-fpic--prefix=/software/openssl1f enable-shared ')
Run ('./config-t ')
Run (' Make depend ')
Run (' Make install ')
With CD ('/software/ruby-2.4.1/ext/zlib '):
Run (' Ruby Extconf.rb ')
Run ("Sed-i ' 16a Top_srcdir =/software/ruby-2.4.1 ' Makefile")
Run (' Make ')
Run (' Make install ')
With CD ('/software/ruby-2.4.1/ext/openssl '):
Run (' Ruby extconf.rb--with-openssl-include=/software/openssl1f/include--with-openssl-lib=/software/openssl1f/ Lib ')
Run ("Sed-i ' 16a Top_srcdir =/software/ruby-2.4.1 ' Makefile")
Run (' Make ')
Run (' Make install ')
With CD ('/software '):
Run (' Gem install Redis-4.0.1.gem ')
Run (' Gem list ')
With CD ('/software/redis-cluster '):
Run ('./REDIS-TRIB.RB Create--replicas 1 hadoop2.cbas:6371 hadoop2.cbas:6372 hadoop3.cbas:6371 hadoop3.cbas:6372 hadoop4.cbas:6371 hadoop4.cbas:6372 ')

@roles (' HADOOP4 ')
Def deployftp ():
With CD ('/software '):
Run (' Unzip Ftp.zip ')
Run (' Rpm-ivh vsftpd-2.2.2-24.el6.x86_64.rpm ')
Run (' Rpm-ivh easy-rsa-3.0.3-1.el6.noarch.rpm ')
Run (' Mkdir-p/ftp ')
Run (' useradd-m-d/ftp-s/sbin/nologin ftptest ')
With CD ('/ETC/VSFTPD '):
Run (' Rm-rf vsftpd.conf ')
Run (' cp/software/vsftpd.conf./')

@roles (' Hadoop1 ')
Def deploypgsql ():
With CD ('/software '):
Run (' Unzip Pgsql.zip ')
Run (' Rpm-ivh postgresql-libs-8.4.20-7.el6.x86_64.rpm ')
Run (' Rpm-ivh postgresql-8.4.20-7.el6.x86_64.rpm ')
Run (' Rpm-ivh postgresql-server-8.4.20-7.el6.x86_64.rpm ')

def deploymysql (masterorslave, password):
Global Mysqlcmd
Mysqlcmd = "Grant replication slave on * * to ' root ' @ ' Hadoop2.cbas ' identified by '%s '"% (password)
if (Masterorslave = = ' Master ' or masterorslave = = ' slave ') and not password is None:
With CD ('/software '):
Run (' Rpm-ivh mysql-connector-java-5.1.37-1.noarch.rpm ')
Run (' Unzip Mysql.zip ')
Run (' tar-xf Mysql56.tar ')
Run (' Useradd MySQL ')
Run (' Mkdir-p/data/mysql ')
Run (' rm-rf/etc/my.cnf ')
Run (' Rm-rf/etc/init.d/mysqld ')
Run (' Rm-rf/usr/bin/mysql ')
Run ('/software/mysql/scripts/mysql_install_db--basedir=/software/mysql--datadir=/data/mysql ')
Run (' Cp/software/mysql/support-files/mysql.server/etc/rc.d/init.d/mysqld ')
Run (' Chkconfig--add mysqld ')
Run (' Chkconfig mysqld on ')
With CD ('/data '):
Run (' Touch Mysqld.log ')
Run (' Chown mysql:mysql/data-r ')
if Masterorslave = = ' Master ':
With CD ('/software/mysql '):
Run (' echo-e ' basedir =/software/mysql\ndatadir =/data/mysql\nport = 3306\nsocket =/tmp/mysql.sock\npid-file=/data/ mysql.pid\nbind-address=0.0.0.0\nmax_connections=3000\ndefault-storage-engine=innodb\nbinlog_format=mixed\ Nserver-id=1\nlog-bin=master-bin\nlog-bin-index=master-bin.index\n[mysqld_safe]\nlog-error =/data/mysqld.log " >> my.cnf ')
With CD ('/software/mysql/bin '):
Run (' Ln-s/software/mysql/bin/mysql/usr/bin/mysql ')
Run (' Service mysqld start ')
Run ("./mysqladmin-u root password '%s '"% (password))
Run ("./mysql-uroot-p{0}-e {1}{2};{ 3} ". Format (password, '" ', Mysqlcmd, ' "))
Run (' Service mysqld restart ')
elif Masterorslave = = ' slave ':
With CD ('/software/mysql '):
Run (' echo-e ' basedir =/software/mysql\ndatadir =/data/mysql\nport = 3306\nsocket =/tmp/mysql.sock\npid-file=/data/ mysql.pid\nbind-address=0.0.0.0\nmax_connections=3000\ndefault-storage-engine=innodb\nbinlog_format=mixed\ Nserver-id=2\nrelay-log=slave-relay-bin\nrelay-log-index=slave-relay-bin.index\n[mysqld_safe]\nlog-error =/data /mysqld.log ">> my.cnf")
With CD ('/software/mysql/bin '):
Run (' Ln-s/software/mysql/bin/mysql/usr/bin/mysql ')
Run (' Service mysqld start ')
Run ("./mysqladmin-u root password '%s '"% (password))
Else
Run (' echo usage:fab-h [email protected] (the host which you want to deploy MySQL master or slave) Setroles Deploymysql:mas Terorslave=master|slave, Password=mysqlpassword

Application of fab modules in Python

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.