码迷,mamicode.com
首页 > 其他好文 > 详细

centos7使用frabric自动化部署LNMP

时间:2017-08-24 22:35:34      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:stc   list   role   fastcgi   centos   star   pass   color   mct   

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、修改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

 

centos7使用frabric自动化部署LNMP

标签:stc   list   role   fastcgi   centos   star   pass   color   mct   

原文地址:http://www.cnblogs.com/jefflee168/p/7425364.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!