负载均衡nginx+mysql练习


在这里插入图片描述

环境准备

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 |
+------+-------------+
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值