部署lamp平台

通过ansible快速部署lamp平台

远程关闭防火墙

[root@localhost ansible]# ansible 192.168.197.135 -m service -a "name=firewalld.service state=stopped enabled=no "
192.168.197.135 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "enabled": false,
    "name": "firewalld.service",
    "state": "stopped",

[root@localhost ansible]# ansible 192.168.197.135 -m service -a "name=firewalld.service state=stopped enabled=no "
192.168.197.135 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "enabled": false,
    "name": "firewalld.service",
    "state": "stopped",
[root@localhost ansible]# ansible 192.168.197.135 -m service -a "name=firewalld.service state=stopped enabled=no "
192.168.197.135 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "enabled": false,
    "name": "firewalld.service",
    "state": "stopped",

部署过程
通过ansible控制远程安装httpd服务

[root@localhost ansible]# ansible 192.168.197.135 -m service -a "name=httpd state=started enabled=yes "
192.168.197.135 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "enabled": true,
    "name": "httpd",
    "state": "started",

通过ansible控制远程安装mariadb服务

[root@localhost ansible]# ansible 192.168.197.135 -m service -a "name=mariadb state=started enabled=yes "
192.168.197.135| CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "enabled": true,
    "name": "mariadb",
    "state": "started",

通过ansible控制远程安装php服务

[root@localhost ansible]# ansible 192.168.197.135 -m yum -a "name='php' state='installed'"192.168.101.210 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "msg": "",
    "rc": 0,
    "results": [......
[root@localhost ansible]# ansible 192.168.197.135 -m yum -a "name='php-mysqlnd.x86_64' state='installed'"
192.168.197.135| CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "msg": "",
    "rc": 0,
    "results": [.......

对httpd进行配置

[root@localhost ansible]# ansible 192.168.197.135 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf line="<VirtualHost *:80>\nDocumentRoot "/usr/local/apache/htdocs"\nServerName www.ljt.com\nErrorLog "logs/www.example.com-error_log"\nCustomLog "logs/www.example.com-access_log" common|nProxyRequests off\nProxyPassMatch ^/(.*\.php)$ fcgi://192.168.101.210:9000/var/www/html/$1\n<Directory "/var/www/html/">\n Require all granted\n</Directory>\n</VirtualHost>"'192.168.101.120 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line added"
}
[root@localhost ansible]# ansible 192.168.197.135 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf regexp="^AddType " insertafter="^AddType application/x-gzip .gz .tgz" line="AddType application/x-httpd-php .php\nAddType application/x-httpd-php-source .phps"'
192.168.197.135 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line replaced"
}
[root@localhost ansible]# ansible 192.168.197.135 -m service -a "name='httpd' state='restarted' "
 
192.168.197.135| CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "name": "httpd",
    "state": "started",

对PHP进行配置


```bash
[root@localhost ansible]# ansible 192.168.197.135 -m command -a "chdir=/var/www/html touch index.php"
[WARNING]: Consider using the file module with state=touch rather than running 'touch'.  If you
need to use command because file is insufficient you can add 'warn: false' to this command task
or set 'command_warnings=False' in ansible.cfg to get rid of this message.
192.168.197.135 | CHANGED | rc=0 >>

[root@localhost ansible]# ansible 192.168.197.135 -m lineinfile -a "name=/var/www/html/index.php  line='<?php\nphpinfo();\n?>'"
192.168.197.135 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line added"
}
[root@localhost ansible]# ansible 192.168.197.135 -m lineinfile -a 'path=/etc/php-fpm.d/www.conf regexp="^listen =" line="listen = 192.168.197.135:9000"'
192.168.197.135 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line replaced"
}
[root@localhost ansible]# ansible 192.168.197.135 -m lineinfile -a 'path=/etc/php-fpm.d/www.conf regexp="^listen.allowed_clients =" line="listen.allowed_clients = 192.168.197.135"'
192.168.197.135 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",

重启服务

[root@localhost ansible]# ansible 192.168.197.135 -m service -a "name='php-fpm' state='restarted' "
192.168.197.135 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "name": "php-fpm",
    "state": "started",
[root@localhost ansible]# ansible 192.168.197.135 -m service -a "name='httpd' state='restarted' "
192.168.197.135 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "name": "httpd",
    "state": "started",

查看结果
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值