box-im部署

发布于:2025-07-11 ⋅ 阅读:(21) ⋅ 点赞:(0)

https://gitee.com/bluexsx/box-im
https://www.yuque.com/u1475064/mufu2a/iulf5xfqz1w9p4gi

jdk、maven、node、mysql、redis、minio准备

mysql准备

#安装mysql
apt install mysql-server

修改mysql配置
vim /etc/mysql/mysql.conf.d/mysqld.cnf

#注释这两条
#bind-address           = x.x.x.x
#mysqlx-bind-address    = x.x.x.x

启动mysql

systemctl start mysql.service

mysql创建库、用户及授权

create database im_platform;
create user 'xxx'@'%' identified with mysql_native_password by '123456';
grant all privileges on *.* to 'xxx'@'%';
flush privileges;

redis准备

#安装redis
apt install redis-server

修改redis配置
vim /etc/redis/redis.conf

#修改以下配置
bind 0.0.0.0

启动redis

systemctl start redis-server.service

minio

wget https://dl.minio.org.cn/server/minio/release/linux-amd64/minio
chmod +x minio
mv minio /usr/local/bin/

vim /usr/lib/systemd/system/minio.service

[Unit]
Description=MinIO
Documentation=https://min.io/docs/minio/linux/index.html
Wants=network-online.target
After=network-online.target
AssertFileIsExecutable=/usr/local/bin/minio

[Service]
WorkingDirectory=/usr/local

User=minio-user
Group=minio-user
ProtectProc=invisible

EnvironmentFile=-/etc/default/minio
ExecStartPre=/bin/bash -c "if [ -z \"${MINIO_VOLUMES}\" ]; then echo \"Variable MINIO_VOLUMES not set in /etc/default/minio\"; exit 1; fi"
ExecStart=/usr/local/bin/minio server $MINIO_OPTS $MINIO_VOLUMES

# MinIO RELEASE.2023-05-04T21-44-30Z adds support for Type=notify (https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type=)
# This may improve systemctl setups where other services use `After=minio.server`
# Uncomment the line to enable the functionality
# Type=notify

# Let systemd restart this service always
Restart=always

# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536

# Specifies the maximum number of threads this process can create
TasksMax=infinity

# Disable timeout logic and wait until process is stopped
TimeoutStopSec=infinity
SendSIGKILL=no

[Install]
WantedBy=multi-user.target

# Built for ${project.name}-${project.version} (${project.name})
groupadd -r minio-user
useradd -M -r -g minio-user minio-user
mkdir /data/minio
chown minio-user:minio-user /data/minio

vim /etc/default/minio

# MINIO_ROOT_USER and MINIO_ROOT_PASSWORD sets the root account for the MinIO server.
# This user has unrestricted permissions to perform S3 and administrative API operations on any resource in the deployment.
# Omit to use the default values 'minioadmin:minioadmin'.
# MinIO recommends setting non-default values as a best practice, regardless of environment

MINIO_ROOT_USER=xxx
MINIO_ROOT_PASSWORD=xxx

# MINIO_VOLUMES sets the storage volume or path to use for the MinIO server.

MINIO_VOLUMES="/data/minio"

# MINIO_OPTS sets any additional commandline options to pass to the MinIO server.
# For example, `--console-address :9001` sets the MinIO Console listen port
MINIO_OPTS="--console-address :9001"
systemctl daemon-reload
systemctl start minio.service

jdk准备

#apt安装jdk
apt install openjdk-17-jdk
#二进制安装jdk
cd /opt
tar xf jdk-8u212-linux-x64.tar.gz
ln -s jdk1.8.0_212 jdk

jdk环境变量(二进制安装jdk需要配置!!)
vim /etc/profile

export JAVA_HOME=/opt/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar

maven准备

cd /opt
tar xf apache-maven-3.9.10-bin.tar.gz
ln -s apache-maven-3.9.10 maven

maven环境变量配置
vim /etc/profile

export MAVEN_HOME=/opt/maven
export PATH="$MAVEN_HOME/bin:$PATH"

maven配置
在</mirrors>标签中配置
vim maven/conf/settings.xml

...
<mirror>
    <id>aliyunmaven</id>
    <mirrorOf>*</mirrorOf>
    <name>阿里云公共仓库</name>
    <url>https://maven.aliyun.com/repository/public</url>
</mirror>
...

node准备

cd /opt
tar xf node-v18.19.1-linux-x64.tar.gz
ln -s node-v18.19.1-linux-x64 node

