首页 > 代码库 > fabric本地一键部署LAMP

fabric本地一键部署LAMP

一、添加普通用户jeff执行sudo时无需输入密码

$ sudo vim /etc/sudoers

--------------------------------------->

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
jeff    ALL=(ALL)     NOPASSWD:     ALL

 

二、安装fabric

$ sudo yum install epel-release -y
$ sudo yum install python-pip -y && sudo pip install --upgrade pip
$ sudo pip install fabric

 

三、创建文件index.php

vim /home/jeff/index.php

 ---------------------------------------->

<?php
   phpinfo() 
?>

 

四、创建自动化安装脚本auto_install_lamp.py

$ vim anto_install_lamp.py

 ----------------------------------------->

#!/usr/bin/env python
 
from fabric.colors import *
from fabric.api import *
 
env.user = ‘root‘
env.roledefs = {
    ‘node1‘: [‘127.0.0.1‘]
}
env.password = ‘redhat‘
 
@roles(‘node1‘)
def lamptask():
    print yellow("Auto install LAMP ...")
    with settings(warn_only=True):
        run("yum install httpd -y")       
	run("yum groupinstall mariadb -y")
        run("yum install pcre gcc-c++ zlib* php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml* php-mbstring php-bcmath php-mhash -y")
        local(‘sudo cp /home/jeff/index.php /var/www/html/‘) 
        run("systemctl start mariadb")
	run("systemctl enable mariadb")
        run("systemctl start httpd")
	run("systemctl enable httpd")

def deploy():
    execute(lamptask)

 

五、执行脚本

$ fab -f auto_install_lamp.py deploy

 

六、浏览器查看结果: http://10.0.0.20        //此处的10.0.0.20为我设置的本机IP

fabric本地一键部署LAMP