nginx 做mysql负载均衡

首先安装nginx
1. 编辑文档: /etc/yum.repos.d/nginx.repo

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
  1. 安装命令

yum install nginx –disablerepo=* –enablerepo=nginx

3.nginx 配置:

stream {
    server {
        listen 3306;
        proxy_pass db;
    }

    upstream db {
        server db1:3306;
        server db2:3306;
        server db3:3306;
    }
}

说明文档
nginx tcp 负载均衡说明文档

你可能感兴趣的:(Mysql)