配置环境变量
vim /etc/profile

export JAVA_HOME=/opt/jdk
export MAVEN_HOME=/opt/maven
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:/opt/node/bin:$PATH"

加载环境变量配置文件

source /etc/profile

npm配置源

npm get registry
npm config set registry http://registry.npmmirror.com


vim /root/.npmrc

registry=http://registry.npmmirror.com

box-im部署

下载box-im源码

git clone https://gitee.com/bluexsx/box-im.git
cd box-im

导入以下sql

box-im/db
im-platform.sql

修改box-im后端配置文件

vim im-platform/src/main/resources/application-prod.yml

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://x.x.x.x:3306/im_platform?useSSL=false&useUnicode=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true
    username: xxx
    password: xxx
  data:
    redis:
      host: localhost
      port: 6379
      #password: PmEpfRjpBnTN6CgW

minio:
  endpoint: http://127.0.0.1:9000 #内网地址
  domain: https://boxim.upwzz.xyz/file  #外网访问地址
  accessKey: xxx
  secretKey: xxx
  bucketName: box-im
  imagePath: image
  filePath: file
  videoPath: video
  expireIn: 180 # 文件过期时间,单位:天

webrtc:
  max-channel: 9 # 多人通话最大通道数量,最大不能超过16,建议值:4,9,16
  iceServers:   #coturn配置
    - urls: stun:boxim.upwzz.xyz:3478
      username: admin
      credential: UrHHKNvE7nFvBTMV
    - urls: turn:boxim.upwzz.xyz:3478
      username: admin
      credential: UrHHKNvE7nFvBTMV

vim im-server/src/main/resources/application-prod.yml

spring:
  data:
    redis:
      host: 127.0.0.1
      port: 6379
      #      password: PmEpfRjpBnTN6CgW

进入box-im代码根目录,执行

mvn clean package -Dmaven.test.skip=true

将生成的im-platform.jar和im-server.jar拷贝到服务器的/data/boxim目录

启动

cd /data/boxim
# 启动im-platform
nohup java -jar im-platform.jar  --spring.profiles.active=prod &
# 启动im-server
nohup java -jar im-server.jar  --spring.profiles.active=prod &

部署web端
修改im-web的配置文件.env.production (主要是将www.boxim.online换成自己的域名或ip)

vim im-web/.env.production

ENV = 'production'

# app名称
VUE_APP_NAME = "盒子IM"
# 接口地址
VUE_APP_BASE_API  = 'https://boxim.upwzz.xyz/api'
# ws地址
VUE_APP_WS_URL = 'wss://boxim.upwzz.xyz/im'

注意:如有没有部署ssl证书,https需要改成http,wss需要改成ws

在im-web目录进入命令行,执行打包命令

npm install
npm run build

生成的dist目录

nginx准备

安装nginx

apt install nginx

配置nginx
cd /etc/nginx/conf.d
vim boxim.upwzz.xyz.conf

  server {
    listen 443 ssl;
    #listen 80;
    server_name boxim.upwzz.xyz;
    root html;
    index index.html index.htm;
    ssl_certificate /opt/ssl/fullchain.cer;
    ssl_certificate_key /opt/ssl/upwzz.xyz.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;   

    location / {
	    #root   im-web;
      root   /opt/box-im/im-web/dist;
      index  index.html index.htm;
    }

    location /h5 {
      alias   im-h5;
      index  index.html index.htm;
    }
    
    location /admin {
      alias   im-admin;
      index  index.html index.htm;
    	try_files $uri $uri/ /admin/index.html;
    }

    location /api/ {
      proxy_pass http://127.0.0.1:8888;
      rewrite "^/api/(.*)$" /$1 break;
    }
    
    location /adm/api/ {
      proxy_pass http://127.0.0.1:8889;
      rewrite "^/adm/api/(.*)$" /$1 break;
    }
    
    location /file/ {
      proxy_pass http://127.0.0.1:9000;
      rewrite "^/file/(.*)$" /$1 break;
    }

    location = /im {
      proxy_pass        http://127.0.0.1:8878;
      proxy_set_header  Host $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_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }        
  }

  server {
    listen       80;
    server_name  boxim.upwzz.xyz;
    rewrite ^(.*)$ https://$host$1 permanent;
  }

启动nginx

systemctl start nginx.service

部署成功结果
在这里插入图片描述

在这里插入图片描述


网站公告

今日签到

点亮在社区的每一天
去签到