• centos7使用frabric自动化部署LNMP


    1、创建lnmp.py文件

    $ vim lnmp.py
    

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

    #!/usr/bin/env python
    
    from fabric.colors import *
    from fabric.api import *
    
    env.user = 'root'
    
    env.roledefs = {
    	'localhost': ['127.0.0.1']
    }
    env.password = 'redhat'
    
    @roles('localhost')
    def lnmptask():
      print yellow("A key to install LNMP...")
      with settings(warn_only=True):
        run('yum groupinstall mariadb -y')
        run('yum install nginx -y')
        run('yum install php php-fpm php-mysql php-mbstring php-xml php-mcrypt php-gd -y')
        run('systemctl start nginx')
        run('systemctl enable nginx')
        run('systemctl start mariadb')
        run('systemctl enable mariadb')
        run('systemctl start php-fpm') 
        run('systemctl enable php-fpm') 
    
    def deploy():
      execute(lnmptask)
    

    2、运行lnmp.py

    $ fab -f lnmp.py deploy
    

    3、修改/etc/nginx/nginx.conf文件,使其支持php。以下代码中只有中文标注部分是手动添加的!

    # for more information.
        include /etc/nginx/conf.d/*.conf;
    
        server {
            listen       80 default_server;
            listen       [::]:80 default_server;
            server_name  _;
            root         /usr/share/nginx/html;
    
            # Load configuration files for the default server block.
            include /etc/nginx/default.d/*.conf;
    
            location / {
               index index.php index.html index.htm;
            }
    
           #从下一行的location开始,往下6行都是添加的内容,  其它的都是默认的。     
            location ~ .php$ {
                    fastcgi_pass 127.0.0.1:9000;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
            }
    
            error_page 404 /404.html;
                location = /40x.html {
            }
    
            error_page 500 502 503 504 /50x.html;
                location = /50x.html {
            }
        }
    

    4、添加测试页面

    $ sudo vim /usr/share/nginx/html/index.php
    
    [/usr/share/nginx/html/index.php]
    
    <?php
        phpinfo() 
    ?>
    

    5、重启nginx服务并测试

    #重启服务
    $ sudo systemctl restart nginx
    
    #浏览器打开测试页面
    http://10.0.0.20
    
  • 相关阅读:
    Unity3D移动端海水的实时绘制
    NGUI 3.x 深度管理及渲染优化
    【入门】从学生到成熟:游戏模块设计起步之抽象思维 (转)
    正弦波近似 http://blog.csdn.net/ring0hx/article/details/44492415
    Stack 栈 ----Queue 队列
    ORM
    CBV&FBV
    Django路由系统
    CRM
    深浅拷贝
  • 原文地址:https://www.cnblogs.com/jefflee168/p/7425364.html
Copyright © 2020-2023  润新知