标签:ber round finger warning des 授权 print -- 表示
[root@localhost ~]# yum -y install ansible 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirror.jdcloud.com * extras: mirror.bit.edu.cn
[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
[root@localhost ~]# vim /etc/ansible/hosts [lnmp] 192.168.202.131 192.168.202.133
如图:
--- - 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 ~
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 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-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关闭了以后自动换另一台不影响存储数据
标签:ber round finger warning des 授权 print -- 表示
原文地址:https://www.cnblogs.com/gaiting/p/12056918.html