Cluster Deployment Instructions
Cluster Deployment Instructions
open-im-server
supports cluster deployment. Below are the steps for source cluster deployment:
Scenario: Deploy open-im-server
on two machines, Machine A and Machine B, assuming both machines are in the same internal network.
Machine A: Deploy open-im-server
, nginx
, mongo
, redis
, etcd
, kafka
, minio
, prometheus
, grafana
, alertmanager
.
Machine B: Deploy open-im-server
.
The components mongo
, redis
, kafka
, and etcd
all support cluster deployment. In the following scenario, each component cluster is deployed on 3 nodes by default.
On Machine A and B: Clone the repository:
git clone https://github.com/openimsdk/open-im-server && cd open-im-server
On Machine A: Modify the addresses in
kafka
,minio
,mongodb
,etcd
(default service discovery method), andredis
, configuring them to the correct component addresses. Ensure that the ports of the connected components are accessible (check if firewall rules allow port access). Modify the addresses of the corresponding components in theopen-im-server/config
directory.Corresponding configuration file fields:
kafka
:kafka.yml:address
, containing[ kafkaAddr1, kafkaAddr2, kafkaAddr3 ]
minio
:minio.yml
,internalAddress
configures the internal service access address,externalAddress
configures the external access address forminio
.mongo
:mongodb.yml:address
, containing[ mongoAddr1, mongoAddr2, mongoAddr3 ]
etcd
:discovery.yml:etcd.address
, containing[ etcdAddr1, etcdAddr2, etcdAddr3 ]
redis
:redis.yml:address
, containing[ redis1, redis2, redis3 ]
, and setclusterMode
inredis.yml
totrue
(not needed for single-node deployment).
Modify the number of each component as needed in
open-im-server/start-config.yml
.Deploy
nginx
on Machine A, with the following reference configuration:🚀 Tip: Ensure to replace with your actual domain name, SSL certificate path, and SSL key.
events {
worker_connections 1024;
}
http {
#open-im-server chat Corresponding deployment address and port
upstream msg_gateway{
#IM Message server address Multiple can be specified according to the deployment
server 127.0.0.1:10001;
server 192.168.2.36:10001;
}
upstream im_api{
#IM Group user api server address Multiple can be specified according to the deployment
server 127.0.0.1:10002;
server 192.168.2.36:10001;
}
upstream minio_s3_2{
#Minio address can be assigned to multiple modules depending on deployment
server 127.0.0.1:10005;
}
server {
listen 443; #Listening on port 443
server_name web.xx.xx; #Your domain name
ssl on;
#Path of pem file for ssl certificate
ssl_certificate /usr/local/nginx/conf/ssh/web.xx.xx_bundle.pem;
#Key file path of ssl certificate
ssl_certificate_key /usr/local/nginx/conf/ssh/web.xx.xx.key;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 2;
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;
gzip_vary off;
gzip_disable "MSIE [1-6]\.";
location ^~/api/{
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Request-Api $scheme://$host/api;
proxy_pass http://im_api/;
}
location /msg_gateway{
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://msg_gateway/;
}
location ^~/im-minio-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 300;
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding off;
proxy_pass http://minio_s3_2/;
}
}
}Compile with
mage
, start the service withmage start
.When initializing the
sdk
, configure theapi
connection address ashttp://web.xx.xx/api
, thews
connection address ashttp://web.xx.xx/msg_gateway
, and theminio
address ashttp://web.xx.xx/im-minio-api
.
Frequently Asked Questions / Notes
When deploying
kafka
, you need to modify the broadcast port ofkafka
. If usingdocker-compose.yml
inopen-im-server
, modifyservice.kafka.environment.KAFKA_CFG_ADVERTISED_LISTENERS
'sEXTERNAL
to the address to access thekafka
component. For other deployment methods, please modify accordingly. For example:KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,EXTERNAL://192.168.2.36:19094
.Deploying on multiple machines requires ensuring clock synchronization for services to run properly. For example, the issuance of
token
allows a clock skew within5s
across machines.If component ports are inaccessible: Use the loopback address to check if the component has started correctly. If the loopback address is accessible, then check if firewall rules are blocking access.
If cluster machines are not within the internal network, you need to set
autoSetPorts
tofalse
and modify theregisterIP
of eachrpc
component to the accessible IP address of the server whereetcd
is deployed, and ensure that all ports are accessible. If you need to enableprometheus
, you also need to ensure that theprometheus.port
of each component is accessible. Components withautoSetPorts
configuration are as follows:openim-api.yml:prometheus.autoSetPorts
openim-msggateway.yml:rpc.autoSetPorts
openim-msgtransfer.yml:prometheus.autoSetPorts
openim-push.yml:rpc.autoSetPorts
openim-rpc-auth.yml:rpc.autoSetPorts
openim-rpc-conversation.yml:rpc.autoSetPorts
openim-rpc-friend.yml:rpc.autoSetPorts
openim-rpc-group.yml:rpc.autoSetPorts
openim-rpc-msg.yml:rpc.autoSetPorts
openim-rpc-third.yml:rpc.autoSetPorts
openim-rpc-user.yml:rpc.autoSetPorts
Additionally, on Machine A, you need to modify
prometheus.yml
by removing allhttp_sd_configs
configuration items and their sub-items, addingstatic_configs
configuration items, and changing thetargets
to the corresponding service ports. For example:openimserver-openim-api
represents theapi
component'sprometheus
data scraping, so the port address in itstarget
should be consistent with theprometheus.ports
inopenim-api.yml
.