通过Nginx TCP反向代理实现Apache Doris负载均衡
概述Nginx能够实现HTTP、HTTPS协议的负载均衡,也能够实现TCP协议的负载均衡。那么,问题来了,可不可以通过Nginx实现Apache Doris数据库的负载均衡呢?答案是:可以。接下来,就让我们一起探讨下如何使用Nginx实现Apache Doris的负载均衡。环境准备注意:使用Nginx实现Apache Doris数据库的负载均衡,前提是要搭建Apache Doris的环境,Apac
·
概述
Nginx能够实现HTTP、HTTPS协议的负载均衡,也能够实现TCP协议的负载均衡。那么,问题来了,可不可以通过Nginx实现Apache Doris数据库的负载均衡呢?答案是:可以。接下来,就让我们一起探讨下如何使用Nginx实现Apache Doris的负载均衡。
环境准备
注意:使用Nginx实现Apache Doris数据库的负载均衡,前提是要搭建Apache Doris的环境,Apache Doris FE的IP和端口分别如下所示, 这里我是用一个FE来做演示的,多个FE只需要在配置里添加多个FE的IP地址和端口即可
IP: 172.31.7.119 端口: 9030
通过Nginx访问MySQL的Apache Doris和端口如下所示。
-
IP : 172.31.7.119
-
端口:6030
安装依赖
sudo apt-get install build-essential sudo apt-get install libpcre3 libpcre3-dev sudo apt-get install zlib1g-dev sudo apt-get install openssl libssl-dev
安装Nginx
sudo wget http://nginx.org/download/nginx-1.18.0.tar.gz sudo tar zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0 sudo ./configure --prefix=/usr/local/nginx --with-stream --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module sudo make && make install
配置反向代理
我这里是新建了一个配置文件
vim /usr/local/nginx/conf/default.conf
然后再里面加上下面的内容
events { worker_connections 1024; } stream { upstream mysqld { hash $remote_addr consistent; server 172.31.7.119:9030 weight=1 max_fails=2 fail_timeout=60s; ##注意这里如果是多个FE,加载这里就行了 } ###这里是配置代理的端口,超时时间等 server { listen 6030; proxy_connect_timeout 30s; proxy_timeout 30s; proxy_pass mysqld; } }
启动Nginx
指定配置文件启动
cd /usr/local/nginx /usr/local/nginx/sbin/nginx -c conf.d/default.conf
验证
mysql -uroot -P6030 -h172.31.7.119
参数解释: -u 指定Doris用户名 -p 指定Doris密码,我这里密码是空,所以没有 -h 指定Nginx代理服务器IP -P 指定端口
mysql -uroot -P6030 -h172.31.7.119 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 5.1.0 Doris version 0.15.1-rc09-Unknown Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | test | +--------------------+ 2 rows in set (0.00 sec) mysql> use test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +------------------+ | Tables_in_test | +------------------+ | dwd_product_live | +------------------+ 1 row in set (0.00 sec) mysql> desc dwd_product_live; +-----------------+---------------+------+-------+---------+---------+ | Field | Type | Null | Key | Default | Extra | +-----------------+---------------+------+-------+---------+---------+ | dt | DATE | Yes | true | NULL | | | proId | BIGINT | Yes | true | NULL | | | authorId | BIGINT | Yes | true | NULL | | | roomId | BIGINT | Yes | true | NULL | | | proTitle | VARCHAR(1024) | Yes | false | NULL | REPLACE | | proLogo | VARCHAR(1024) | Yes | false | NULL | REPLACE | | shopId | BIGINT | Yes | false | NULL | REPLACE | | shopTitle | VARCHAR(1024) | Yes | false | NULL | REPLACE | | profrom | INT | Yes | false | NULL | REPLACE | | proCategory | BIGINT | Yes | false | NULL | REPLACE | | proPrice | DECIMAL(18,2) | Yes | false | NULL | REPLACE | | couponPrice | DECIMAL(18,2) | Yes | false | NULL | REPLACE | | livePrice | DECIMAL(18,2) | Yes | false | NULL | REPLACE | | volume | BIGINT | Yes | false | NULL | REPLACE | | addedTime | BIGINT | Yes | false | NULL | REPLACE | | offTimeUnix | BIGINT | Yes | false | NULL | REPLACE | | offTime | BIGINT | Yes | false | NULL | REPLACE | | createTime | BIGINT | Yes | false | NULL | REPLACE | | createTimeUnix | BIGINT | Yes | false | NULL | REPLACE | | amount | DECIMAL(18,2) | Yes | false | NULL | REPLACE | | views | BIGINT | Yes | false | NULL | REPLACE | | commissionPrice | DECIMAL(18,2) | Yes | false | NULL | REPLACE | | proCostPrice | DECIMAL(18,2) | Yes | false | NULL | REPLACE | | proCode | VARCHAR(1024) | Yes | false | NULL | REPLACE | | proStatus | INT | Yes | false | NULL | REPLACE | | status | INT | Yes | false | NULL | REPLACE | | maxPrice | DECIMAL(18,2) | Yes | false | NULL | REPLACE | | liveView | BIGINT | Yes | false | NULL | REPLACE | | firstCategory | BIGINT | Yes | false | NULL | REPLACE | | secondCategory | BIGINT | Yes | false | NULL | REPLACE | | thirdCategory | BIGINT | Yes | false | NULL | REPLACE | | fourCategory | BIGINT | Yes | false | NULL | REPLACE | | minPrice | DECIMAL(18,2) | Yes | false | NULL | REPLACE | | liveVolume | BIGINT | Yes | false | NULL | REPLACE | | liveClick | BIGINT | Yes | false | NULL | REPLACE | | extensionId | VARCHAR(128) | Yes | false | NULL | REPLACE | | beginTime | BIGINT | Yes | false | NULL | REPLACE | | roomTitle | TEXT | Yes | false | NULL | REPLACE | | beginTimeUnix | BIGINT | Yes | false | NULL | REPLACE | | nickname | TEXT | Yes | false | NULL | REPLACE | +-----------------+---------------+------+-------+---------+---------+ 40 rows in set (0.06 sec)
更多推荐
已为社区贡献3条内容
所有评论(0)