You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/admin-manual/cluster-management/load-balancing.md
+224-2Lines changed: 224 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -121,7 +121,229 @@ mysql> show databases;
121
121
2 rows inset (0.00 sec)
122
122
```
123
123
124
-
### 03 HAProxy
124
+
### 03 NJet
125
+
126
+
You can use [NJet](https://docs.njet.org.cn/) to keep an Nginx-like experience while gaining enhanced features such as dynamic management and health checks. The following example also uses `192.168.1.100` as the proxy node and `192.168.1.101/102/103`.
127
+
128
+
#### Install NJet
129
+
130
+
Please refer to the official NJet installation guide: https://docs.njet.org.cn/docs/v4.0.0/guide/install/index.html. Below are example installation steps for Docker and Ubuntu.
131
+
132
+
1. Docker
133
+
134
+
```shell
135
+
## Pull NJET image
136
+
docker pull tmlake/njet:latest
137
+
138
+
## Run NJET
139
+
docker run -d --rm --privileged tmlake/njet:latest
server 192.168.1.101:9030 weight=1 max_fails=2 fail_timeout=60s;
173
+
server 192.168.1.102:9030 weight=1 max_fails=2 fail_timeout=60s;
174
+
server 192.168.1.103:9030 weight=1 max_fails=2 fail_timeout=60s;
175
+
}
176
+
server {
177
+
# Proxy port
178
+
listen 6030;
179
+
proxy_connect_timeout 300s;
180
+
proxy_timeout 300s;
181
+
proxy_pass mysqld;
182
+
}
183
+
}
184
+
```
185
+
186
+
#### Dynamic upstream member management
187
+
188
+
OpenNJet provides HTTP APIs to dynamically add/remove upstream members. To enable this you need to enable related modules on both data plane and control plane.
When you add a new FE node (for example `192.168.1.104:9030`), you can add it via API. OpenNJet will assign an ID to the newly added server which can be used for later queries, removal, or update.
234
+
235
+
POST URL: `POST http://{ip}:8081/api/v1/upstream_api/stream/upstreams/{upstream_name}/servers/`
236
+
237
+
```bash
238
+
curl -X POST http://127.0.0.1:8081/api/v1/upstream_api/stream/upstreams/mysqld/servers/ -d '{
Active health checks are enabled by default; you can configure them via `http://{ip}:8081/api/v1/hc/smysql/{upstream}`:
262
+
263
+
```bash
264
+
curl -X 'POST' \
265
+
'http://127.0.0.1:8081/api/v1/hc/smysql/mysqld' \
266
+
-H 'accept: application/json' \
267
+
-H 'Content-Type: application/json' \
268
+
-d '{
269
+
"interval": "5s",
270
+
"jitter": "1s",
271
+
"timeout": "5s",
272
+
"passes": 1,
273
+
"fails": 1,
274
+
"sql": {
275
+
"select": "select 1",
276
+
"useSsl": true,
277
+
"user": "root",
278
+
"password": "123456",
279
+
"db": "db"
280
+
}
281
+
}'
282
+
```
283
+
284
+
Field notes:
285
+
286
+
- `interval`: required, health check frequency.
287
+
- `visit_interval`: optional, if the server has been accessed by clients within this interval, skip the health check;`interval` should be greater than `visit_interval`.
288
+
- `jitter`: required, maximum timer jitter for the health check to avoid synchronized checks.
289
+
- `timeout`: required, timeout for the health check.
290
+
- `passes`: required, number of consecutive successful checks to mark server healthy.
291
+
- `fails`: required, number of consecutive failures to mark server unhealthy.
292
+
- `port`: optional, override the port used for health checks;if omitted, the upstream server port is used.
293
+
- `sql`: contains `select/useSsl/user/password/db` fields;`db` is required.
294
+
295
+
#### JSON configuration support
296
+
297
+
NJet supports JSON configuration which is helpful for automation. Convert `njet.conf` to `njet.json` and load it with `njet -c conf/njet.json`.
[HAProxy](https://www.haproxy.org/) is a high-performance TCP/HTTP load balancer written in C language.
127
349
@@ -244,7 +466,7 @@ mysql> show databases;
244
466
245
467
`mysql -h 192.168.1.100 -uroot -P6030 -p`
246
468
247
-
### 04 ProxySQL
469
+
### 05 ProxySQL
248
470
249
471
[ProxySQL](https://proxysql.com/) is an open-source MySQL database proxy software written in C language. It can implement connection management, read-write splitting, load balancing, failover, and other functions. It has advantages such as high performance, configurability, and dynamic management, and is commonly used in Web services, big data platforms, cloud databases, and other scenarios.
0 commit comments