IM开源项目OpenIM部署文档-从准备工作到nginx配置2022-11-14 22:27·OpenIM
一、准备工作运行环境linux系统即可, Ubuntu 7.5.0-3ubuntu1~18.04最优图片视频文件存储支持cos/MinIOhttps/wss协议1. 需申请域名或者子域名(web im端登录注册及im 服务端使用)建议:web.xx.xx 2. 若使用MinIO作为对象存储,建议:storage.xx.xx 3. 管理后台子域名,建议:admin.xx.xx 4. 部署nginx,并配置证书。离线推送(app被杀死或未启动时推送)国内申请申请厂商通道以及个推,建议提前申请;海外申请firebase;苹果开发者账号如需打包、上架,请自行申请账号手机验证码服务请自行申请阿里云,建议提前申请消息加密存储需购买消息加密插件组织架构需购买组织架构模块机器资源如果用户量小于10万,可用单机部署,8C 16G 5Mb 1T普通磁盘即可logo1024 x 1024png软著如需上架国内市场,提前准备软著管理后台需购买二、docker-compose一键部署先准备go/git/docker/docker-compose,具体参考:https://doc.rentsoft.cn/#/com...单机环境下的组件部署,可以通过docker-compose一键部署,先选择某个大磁盘目录,然后依次输入如下命令:git clone https://github.com/OpenIMSDK/... --recursive;进入项目后1.修改.envUSER=root #不用修改
PASSWORD=openIM123 #建议修改复杂密码 不能包括 @#之类特殊符号 且至少要8位
ENDPOINT=http://127.0.0.1:10005 #使用minio发图片视频文件需要填写 外网ip:port或者用域名
DATA_DIR=./ #指定大磁盘目录2.初始化部署chmod +x install_im_server.sh
./install_im_server.sh具体组件包括:ETCD 2. MySQL 3. MongoDB 4. Redis 5. Kafka 6. Minio(注:如果使用三方云服务器存储媒体文件可不搭建)3.修改配置如果已经执行过install_im_server.sh,则config/usualConfig.yaml根据.env的配置已经修改完成了,且组件也安装完毕,则根据需求修改如下字段tokenpolicy:
accessSecret: "open_im_server" #token生成相关 建议修改
accessExpire: 90 #token过期时间(天) 默认即可
messageverify:
friendVerify: false #发送消息是否验证好友关系 false表示不验证好友关系
push:
getui:
pushUrl: "https://restapi.getui.com/v2/$appId"
masterSecret: "" #需添加
appKey: "" #需添加
enable: false #true启动个推推送可能存在的问题:如果非首次安装,可能env密码不能生效,如果数据不重要,先docker-compose down ; rm components -rf再执行以上步骤,需要注意的是app需要重新安装。4.重启docker-compose down; docker-compose up -d;三、开源版Open-IM-Server 源码编译安装Go环境。确保Go版本至少为1.15。下载源码到服务器git clone https://github.com/OpenIMSDK/Open-IM-Server.git --recursive
cd cmd/Open-IM-SDK-Core
设置脚本权限cd ../../script/
chmod +x *.sh编译源码./batch_build_all_service.sh出现all services build success表示编译成功四、Open-IM-Server修改配置&启动服务修改配置如果组件未自行安装,则先执行(二)的1-3步骤、如果要修改ip port等非常用信息,需要在config.yaml中修改。启动服务cd script
./start_all.sh 检查服务./check_all.sh启动服务./start_all.sh检查服务# 出现all services launch success表示服务启动成功
./check_all.sh(二)和(四)操作完成后,实际上完成了混合部署模式,即docker部署组件,IM源码部署。五、nginx配置参考用业务申请的web.xx.xx/storage.xx.xx/admin.xx.xx分别替换open-im-ng-example.conf中web.rentsoft.cn /storage.rentsoft.cn/admin.rentsoft.cn三个域名及对应的证书upstream im_msg_gateway{
server 127.0.0.1:10001; #IM消息服务器地址 根据部署情况可指定多台
}
upstream im_api{
server 127.0.0.1:10002; #IM群组用户api服务器地址 根据部署情况可指定多台
}
upstream im_jssdk_gateway{
server 127.0.0.1:10003; #IM jssdk服务器地址 根据部署情况可指定多台
}
upstream im_demo{
server 127.0.0.1:10004; #IM demo登录注册服务器地址 根据部署情况可指定多台
}
upstream storage {
server 127.0.0.1:10005; #MinIO服务器地址 暂时支持1台
}
upstream im_admin{
server 127.0.0.1:10006; #IM admin服务器地址 根据部署情况可指定多台
}
upstream im_grafana{
server 127.0.0.1:10007; #IM 统计服务器地址 docker-compose启动所在机器
}
upstream im_chat{
server 127.0.0.1:10008; #IM 商业版登录注册服务器地址 根据部署情况可指定多台
}
upstream im_complete_admin{
server 127.0.0.1:10009; #IM 商业版admin地址 根据部署情况可指定多台
}
upstream im_organization{
server 127.0.0.1:10010; #IM 商业版组织架构服务器地址 根据部署情况可指定多台
}
upstream im_open_rtc{
server 127.0.0.1:7880; #rtc 音视频通话 服务器地址 根据部署情况可指定多台
}
server {
listen 443;
server_name web.rentsoft.cn; #1 web im 端 域名
ssl on;
ssl_certificate /etc/nginx/conf.d/ssl/web.rentsoft.cn.crt; #2 证书
ssl_certificate_key /etc/nginx/conf.d/ssl/web.rentsoft.cn.key; #3 证书
ssl_session_timeout 5m;
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]\.";
error_page 405 =200 $uri;
default_type application/wasm;
location /{ #web demo
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-NginX-Proxy true;
root /data1/online/Pc-Web-Demo/build/; # web im静态资源存放路径
index index.html;
try_files $uri $uri/ /index.html;
}
location /msg_gateway { #10001 ws
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://im_msg_gateway/;
}
location ^~/api/ { #10002 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_pass http://im_api/;
}
location /jssdk_gateway { #10003 jssdk
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://im_jssdk_gateway/;
}
location ^~/demo/ { # 10004 demo
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://im_demo/;
}
location ^~/admin/ { #10006 admin
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://im_admin/;
}
location ^~/grafana/ { #10007 prometheus
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://im_grafana/;
}
location ^~/chat/ { #10008 chat login
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://im_chat/;
}
location ^~/complete_admin/ { #10009 admin
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://im_complete_admin/;
}
location ^~/organization/ { #10010 organization
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://im_organization/;
}
location ^~/open_rtc/ { #7880 rtc
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://im_open_rtc/;
}
}
server {
listen 80;
server_name web.rentsoft.cn ; #1 web im 端 域名
rewrite ^(.*)$ https://${server_name}$1 permanent;
}
server {
ssl_session_timeout 5m;
listen 443;
server_name storage.rentsoft.cn; #1 MinIO存储域名
ssl on;
ssl_certificate /etc/nginx/conf.d/ssl/storage.rentsoft.cn.crt; #证书
ssl_certificate_key /etc/nginx/conf.d/ssl/storage.rentsoft.cn.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;
gzip_vary off;
gzip_disable "MSIE [1-6]\.";
location / {
proxy_pass http://storage;
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_set_header Host $http_host;
proxy_http_version 1.1;
client_max_body_size 8000M;
}
}
server {
listen 443;
server_name admin.rentsoft.cn; #后台管理域名
ssl on;
ssl_certificate /etc/nginx/conf.d/ssl/admin.rentsoft.cn.crt; # 证书
ssl_certificate_key /etc/nginx/conf.d/ssl/admin.rentsoft.cn.key; #证书
ssl_session_timeout 5m;
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;
gzip_vary off;
gzip_disable "MSIE [1-6]\.";
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-NginX-Proxy true;
root /data1/online/Open-IM-Admin/dist/; #管理后台web静态资源存放路径
index index.html;
try_files $uri $uri/ /index.html;
}
}
server {
listen 80;
server_name admin.rentsoft.cn; #管理后台 域名
rewrite ^(.*)$ https://${server_name}$1 permanent;
}
六、端口开放及访问路由IM如果按照(七)做了nginx配置,仅开放443和80端口即可。IM端口说明访问说明对应关系TCP:10001IM ws消息在域名和路由之间增加msg_gatewaywss://test.xx.xx/msg_gateway->ws://ip:10001TCP:10002IM api在域名和路由之间增加apihttps://test.xx.xx/api->http://ip:10002TCP:10003ws端口 jssdk的专用在域名和路由之间增加jssdk_gatewaywss://test.xx.xx/jssdk_gateway->ws://ip:10003TCP:10004demo注册登录在域名和路由之间增加demohttps://test.xx.xx/demo->http://ip:10004TCP:10005minio存储时TCP:10006IM 后台管理在域名和路由之间增加adminhttps://test.xx.xx/admin->http://ip:10006TCP:10007数据统计TCP:10008商业版业务在域名和路由之间增加chathttps://test.xx.xx/chat->http://ip:10008TCP:10009商业版管理后台在域名和路由之间增加complete_adminhttps://test.xx.xx/complete_a...;http://ip:10009TCP:10010商业版组织架构在域名和路由之间增加organizationhttps://test.xx.xx/organizati...;http://ip:10006音视频通话RTC端口说明操作TCP: 7881音视频通话直接开通端口,不走nginx反向代理UDP: 7882音视频通话直接开通端口,不走nginx反向代理关于OpenIMOpenIM是由IM技术专家打造开源即时通讯组件,也是目前最受欢迎的开源IM项目之一,开发者通过集成OpenIM组件,并私有化部署服务端,可以将即时通讯、实时通讯能力快速集成到自身应用中,并确保业务数据的安全性和私密性。github社区活跃,star近万,排名遥遥领先,开发者万人,OpenM力争开源IM项目No1,打造开源IM第一社区。OpenIM是也是目前非常受欢迎的开源IM项目,广泛用于政企协同办公场景。
github地址:https://github.com/OpenIMSDK/...开发者中心:https://doc.rentsoft.cn/#/平台支持:Android iOS Uniapp Flutter Electron Web reactNative等几乎所有平台web端基于wasm的sdk即将发布pc支持信创环境:银河麒麟 UOS等;群组支持:十万群成员的超级大群安卓基于自启动-保活机制,确保消息实时触达;
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。