ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ansible分离部署lamp

2021-07-19 09:32:06  阅读:249  来源: 互联网

标签:x86 部署 192.168 Installed python lamp ansible 64


Ansible部署lanm

添加受管主机

[root@localhost ansible]# cat cctv 
[http]
192.168.100.42 ansible_user=root ansible_password=1
[php]
192.168.100.43 ansible_user=root ansible_password=1
[mysql]
192.168.100.44ansible_user=root ansible_password=1 

测试能否ping通

[root@localhost ansible]# ansible all -m ping
192.168.100.42 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
192.168.100.43 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
192.168.100.44 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}

下载和配置httpd、php、mysql

[root@localhost ansible]# ansible 192.168.100.42 -m yum -a 'name=httpd state=present'	#下载http服务
192.168.100.42 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "msg": "",
    "rc": 0,
    "results": [
        "Installed: httpd-2.4.37-40.module_el8.5.0+852+0aafc63b.x86_64",
        "Installed: mod_http2-1.15.7-3.module_el8.4.0+778+c970deab.x86_64"
    ]
}

[root@localhost ansible]# ansible 192.168.100.43-m yum -a 'name=php* state=present'	#下载php服务
192.168.100.43| CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "msg": "",
    "rc": 0,
    "results": [
        "Installed: php-intl-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64",
        "Installed: php-json-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64",
········
   "Installed: glibc-headers-2.28-161.el8.x86_64",
        "Installed: php-fpm-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64",
        "Installed: pcre-utf32-8.42-6.el8.x86_64",
        "Installed: php-gd-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64",
        "Installed: php-gmp-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64",
        "Removed: pcre-8.42-4.el8.x86_64",
        "Removed: glibc-2.28-141.el8.x86_64",
        "Removed: glibc-common-2.28-141.el8.x86_64",
        "Removed: glibc-langpack-zh-2.28-141.el8.x86_64",
        "Removed: libxcrypt-4.1.1-4.el8.x86_64"
    ]
}

[root@localhost ansible]# ansible 192.168.100.44 -m yum -a 'name=mysql state=present'	#安装mysql
192.168.100.44 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "msg": "",
    "rc": 0,
    "results": [
        "Installed: mariadb-connector-c-config-3.1.11-2.el8_3.noarch",
        "Installed: mysql-8.0.21-1.module_el8.4.0+589+11e12751.x86_64",
        "Installed: mysql-common-8.0.21-1.module_el8.4.0+589+11e12751.x86_64"
    ]
[root@localhost ansible]# ansible 192.168.100.44-m yum -a 'name=mysql-server state=present'
192.168.100.44 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "msg": "",
    "rc": 0,
    "results": [
        "Installed: protobuf-lite-3.5.0-13.el8.x86_64",
        "Installed: python3-policycoreutils-2.9-14.el8.noarch",
        "Installed: python3-audit-3.0-0.17.20191104git1c2f876.el8.x86_64",
        "Installed: mysql-errmsg-8.0.21-1.module_el8.4.0+589+11e12751.x86_64",
        "Installed: mysql-server-8.0.21-1.module_el8.4.0+589+11e12751.x86_64",
        "Installed: mecab-0.996-1.module_el8.4.0+589+11e12751.9.x86_64",
        "Installed: python3-setools-4.3.0-2.el8.x86_64",
        "Installed: policycoreutils-2.9-14.el8.x86_64",
        "Installed: libsemanage-2.9-6.el8.x86_64",
        "Installed: checkpolicy-2.9-1.el8.x86_64",
        "Installed: policycoreutils-python-utils-2.9-14.el8.noarch",
        "Installed: python3-libsemanage-2.9-6.el8.x86_64",
        "Removed: libsemanage-2.9-4.el8.x86_64",
        "Removed: policycoreutils-2.9-9.el8.x86_64"
    ]
}
[root@localhost ansible]#

配置httpd服务

[root@localhost ansible]# ansible 192.168.100.42 -m lineinfile -a 	'path=/etc/httpd/conf/httpd.conf insertafter="AddType application/x-gzip" line="AddType application/x-httpd-php .php"'
192.168.100.42 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line added"
}
[root@localhost ansible]# ansible 192.168.100.42 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf insertafter="AddType application/x-httpd-php .php" line="AddType application/x-httpd-php-source .phps "'
192.168.100.42 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line added"
}

