• 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全部左对齐
            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

  • 相关阅读:
    日程管理系统找Bug
    #单元测试
    读后感
    四则运算
    事后诸葛亮会议
    数据流图和数据流程图
    时序图
    ER图
    uml用例图
    第一迭代感想
  • 原文地址:https://www.cnblogs.com/jefflee168/p/7349893.html
Copyright © 2020-2023  润新知