Ansible分离部署LAMP架构

Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@master ~]# ansible all -m lineinfile -a ‘path=/etc/selinux/config regexp=“^SELINUX=”’

//查看selinux

[root@master ~]# ansible all -m shell -a ‘cat /etc/selinux/config’

192.168.129.133 | CHANGED | rc=0 >>

This file controls the state of SELinux on the system.

SELINUX= can take one of these three values:

enforcing - SELinux security policy is enforced.

permissive - SELinux prints warnings instead of enforcing.

disabled - No SELinux policy is loaded.

SELINUX=disabled

SELINUXTYPE= can take one of these three values:

targeted - Targeted processes are protected,

minimum - Modification of targeted policy. Only selected processes are protected.

mls - Multi Level Security protection.

SELINUXTYPE=targeted

master主机进行anisble配置


[root@master lamp]# vim /etc/ansible/ansible.cfg

inventory = /etc/ansible/inventory

[root@master lamp]# cat /etc/ansible/inventory

[php]

192.168.129.137

[mysql]

192.168.129.135

[httpd]

192.168.129.133

免密登录


  • httpd、mysql、php步骤一样

[root@master ~]# ssh-copy-id root@192.168.129.133

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: “/root/.ssh/id_rsa.pub”

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed – if you are prompted now it is to install the new keys

root@192.168.129.133’s password:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘root@192.168.129.133’”

and check to make sure that only the key(s) you wanted were added.

[root@master ~]# ssh-agent bash

[root@master ~]# ssh-add

Enter passphrase for /root/.ssh/id_rsa:

Identity added: /root/.ssh/id_rsa (root@master)

192.168.129.133安装httpd


[root@master ~]# ansible httpd -m yum -a ‘name=httpd* state=installed’

192.168.129.133 | CHANGED => {

“ansible_facts”: {

“discovered_interpreter_python”: “/usr/libexec/platform-python”

},

“changed”: true,

“msg”: “”,

“rc”: 0,

“results”: [

“Installed: mod_http2-1.15.7-3.module_el8.4.0+778+c970deab.x86_64”,

“Installed: cyrus-sasl-devel-2.1.27-1.el8.x86_64”,

“Installed: expat-devel-2.2.5-3.el8.x86_64”,

“Installed: apr-1.6.3-11.el8.x86_64”,

“Installed: apr-devel-1.6.3-11.el8.x86_64”,

“Installed: libdb-devel-5.3.28-40.el8.x86_64”,

“Installed: apr-util-1.6.1-6.el8.x86_64”,

“Installed: httpd-tools-2.4.37-39.module_el8.4.0+778+c970deab.x86_64”,

“Installed: apr-util-bdb-1.6.1-6.el8.x86_64”,

“Installed: openldap-devel-2.4.46-11.el8.x86_64”,

“Installed: apr-util-devel-1.6.1-6.el8.x86_64”,

“Installed: httpd-2.4.37-39.module_el8.4.0+778+c970deab.x86_64”,

“Installed: apr-util-openssl-1.6.1-6.el8.x86_64”,

“Installed: centos-logos-httpd-85.8-1.el8.noarch”,

“Installed: httpd-devel-2.4.37-39.module_el8.4.0+778+c970deab.x86_64”,

“Installed: httpd-filesystem-2.4.37-39.module_el8.4.0+778+c970deab.noarch”,

“Installed: httpd-manual-2.4.37-39.module_el8.4.0+778+c970deab.noarch”

]

}

//开启服务与开机自启

[root@master ~]# ansible httpd -m service -a “name=httpd state=started enabled=yes”

