zoukankan      html  css  js  c++  java
  • 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
    
  • 相关阅读:
    MvcApplication 中方法的那点事
    Html 中阻止事件冒泡的三种方法比较
    WPF中 ItemsSource 和DataContext不同点
    解决:Visual Studio 启动就报错退出
    webapi是如何绑定参数的(How WebAPI does Parameter Binding)
    %cd% 和%~dp0%的区别及cd跨盘符切换路径问题
    win10中matlabR2015b安装libsvm
    MATLAB2015b链接MinGW编译器
    网易内推编程题:异或运算求混合颜料的最小种类
    小易喜欢的单词
  • 原文地址:https://www.cnblogs.com/jefflee168/p/7425364.html
Copyright © 2011-2022 走看看