云计算架构设计 MHA+mysql
实验报告架构设计1.部署MHA+mysql主从,实现数据读写分离及集群高可用2.部署nginx+keepalived主从,实现主nginx故障从nginx转换为新主3.部署nginx+php+mysql集群,实现php通过代码连接主节点和从节点,验证是否可以成功连接4.部署nginx反向代理tomcat并验证5.部署redis集群1.部署MHA+mysql主从,实现数据读写分离及集群高可用[roo
实验报告
架构设计
1.部署MHA+mysql主从,实现数据读写分离及集群高可用
2.部署nginx+keepalived主从,实现主nginx故障从nginx转换为新主
3.部署nginx+php+mysql集群,实现php通过代码连接主节点和从节点,验证是否可以成功连接
4.部署nginx反向代理tomcat并验证
5.部署redis集群
1.部署MHA+mysql主从,实现数据读写分离及集群高可用
[root@localhost ~]# ssh-keygen
[root@localhost ~]# ssh-copy-id root@192.168.1.2
yes 123.com
[root@localhost ~]# ssh root@192.168.2.20
Last login: Sun Aug 30 23:41:11 2020
[root@localhost ~]# exit
登出
Connection to 192.168.2.20 closed.
[root@localhost ~]# ssh-copy-id root@192.168.2.30
ssh-copy-id root@192.168.2.30
ssh root@192.168.2.30
exit
ssh-copy-id root@192.168.2.40
ssh root@192.168.2.40
exit
其它主机同上
后三台
[root@localhost ~]# yum -y install mariadb*
mariadb的主:
[root@localhost ~]# vim /etc/my.cnf
server-id=1
log-bin=mysql-bin
重启服务
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# mysql -uroot -p
MariaDB [(none)]> set password=password("123.com");
进入数据库授权
MariaDB [(none)]> grant replication slave on *.* to "slave"@"192.168.1.%" identified by "123.com";
MariaDB [(none)]> grant all on *.* to "mha"@"192.168.1.%" identified by "123.com";
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> show master status\G
mariadb从1
[root@localhost ~]# vim /etc/my.cnf
server-id=2
log-bin=mysql-bin
relay-log=relay-log-bin
relay-log-purge=0
read-only=1
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# mysql -uroot -p
MariaDB [(none)]> set password=password("123.com");
MariaDB [(none)]> grant replication slave on *.* to "slave"@"192.168.1.%" identified by "123.com";
MariaDB [(none)]> grant all on *.* to "mha"@"192.168.1.%" identified by "123.com";
MariaDB [(none)]> flush privileges;
MariaDB[(none)]>changemasterto master_host="192.168.1.2",master_user="slave",master_password="123.com",master_log_file="mysql-bin.000003",master_log_pos=750;
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status\G
mariadb从2
[root@localhost ~]# vim /etc/my.cnf
server-id=3
log-bin=mysql-bin
relay-log=relay-log-bin
relay-log-purge=0
read-only=1
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# mysql -uroot -p
MariaDB [(none)]> set password=password("123.com");
MariaDB [(none)]> grant replication slave on *.* to "slave"@"192.168.2.%" identified by "123.com";
MariaDB [(none)]> grant all on *.* to "mha"@"192.168.2.%" identified by "123.com";
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> change master to master_host="192.168.2.20",master_user="slave",master_password="123.com",master_log_file="mysql-bin.000003",master_log_pos=750;
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status\G
连接成功
安装mha
四台
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# yum -y install perl-DBD-mysql perl-DBI perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager
如果出现yum睡眠
rm -rf /var/run/yum.pid
[root@localhost ~]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm
没有mariadb 第一台
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@localhost ~]# yum -y install perl-DBD-mysql perl-DBI perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager
[root@localhost ~]# rpm -ivh mha4mysql-manager-0.56-0.el6.noarch.rpm
第一台管理节点
[root@localhost ~]# mkdir /etc/mha
[root@localhost ~]# vim /etc/mha/mha.cnf
[server default]
user=mha
password=123.com
ssh_user=root
repl_user=slave
repl_password=123.com
ping_interval=1
master_ip_failover_script=/usr/bin/master_ip_failover
manager_workdir=/var/mha
manager_log=/var/mha/manager.log
[server1]
hostname=192.168.2.20
ssh_port=22
master_binlog_dir=/var/lib/mysql
[server2]
hostname=192.168.2.30
ssh_port=22
candidate_master=1
master_binlog_dir=/var/lib/mysql
[server3]
hostname=192.168.2.40
ssh_port=22
no_master=1
master_binlog_dir=/var/lib/mysql
vim /usr/bin/master_ip_failover 添加:
hmod a+x /usr/bin/master_ip_failover
检测mha的管理节点和后端mariadb节点ssh是否正常
masterha_check_ssh --conf=/etc/mha/mha.cnf
mariadb主
[root@localhost ~]# ip a
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:80:01:0f brd ff:ff:ff:ff:ff:ff
inet 192.168.2.20/24 brd 192.168.2.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet 192.168.2.200/24
从1:
Nginx+keepalived1:
安装nginx
root@localhost ~]# tar -zxf nginx-1.11.5.tar.gz
[root@localhost ~]# cd nginx-1.11.5/
[root@localhost nginx-1.11.5]# yum -y install gcc* pcre pcre-devel openssl-devel openssl zlib zlib-devel
[root@localhost nginx-1.11.5]# useradd -M -s /sbin/nologin nginx
[root@localhost nginx-1.11.5]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module && make && make install #编译安装
[root@localhost nginx-1.11.5]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
[root@localhost nginx-1.11.5]# nginx #启动服务
[root@localhost nginx-1.11.5]# netstat -anput | grep nginx
安装keepalived:
#yum -y install popt-devel kernel-devel openssl openssl-devel
# tar -zxf keepalived-1.2.13.tar.gz
# cd keepalived-1.2.13/
#./configure --prefix=/ --with-kernel-dir=/usr/src/kernel && make && make install
# vim /etc/keepalived/keepalived.conf #修改配置文件,改完将下面的全部删除
[root@localhost ~]# vim /etc/keepalived/check_nginx.sh
Nginx+keepalived2:
安装nginx
[root@localhost ~]# tar -zxf nginx-1.11.5.tar.gz
[root@localhost ~]# cd nginx-1.11.5/
[root@localhost nginx-1.11.5]# yum -y install gcc* pcre pcre-devel openssl-devel openssl zlib zlib-devel
[root@localhost nginx-1.11.5]# useradd -M -s /sbin/nologin nginx
[root@localhost nginx-1.11.5]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module && make && make install
[root@localhost nginx-1.11.5]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
[root@localhost nginx-1.11.5]# nginx #启动服务
[root@localhost nginx-1.11.5]#
3.部署nginx+php+mysql集群,实现php通过代码连接主节点和从节点,验证是否可以成功连接
安装PHP:
yum -y install gd libxml2-devel.x86_64 libpng-devel.x86_64 libjpeg-turbo-devel.x86_64 libXpm-devel.x86_64 pcre-devel
把那三个文件拖进来
配置编译安装:
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-gd --with-zlib --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-mysql=mysqlnd --with-mysqli=mysqlnd --enable-fpm --enable-mbstring && make && make install
- 复制主配置文件,路径优化
cp php.ini-development /usr/local/php/php.ini
ln -s /usr/local/php/bin/* /usr/local/bin/
- 修改配置文件
202 short_open_tag = On
680 default_charset ="UTF-8”
第一种请求
客户端访问
第二种请求
编辑: vim /usr/local/httpd/conf/httpd.conf
修改添加
systemctl stop httpd systemctl start httpd
编写动态页面
vim index.php
69 bind 192.168.2.10
92 port 7000 #端口
136 daemonize yes
672 appendonly yes
676 appendfilename "appendonly-7000.aof"
814 cluster-enabled yes #开启集群的功能
822 cluster-config-file nodes-7000.conf #集群文件
828 cluster-node-timeout 5000 #节点之间连接超时的时间
sed -i "s/7000/7001/g" 7001/redis.conf
cat 7001/redis.conf | grep 7001
sed -i "s/7000/7002/g" 7002/redis.conf
cat 7002/redis.conf | grep 7002
sed -i "s/7000/7003/g" 7003/redis.conf
cat 7003/redis.conf | grep 7003
sed -i "s/7000/7004/g" 7004/redis.conf
cat 7004/redis.conf | grep 7004
sed -i "s/7000/7005/g" 7005/redis.conf
cat 7005/redis.conf | grep 7005
更多推荐
所有评论(0)