192.168.129.133 | SUCCESS => {

“ansible_facts”: {

“discovered_interpreter_python”: “/usr/libexec/platform-python”

},

“changed”: false,

“enabled”: true,

“name”: “httpd”,

“state”: “started”,

“status”: {

“ActiveEnterTimestamp”: “Mon 2021-07-19 19:12:12 CST”,

“ActiveEnterTimestampMonotonic”: “1076238167”,

“ActiveExitTimestampMonotonic”: “0”,

……略

192.168.129.135安装mariadb


[root@master ~]# ansible mysql -m yum -a ‘name=mariadb state=present’

192.168.129.135 | CHANGED => {

“ansible_facts”: {

“discovered_interpreter_python”: “/usr/libexec/platform-python”

},

“changed”: true,

“msg”: “”,

“rc”: 0,

“results”: [

“Installed: mariadb-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64”,

“Installed: mariadb-common-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64”,

“Installed: mariadb-connector-c-3.0.7-1.el8.x86_64”,

“Installed: mariadb-connector-c-config-3.0.7-1.el8.noarch”

]

}

//安装mariadb-server

[root@master ~]# ansible mysql -m yum -a ‘name=mariadb-server state=present’

192.168.129.135 | CHANGED => {

“ansible_facts”: {

“discovered_interpreter_python”: “/usr/libexec/platform-python”

},

“changed”: true,

“msg”: “”,

“rc”: 0,

“results”: [

“Installed: mariadb-errmsg-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64”,

“Installed: mariadb-gssapi-server-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64”,

“Installed: mariadb-server-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64”,

“Installed: mariadb-server-utils-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64”,

“Installed: perl-DBD-MySQL-4.046-3.module+el8.1.0+2938+301254e2.x86_64”,

“Installed: mariadb-backup-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64”

]

}

//开启服务于开机自启

[root@master ~]# ansible mysql -m service -a ‘name=mariadb state=started enabled=yes’

192.168.129.135 | CHANGED => {

“ansible_facts”: {

“discovered_interpreter_python”: “/usr/libexec/platform-python”

},

“changed”: true,

“enabled”: true,

“name”: “mariadb”,

“state”: “started”,

“status”: {

“ActiveEnterTimestampMonotonic”: “0”,

“ActiveExitTimestampMonotonic”: “0”,

……略

192.168129.137安装php


[root@master ~]# ansible php -m yum -a ‘name=php state=present’

192.168.129.137 | CHANGED => {

“ansible_facts”: {

“discovered_interpreter_python”: “/usr/libexec/platform-python”

},

“changed”: true,

“msg”: “”,

“rc”: 0,

“results”: [

“Installed: apr-util-bdb-1.6.1-6.el8.x86_64”,

“Installed: httpd-2.4.37-39.module_el8.4.0+778+c970deab.x86_64”,

“Installed: apr-util-openssl-1.6.1-6.el8.x86_64”,

“Installed: centos-logos-httpd-85.8-1.el8.noarch”,

“Installed: httpd-filesystem-2.4.37-39.module_el8.4.0+778+c970deab.noarch”,

“Installed: httpd-tools-2.4.37-39.module_el8.4.0+778+c970deab.x86_64”,

“Installed: nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch”,

“Installed: php-fpm-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64”,

“Installed: php-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64”,

“Installed: php-common-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64”,

“Installed: mod_http2-1.15.7-3.module_el8.4.0+778+c970deab.x86_64”,

“Installed: php-cli-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64”,

“Installed: apr-1.6.3-11.el8.x86_64”,

“Installed: apr-util-1.6.1-6.el8.x86_64”

]

}

//安装php相关组件

[root@master ~]# ansible php -m yum -a ‘name=php-* state=present’

192.168.129.137 | CHANGED => {

“ansible_facts”: {

“discovered_interpreter_python”: “/usr/libexec/platform-python”

},

“changed”: true,

“msg”: “”,

“rc”: 0,

……略

修改apache的配置


[root@master ~]# ansible httpd -m lineinfile -a ‘path=/etc/httpd/conf/httpd.conf line=“<VirtualHost :80>\nDocumentRoot “/var/www/html/www1”\nServerName www.192.168.129.133.com\nProxyRequests off\nProxyPassMatch ^/(..php)$ fcgi://192.168.129.137:9000/var/www/html/www1/$1\n<Directory “/var/www/html/www1”>\nOptions None\nAllowOverride None\nOrder allow,deny\nAllow from all\n\n”’

192.168.129.133 | CHANGED => {

“ansible_facts”: {

“discovered_interpreter_python”: “/usr/libexec/platform-python”

},

“backup”: “”,

“changed”: true,

“msg”: “line added”

}

//在http主机上查看

[root@httpd conf]# cat /etc/httpd/conf/httpd.conf

<VirtualHost *:80>

DocumentRoot “/var/www/html/www1”

ServerName www.192.168.129.133

ProxyRequests Off

ProxyPassMatch ^/(.*.php)$ fcgi://192.168.129.137:9000/var/www/html/www1$1

<Directory “/var/www/html/www1”>

Options none

言尽于此,完结

无论是一个初级的 coder,高级的程序员,还是顶级的系统架构师,应该都有深刻的领会到设计模式的重要性。

  • 第一,设计模式能让专业人之间交流方便,如下:

程序员A:这里我用了XXX设计模式

程序员B:那我大致了解你程序的设计思路了

  • 第二,易维护

项目经理:今天客户有这样一个需求…

程序员:明白了,这里我使用了XXX设计模式,所以改起来很快

  • 第三,设计模式是编程经验的总结

程序员A:B,你怎么想到要这样去构建你的代码

程序员B:在我学习了XXX设计模式之后,好像自然而然就感觉这样写能避免一些问题

  • 第四,学习设计模式并不是必须的

程序员A:B,你这段代码使用的是XXX设计模式对吗?

程序员B:不好意思,我没有学习过设计模式,但是我的经验告诉我是这样写的

image

从设计思想解读开源框架,一步一步到Spring、Spring5、SpringMVC、MyBatis等源码解读,我都已收集整理全套,篇幅有限,这块只是详细的解说了23种设计模式,整理的文件如下图一览无余!

image

搜集费时费力,能看到此处的都是真爱!

这里我用了XXX设计模式

程序员B:那我大致了解你程序的设计思路了

  • 第二,易维护

项目经理:今天客户有这样一个需求…

程序员:明白了,这里我使用了XXX设计模式,所以改起来很快

  • 第三,设计模式是编程经验的总结

程序员A:B,你怎么想到要这样去构建你的代码

程序员B:在我学习了XXX设计模式之后,好像自然而然就感觉这样写能避免一些问题

  • 第四,学习设计模式并不是必须的

程序员A:B,你这段代码使用的是XXX设计模式对吗?

程序员B:不好意思,我没有学习过设计模式,但是我的经验告诉我是这样写的

[外链图片转存中…(img-NiReNVmT-1714276074842)]

从设计思想解读开源框架,一步一步到Spring、Spring5、SpringMVC、MyBatis等源码解读,我都已收集整理全套,篇幅有限,这块只是详细的解说了23种设计模式,整理的文件如下图一览无余!

[外链图片转存中…(img-5QfEFhIZ-1714276074843)]

搜集费时费力,能看到此处的都是真爱!

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

  • 15
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用Ansible分离部署LNMP可以让你更轻松地管理和部署LNMP服务器。以下是一些基本步骤: 1. 安装Ansible 2. 创建Ansible inventory文件,包含LNMP服务器的IP地址。 3. 创建Ansible playbook文件,指定要安装的软件包。 4. 在Ansible playbook文件中定义任务,例如安装Nginx、MySQL和PHP。 5. 运行Ansible playbook文件,Ansible将自动在LNMP服务器上安装和配置软件。 下面是一个可能的示例Ansible playbook文件: ``` --- - hosts: lnmp_servers become: true vars: nginx_version: 1.18.0 mysql_version: 5.7 php_version: 7.4 tasks: - name: Install Nginx yum: name: nginx-{{ nginx_version }} state: present - name: Start Nginx service: name: nginx state: started - name: Install MySQL yum: name: mysql-server-{{ mysql_version }} state: present - name: Start MySQL service: name: mysqld state: started - name: Install PHP yum: name: php-{{ php_version }} php-fpm-{{ php_version }} state: present - name: Start PHP-FPM service: name: php-fpm state: started ``` 在这个示例中,我们假设我们有一个名为"lnmp_servers"的Ansible组,其中包含我们要部署LNMP的服务器的IP地址。此外,我们定义了要安装的软件包的版本号,并在任务中安装和启动Nginx、MySQL和PHP。 运行Ansible playbook文件的命令是: ``` ansible-playbook -i inventory_file playbook_file.yml ``` 其中,inventory_file是你的Ansible inventory文件的路径,playbook_file.yml是你的Ansible playbook文件的路径。 这就是使用Ansible分离部署LNMP的基本步骤。你可以根据你的具体需求进行修改和定制。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值