环境准备
mysql server :192.168.122.80
mysql server :192.168.122.121
负载均衡server :192.168.122.231
一、数据库
安装数据库详情见下面链接
https://blog.csdn.net/huhuhuhu555/category_10274299.html
数据库授权
grant all on *.* to zz@'%' identified by 'QianFeng@123';
三、修改代理服务器配置文件
(这个和http标签属于同一级,七层需要写到http下,这个不需要,别写错位置)
1 vim /etc/nginx/nginx.conf
stream {
upstream myweb {
server 192.168.122.80:3306;
server 192.168.122.121:3306;
}
server {
listen 82;
proxy_connect_timeout 10s;
proxy_timeout 30s;
proxy_pass myweb;
}
}
2 nginx -s reload
测试
[root@yum_nginx_121 ~]# mysql -u zz -pQianFeng@123 -h 192.168.122.231 -e "select * from db1.t1" -P82
mysql: [Warning] Using a password on the command line interface can be insecure.
+------+-------------+
| id | name |
+------+-------------+
| 1 | a.mysql.com |
+------+-------------+
[root@yum_nginx_121 ~]# mysql -u zz -pQianFeng@123 -h 192.168.122.231 -e "select * from db1.t1" -P82
mysql: [Warning] Using a password on the command line interface can be insecure.
+------+-------------+
| id | name |
+------+-------------+
| 1 | b.mysql.com |
+------+-------------+
[root@yum_nginx_121 ~]# mysql -u zz -pQianFeng@123 -h 192.168.122.231 -e "select * from db1.t1" -P82
mysql: [Warning] Using a password on the command line interface can be insecure.
+------+-------------+
| id | name |
+------+-------------+
| 1 | a.mysql.com |
+------+-------------+
[root@yum_nginx_121 ~]# mysql -u zz -pQianFeng@123 -h 192.168.122.231 -e "select * from db1.t1" -P82
mysql: [Warning] Using a password on the command line interface can be insecure.
+------+-------------+
| id | name |
+------+-------------+
| 1 | b.mysql.com |
+------+-------------+