|
1 | | -1. |
| 1 | +--- |
| 2 | +title: '集群部署说明' |
| 3 | +sidebar_position: 6 |
| 4 | +--- |
2 | 5 |
|
3 | | - ## 集群部署说明 |
4 | 6 |
|
5 | | - `open-im-server`支持集群部署。以下是**源码集群**部署的步骤: |
6 | 7 |
|
7 | | - 场景:两台机器部署`open-im-server`,分别为机器A和机器B,假设两台机器在同一内网中。 |
| 8 | +## 集群部署说明 |
8 | 9 |
|
9 | | - 机器A:部署`open-im-server`、`nginx`、`mongo`、`redis`、`etcd`、`kafka`、`minio`、`prometheus`、`grafana`、`aleartmanager`。 |
| 10 | +`open-im-server`支持集群部署。以下是**源码集群**部署的步骤: |
10 | 11 |
|
11 | | - 机器B:部署`open-im-server`。 |
| 12 | +场景:两台机器部署`open-im-server`,分别为机器A和机器B,假设两台机器在同一内网中。 |
12 | 13 |
|
13 | | - 组件`mongo`、`redis`、`kafka`、`etcd`均支持集群部署,以下场景默认每个组件集群部署3台。 |
| 14 | +机器A:部署`open-im-server`、`nginx`、`mongo`、`redis`、`etcd`、`kafka`、`minio`、`prometheus`、`grafana`、`aleartmanager`。 |
14 | 15 |
|
15 | | - 1. 机器A、B:克隆仓库: |
| 16 | +机器B:部署`open-im-server`。 |
16 | 17 |
|
17 | | - ```bash |
18 | | - git clone https://github.com/openimsdk/open-im-server && cd open-im-server |
19 | | - ``` |
| 18 | +组件`mongo`、`redis`、`kafka`、`etcd`均支持集群部署,以下场景默认每个组件集群部署3台。 |
20 | 19 |
|
21 | | - 2. 机器A:修改`kafka`、`minio`、`mongodb`、`etcd`(默认服务发现方式)、`redis`中的地址,将其配置到正确的组件地址中。**保证连接组件的各个端口可访问(关注防火墙规则是否允许端口被访问)。** |
22 | | - 修改`open-im-server/config`目录下,对应组件的地址。 |
23 | | - 对应配置文件字段为: |
| 20 | +1. 机器A、B:克隆仓库: |
24 | 21 |
|
25 | | - - `kafka`: `kafka.yml:address`,内容为`[ kafkaAddr1, kafkaAddr2, kafkaAddr3 ]` |
26 | | - - `minio`: `minio.yml`,`internalAddress`配置内部服务访问地址,`externalAddress`配置外部访问`minio`的地址。 |
27 | | - - `mongo`:`mongodb.yml:address`,内容为`[ mongoAddr1, mongoAddr2, mongoAddr3 ]` |
28 | | - - `etcd`: `discovery.yml:etcd.address`,内容为`[ etcdAddr1, etcdAddr2, etcdAddr3 ]` |
29 | | - - `redis`: `redis.yml:address`,内容为`[ redis1, redis2, redis3 ]`,并将`redis.yml`中的`clusterMode`设置为`true`(单机部署不需要)。 |
| 22 | + ```bash |
| 23 | + git clone https://github.com/openimsdk/open-im-server && cd open-im-server |
| 24 | + ``` |
30 | 25 |
|
31 | | - 3. 在`open-im-server/start-config.yml`中根据需求修改各个组件数量。 |
32 | | - |
33 | | - 4. 机器A部署`nginx`,参考配置如下: |
34 | | - |
35 | | - >🚀 **提示**: 确保替换成您的实际域名、SSL 证书路径和 SSL 密钥。 |
36 | | - |
37 | | - ```yaml |
38 | | - events { |
39 | | - worker_connections 1024; |
40 | | - } |
41 | | - |
42 | | - http { |
43 | | - #open-im-server chat Corresponding deployment address and port |
44 | | - upstream msg_gateway{ |
45 | | - #IM Message server address Multiple can be specified according to the deployment |
46 | | - server 127.0.0.1:10001; |
47 | | - server 192.168.2.36:10001; |
48 | | - } |
49 | | - upstream im_api{ |
50 | | - #IM Group user api server address Multiple can be specified according to the deployment |
51 | | - server 127.0.0.1:10002; |
52 | | - server 192.168.2.36:10001; |
53 | | - } |
54 | | - upstream minio_s3_2{ |
55 | | - #Minio address can be assigned to multiple modules dependingon deployment |
56 | | - server 127.0.0.1:10005; |
57 | | - } |
58 | | - server { |
59 | | - listen 443; #Listening on port 443 |
60 | | - server_name web.xx.xx; #Your domain name |
61 | | - ssl on; |
62 | | - #Path of pem file for ssl certificate |
63 | | - ssl_certificate /usr/local/nginx/conf/ssh/web.xx.xx_bundle.pem; |
64 | | - #Key file path of ssl certificate |
65 | | - ssl_certificate_key /usr/local/nginx/conf/ssh/web.xx.xx.key; |
66 | | - |
67 | | - gzip on; |
68 | | - gzip_min_length 1k; |
69 | | - gzip_buffers 4 16k; |
70 | | - gzip_comp_level 2; |
71 | | - gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/wasm; |
72 | | - gzip_vary off; |
73 | | - gzip_disable "MSIE [1-6]\."; |
74 | | - |
75 | | - location ^~/api/{ |
76 | | - proxy_http_version 1.1; |
77 | | - proxy_set_header Upgrade $http_upgrade; |
78 | | - proxy_set_header Connection "Upgrade"; |
79 | | - proxy_set_header X-real-ip $remote_addr; |
80 | | - proxy_set_header X-Forwarded-For $remote_addr; |
81 | | - proxy_set_header X-Request-Api $scheme://$host/api; |
82 | | - proxy_pass http://im_api/; |
83 | | - } |
84 | | - |
85 | | - location /msg_gateway{ |
86 | | - proxy_http_version 1.1; |
87 | | - proxy_set_header Upgrade $http_upgrade; |
88 | | - proxy_set_header Connection "Upgrade"; |
89 | | - proxy_set_header X-real-ip $remote_addr; |
90 | | - proxy_set_header X-Forwarded-For $remote_addr; |
91 | | - proxy_pass http://msg_gateway/; |
92 | | - } |
93 | | - |
94 | | - location ^~/im-minio-api/ { |
95 | | - proxy_set_header Host $http_host; |
96 | | - proxy_set_header X-Real-IP $remote_addr; |
97 | | - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
98 | | - proxy_set_header X-Forwarded-Proto $scheme; |
99 | | - proxy_connect_timeout 300; |
100 | | - |
101 | | - proxy_http_version 1.1; |
102 | | - proxy_set_header Connection ""; |
103 | | - chunked_transfer_encoding off; |
104 | | - proxy_pass http://minio_s3_2/; |
105 | | - } |
106 | | - } |
107 | | - } |
108 | | - ``` |
| 26 | +2. 机器A:修改`kafka`、`minio`、`mongodb`、`etcd`(默认服务发现方式)、`redis`中的地址,将其配置到正确的组件地址中。**保证连接组件的各个端口可访问(关注防火墙规则是否允许端口被访问)。** |
| 27 | + 修改`open-im-server/config`目录下,对应组件的地址。 |
| 28 | + 对应配置文件字段为: |
| 29 | + |
| 30 | + - `kafka`: `kafka.yml:address`,内容为`[ kafkaAddr1, kafkaAddr2, kafkaAddr3 ]` |
| 31 | + - `minio`: `minio.yml`,`internalAddress`配置内部服务访问地址,`externalAddress`配置外部访问`minio`的地址。 |
| 32 | + - `mongo`:`mongodb.yml:address`,内容为`[ mongoAddr1, mongoAddr2, mongoAddr3 ]` |
| 33 | + - `etcd`: `discovery.yml:etcd.address`,内容为`[ etcdAddr1, etcdAddr2, etcdAddr3 ]` |
| 34 | + - `redis`: `redis.yml:address`,内容为`[ redis1, redis2, redis3 ]`,并将`redis.yml`中的`clusterMode`设置为`true`(单机部署不需要)。 |
| 35 | + |
| 36 | +3. 在`open-im-server/start-config.yml`中根据需求修改各个组件数量。 |
| 37 | + |
| 38 | +4. 机器A部署`nginx`,参考配置如下: |
| 39 | + |
| 40 | + >🚀 **提示**: 确保替换成您的实际域名、SSL 证书路径和 SSL 密钥。 |
| 41 | +
|
| 42 | + ```yaml |
| 43 | + events { |
| 44 | + worker_connections 1024; |
| 45 | + } |
109 | 46 |
|
110 | | - 5. `mage`编译,`mage start`启动服务。 |
| 47 | + http { |
| 48 | + #open-im-server chat Corresponding deployment address and port |
| 49 | + upstream msg_gateway{ |
| 50 | + #IM Message server address Multiple can be specified according to the deployment |
| 51 | + server 127.0.0.1:10001; |
| 52 | + server 192.168.2.36:10001; |
| 53 | + } |
| 54 | + upstream im_api{ |
| 55 | + #IM Group user api server address Multiple can be specified according to the deployment |
| 56 | + server 127.0.0.1:10002; |
| 57 | + server 192.168.2.36:10001; |
| 58 | + } |
| 59 | + upstream minio_s3_2{ |
| 60 | + #Minio address can be assigned to multiple modules dependingon deployment |
| 61 | + server 127.0.0.1:10005; |
| 62 | + } |
| 63 | + server { |
| 64 | + listen 443; #Listening on port 443 |
| 65 | + server_name web.xx.xx; #Your domain name |
| 66 | + ssl on; |
| 67 | + #Path of pem file for ssl certificate |
| 68 | + ssl_certificate /usr/local/nginx/conf/ssh/web.xx.xx_bundle.pem; |
| 69 | + #Key file path of ssl certificate |
| 70 | + ssl_certificate_key /usr/local/nginx/conf/ssh/web.xx.xx.key; |
111 | 71 |
|
112 | | - ## **常见问题/注意事项** |
| 72 | + gzip on; |
| 73 | + gzip_min_length 1k; |
| 74 | + gzip_buffers 4 16k; |
| 75 | + gzip_comp_level 2; |
| 76 | + gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/wasm; |
| 77 | + gzip_vary off; |
| 78 | + gzip_disable "MSIE [1-6]\."; |
113 | 79 |
|
114 | | - 1. 部署`kafka`时,需要修改`kafka`广播的端口。如果使用`open-im-server`中的`docker-compose.yml`部署,修改`service.kafka.environment.KAFKA_CFG_ADVERTISED_LISTENERS`中的`EXTERNAL`为访问`kafka`组件的地址。其他部署方式请自行修改。 |
115 | | - 例如:`KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,EXTERNAL://192.168.2.36:19094`。 |
116 | | - 2. 多台机器部署需要保证时钟一致,服务才可正常运行。例如`token`的签发允许各个机器的时钟误差在`5s`以内。 |
117 | | - 3. 组件端口无法访问:通过回环地址检测组件启动是否正常,若回环地址可访问,则检查是否被防火墙规则过滤。 |
118 | | - 4. 如果集群机器**不在内网中**,需要将`autoSetPorts`设置为`false`,并修改各个`rpc`组件的`registerIP`为设置部署`etcd`的服务器可访问的`ip`地址,**并保证各个端口可被访问**。如需启用`prometheus`,还需要保证各个组件的`prometheus.port`端口可被访问。 |
119 | | - 拥有`autoSetPorts`配置的组件如下: |
120 | | - |
121 | | - - `openim-api.yml:prometheus.autoSetPorts` |
122 | | - - `openim-msggateway.yml:rpc.autoSetPorts` |
123 | | - - `openim-msgtransfer.yml:prometheus.autoSetPorts` |
124 | | - - `openim-push.yml:rpc.autoSetPorts` |
125 | | - - `openim-rpc-auth.yml:rpc.autoSetPorts` |
126 | | - - `openim-rpc-conversation.yml:rpc.autoSetPorts` |
127 | | - - `openim-rpc-friend.yml:rpc.autoSetPorts` |
128 | | - - `openim-rpc-group.yml:rpc.autoSetPorts` |
129 | | - - `openim-rpc-msg.yml:rpc.autoSetPorts` |
130 | | - - `openim-rpc-third.yml:rpc.autoSetPorts` |
131 | | - - `openim-rpc-user.yml:rpc.autoSetPorts` |
| 80 | + location ^~/api/{ |
| 81 | + proxy_http_version 1.1; |
| 82 | + proxy_set_header Upgrade $http_upgrade; |
| 83 | + proxy_set_header Connection "Upgrade"; |
| 84 | + proxy_set_header X-real-ip $remote_addr; |
| 85 | + proxy_set_header X-Forwarded-For $remote_addr; |
| 86 | + proxy_set_header X-Request-Api $scheme://$host/api; |
| 87 | + proxy_pass http://im_api/; |
| 88 | + } |
132 | 89 |
|
133 | | -  |
| 90 | + location /msg_gateway{ |
| 91 | + proxy_http_version 1.1; |
| 92 | + proxy_set_header Upgrade $http_upgrade; |
| 93 | + proxy_set_header Connection "Upgrade"; |
| 94 | + proxy_set_header X-real-ip $remote_addr; |
| 95 | + proxy_set_header X-Forwarded-For $remote_addr; |
| 96 | + proxy_pass http://msg_gateway/; |
| 97 | + } |
134 | 98 |
|
135 | | - 此外,机器A还需要修改`prometheus.yml`,将其中的所有`http_sd_configs`配置项及其子配置项去掉,加上`static_configs`配置项,并将其中的`targets`改为对应的服务的端口。 |
136 | | - 例如:`openimserver-openim-api`表示`api`组件的`prometheus`数据抓取,则其`target`中的端口地址应和`openim-api.yml`中的`prometheus.ports`一致。 |
| 99 | + location ^~/im-minio-api/ { |
| 100 | + proxy_set_header Host $http_host; |
| 101 | + proxy_set_header X-Real-IP $remote_addr; |
| 102 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 103 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 104 | + proxy_connect_timeout 300; |
137 | 105 |
|
138 | | -  |
| 106 | + proxy_http_version 1.1; |
| 107 | + proxy_set_header Connection ""; |
| 108 | + chunked_transfer_encoding off; |
| 109 | + proxy_pass http://minio_s3_2/; |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + ``` |
| 114 | + |
| 115 | +5. `mage`编译,`mage start`启动服务。 |
| 116 | + |
| 117 | +6. 初始化`sdk`时,配置`api`连接地址`http://web.xx.xx/api`,`ws`连接地址`http://web.xx.xx/msg_gateway`,`minio`地址为`http://web.xx.xx/im-minio-api`。 |
| 118 | + |
| 119 | +## **常见问题/注意事项** |
| 120 | + |
| 121 | +1. 部署`kafka`时,需要修改`kafka`广播的端口。如果使用`open-im-server`中的`docker-compose.yml`部署,修改`service.kafka.environment.KAFKA_CFG_ADVERTISED_LISTENERS`中的`EXTERNAL`为访问`kafka`组件的地址。其他部署方式请自行修改。 |
| 122 | + 例如:`KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,EXTERNAL://192.168.2.36:19094`。 |
| 123 | +2. 多台机器部署需要保证时钟一致,服务才可正常运行。例如`token`的签发允许各个机器的时钟误差在`5s`以内。 |
| 124 | +3. 组件端口无法访问:通过回环地址检测组件启动是否正常,若回环地址可访问,则检查是否被防火墙规则过滤。 |
| 125 | +4. 如果集群机器**不在内网中**,需要将`autoSetPorts`设置为`false`,并修改各个`rpc`组件的`registerIP`为设置部署`etcd`的服务器可访问的`ip`地址,**并保证各个端口可被访问**。如需启用`prometheus`,还需要保证各个组件的`prometheus.port`端口可被访问。 |
| 126 | + 拥有`autoSetPorts`配置的组件如下: |
| 127 | + |
| 128 | + - `openim-api.yml:prometheus.autoSetPorts` |
| 129 | + - `openim-msggateway.yml:rpc.autoSetPorts` |
| 130 | + - `openim-msgtransfer.yml:prometheus.autoSetPorts` |
| 131 | + - `openim-push.yml:rpc.autoSetPorts` |
| 132 | + - `openim-rpc-auth.yml:rpc.autoSetPorts` |
| 133 | + - `openim-rpc-conversation.yml:rpc.autoSetPorts` |
| 134 | + - `openim-rpc-friend.yml:rpc.autoSetPorts` |
| 135 | + - `openim-rpc-group.yml:rpc.autoSetPorts` |
| 136 | + - `openim-rpc-msg.yml:rpc.autoSetPorts` |
| 137 | + - `openim-rpc-third.yml:rpc.autoSetPorts` |
| 138 | + - `openim-rpc-user.yml:rpc.autoSetPorts` |
| 139 | + |
| 140 | +  |
| 141 | + |
| 142 | + 此外,机器A还需要修改`prometheus.yml`,将其中的所有`http_sd_configs`配置项及其子配置项去掉,加上`static_configs`配置项,并将其中的`targets`改为对应的服务的端口。 |
| 143 | + 例如:`openimserver-openim-api`表示`api`组件的`prometheus`数据抓取,则其`target`中的端口地址应和`openim-api.yml`中的`prometheus.ports`一致。 |
| 144 | + |
| 145 | +  |
0 commit comments