[root@localhost ansible]# ansible 192.168.100.42 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf line="<VirtualHost *:80>\nDocumentRoot "/usr/local/apache/htdocs"\nServerName www.scl.com\nProxyRequests Off\nProxyPassMatch ^/(.*\.php)$ fcgi://192.168.100.43:9000/www/abc/$1\n<Directory "/www/abc/">\nOptions none\nAllowOverride none\nRequire all granted\n</Directory>\n</VirtualHost>"'
192.168.100.42 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line added"
}

配置php服务

[root@localhost ansible]# ansible 192.168.240.50 -m command -a 'touch www/abc/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.240.50 | CHANGED | rc=0 >>

[root@localhost ansible]# ansible 192.168.100.43 -m lineinfile -a 'path=www/abc/index.php line="<?php phpinfo(); ?>"'
192.168.100.43 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line added"
}

[root@localhost ansible]# ansible 192.168.100.43 -m lineinfile -a 'path=/etc/php-fpm.d/www.conf insertafter=" Note: This value is mandatory." line=192.168.100.43:9000'
192.168.100.43 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line added"
}

关闭防火墙跟selinux

[root@localhost ansible]# ansible all -m service -a 'name=firewalld  state=stopped'
192.168.100.42 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "name": "firewalld",
    "state": "stopped",
    "status": {
·······
192.168.100.43 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
·······
192.168.100.44 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "name": "firewalld",
    "state": "stopped",
    "status": {
        "ActiveState": "active",
        "UMask": "0022",
        "WatchdogTimestamp": "Sat 2021-07-17 07:15:33 EDT",
        "WatchdogTimestampMonotonic": "5128397",
        "WatchdogUSec": "0"
    }
}

[root@localhost ansible]# ansible all -m service -a 'name=selinux state=stopped'
192.168.100.44 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "name": "selinux",
    "state": "stopped",
    "status": {
        "ActiveState": "inactive",
        "AllowedCPUs": "",
·····
192.168.100.43 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "name": "selinux",
    "state": "stopped",
    "status": {
        "ActiveState": "inactive",
        "AllowedCPUs": "",
        "AllowedMemoryNodes": "",
        "BlockIOAccounting": "no",
······
192.168.100.42 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "name": "selinux",
    "state": "stopped",
    "status": {
        "ActiveState": "inactive",
        "AllowedCPUs": "",
        "AllowedMemoryNodes": "",
·······
"TimeoutStartUSec": "1min 30s",
        "TimeoutStopUSec": "1min 30s",
        "TimerSlackNSec": "50000",
        "UID": "[not set]",
        "UMask": "0022",
        "WatchdogTimestampMonotonic": "0",
        "WatchdogUSec": "0"
    }
}

启动服务

[root@localhost ansible]# ansible 192.168.100.42 -m service -a 'name=httpd state=restarted'
192.168.100.43 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "name": "httpd",
    "state": "started",
    "status": {
        "ActiveState": "active",
        "AllowedCPUs": "",
        "AllowedMemoryNodes": "",
······
 "TimerSlackNSec": "50000",
        "Type": "notify",
        "UID": "[not set]",
        "UMask": "0022",
        "WatchdogTimestamp": "Sun 2021-07-17 07:50:43 EDT",
        "WatchdogTimestampMonotonic": "20867005813",
        "WatchdogUSec": "0"
    }
}

[root@localhost ansible]# ansible 192.168.100.43 -m service -a 'name=php-fpm.service state=restarted
> '
192.168.100.43 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "name": "php-fpm.service",
    "state": "started",
    "status": {
        "ActiveState": "inactive",
        "AllowedCPUs": "",
        "AllowedMemoryNodes": "",
        "BlockIOAccounting": "no",
        "BlockIOWeight": "[not set]",
······
 "TasksCurrent": "[not set]",
        "TasksMax": "4743",
        "TimeoutStartUSec": "1min 30s",
        "TimeoutStopUSec": "1min 30s",
        "TimerSlackNSec": "50000",
        "Type": "notify",
        "UID": "[not set]",
        "UMask": "0022",
        "WatchdogTimestampMonotonic": "0",
        "WatchdogUSec": "0"
    }
}

在这里插入图片描述

标签:x86,部署,192.168,Installed,python,lamp,ansible,64
来源: https://blog.csdn.net/m0_60072944/article/details/118888408

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有