大环境

Posted gaiting

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了大环境相关的知识,希望对你有一定的参考价值。

一. 用三台机器 一台做ansible+playbook 搭建lnmp环境 

IP分配 

ansible 主机192.168.202.132

lnmp第一台主机 192.168.202.131

lnmp第一台主机 192.168.202.133

1.1 ansible主机安装ansible

[root@localhost ~]# yum -y install ansible
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.jdcloud.com
 * extras: mirror.bit.edu.cn 

1.2 ansible主机生成密钥设置免密码登录

[root@localhost ~]# ssh -keygen
Bad escape character ‘ygen‘.
[root@localhost ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_r
Created directory ‘/root/.ssh‘.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_
Your public key has been saved in /root/.ssh/id_rsa.
The key fingerprint is:
SHA256:snafmBirD5A4bkRNfs/yraWQ7BqJf4SKpLd0UO5yZyA rhost
The key‘s randomart image is:
+---[RSA 2048]----+
|   .             |
|  +              |
| . o..           |
|.. +. o          |
|o.E +..oS        |
|oo.*oo+o.        |
|+++o*+*..o       |
|+oo+o*.=++ .     |
| ..++++oo o      |
+----[SHA256]-----+
[root@localhost ~]# ssh-copy-id root@192.168.202.131
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be i "/root/.ssh/id_rsa.pub"
The authenticity of host ‘192.168.202.131 (192.168.2can‘t be established.
ECDSA key fingerprint is SHA256:+YOuMKydPwvlPwXHq3Cgj6X6jdlupF1W3A.
ECDSA key fingerprint is MD5:33:f9:54:0f:ce:1e:53:96:96:29:e3:04:7c.
Are you sure you want to continue connecting (yes/no
/usr/bin/ssh-copy-id: INFO: attempting to log in wit key(s), to filter out any that are already installe
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be in- if you are prompted now it is to install the new k
root@192.168.202.131‘s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh ‘root202.131‘"
and check to make sure that only the key(s) you wantdded.
[root@localhost ~]# ssh-copy-id root@192.168.202.133

  

1.3 ansible主机配置

[root@localhost ~]# vim /etc/ansible/hosts 

[lnmp]
192.168.202.131
192.168.202.133

 如图:

技术图片

 

 

 1.4 编写ansible的playbook  

---
        - hosts: lnmp
          tasks:
                - name: "安装需要的环境"
                  yum: name=gcc,gcc-c++,make,php,php-gd,php-mysql,php-fpm,pcre-devel,zlib-devel,mariadb,mariadb-server state=latest
                - name: "导入nginx"
                  unarchive: src=nginx-1.16.1.tar.gz dest=/root
                - name: "编译安装"
                  shell: cd /root/nginx-1.16.1 && ./configure && make && make install
                - name: "分发配置文件"
                  copy: src=nginx.conf dest=/usr/local/nginx/conf/nginx.conf
                - name: "分发主界面"
                  copy: src=info.php dest=/var/www/html/info.php
                - name: 启动nginx
                  shell: /usr/local/nginx/sbin/nginx
                - name: "启动mysql"
                  shell: systemctl restart mariadb
                - name: "启动php-fpm"
                  shell: systemctl restart php-fpm
                - name : "关闭防火墙"
                  shell: systemctl stop firewalld
                - name: "关闭selinux"
                  shell: setenforce 0
~                                      

 

 

1.4.2 更改nginx的配置文件

技术图片

技术图片

1.4.3 分发一个php的测试界面

技术图片

1.4.4 执行ansible-playbook

技术图片

 技术图片

1.4.5 展示效果看看lnmp是否搭建成功

技术图片

 

 

 

一.ansible主机完成

二.lnmp主机配置MySQL实现数据库的同步做数据库的互为主主然后做高可用

lnmp第一台主机 192.168.202.131 主

lnmp第一台主机 192.168.202.133  备份

2.1编辑配置文件 

192.168.202.131 操作

[root@localhost ~]# vim /etc/my.cnf
server-id=1
log-bin=mysql-bie
relay-log=mysql-relay
[root@localhost ~]# systemctl restart mariadb

192.168.202.133 操作

[root@localhost ~]# vim /etc/my.cnf
server-id=2
log-bin=mysql-bin
relay-log=mysql-relay
[root@localhost ~]# systemctl restart mariadb

2.2 主mysql授权

192.168.202.131操作

[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 2
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type help; or h for help. Type c to clear the current input statement.

MariaDB [(none)]> grant all on *.* to tom@% identified by123;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bie.000001 |      443 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

2.3 从上接受主的二进制日志更改slave

192.168.202.133 操作

[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 2
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type help; or h for help. Type c to clear the current input statement.

MariaDB [(none)]> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)

MariaDB [(none)]> change master to
-> master_host=192.168.202.131,
    -> master_user=tom,
    -> master_password=123,
    -> master_log_file=mysql-bie.000001,
    -> master_log_pos=443;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.11 sec)

2.4 查看有没有主从设置成功 如果是yes 表示成功

192.168.202.133 操作

 

2.5 设置主主

192.168.202.133 操作 给权限

MariaDB [(none)]>  grant all on *.* to ‘tom‘@‘%‘ identified by‘123‘;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>  flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      443 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

2.6 更改slave

192.168.202.131 操作  

[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 4
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type help; or h for help. Type c to clear the current input statement.

MariaDB [(none)]> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)

MariaDB [(none)]> change master to
    -> master_host=192.168.202.133,
    -> master_user=tom,
    -> master_password=123,
    -> master_log_file=mysql-bin.000001,
    -> master_log_pos=443;
Query OK, 0 rows affected (0.13 sec)

MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)

2.7 查看主主有没有配置成功 

两台主机都测试  是不是都是yes  主主设置完毕

MariaDB [(none)]> show slave status G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.202.131
                  Master_User: tom
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bie.000001
          Read_Master_Log_Pos: 443
               Relay_Log_File: mysql-relay.000002
                Relay_Log_Pos: 529
        Relay_Master_Log_File: mysql-bie.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
MariaDB [(none)]>  show slave status G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.202.133
                  Master_User: tom
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 443
               Relay_Log_File: mysql-relay.000002
                Relay_Log_Pos: 529
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

2.8 设置MySQL的高可用 一台MySQL关闭了以后自动换另一台不影响存储数据

 

  

 

  

  

二.lnmp主机配置mysql高可用完成

以上是关于大环境的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段13——Vue的状态大管家

炫酷 CSS 背景效果的 10 个代码片段

使用 Python 代码片段编写 LaTeX 文档

vue2.0 代码功能片段

一些恶心的代码片段

环境初始化 Build and Install the Apache Thrift IDL Compiler Install the Platform Development Tools(代码片段