diff --git a/.env b/.env index 4f684ad77e..a1bf4c89ea 100644 --- a/.env +++ b/.env @@ -30,11 +30,18 @@ MINIO_ENDPOINT=http://172.28.0.1:10005 # Base URL for the application programming interface (API). # Default: API_URL=http://172.28.0.1:10002 -API_URL=http://127.0.0.1:10002 +API_URL=http://14.155.86.214:10002 # Directory path for storing data files or related information. # Default: DATA_DIR=./ -DATA_DIR=./ +DATA_DIR=/root/workspaces/openim/Open-IM-Server + +# Choose the appropriate image address, the default is GITHUB image, +# you can choose docker hub, for Chinese users can choose Ali Cloud +# export IMAGE_REGISTRY="ghcr.io/openimsdk" +# export IMAGE_REGISTRY="openim" +# export IMAGE_REGISTRY="registry.cn-hangzhou.aliyuncs.com/openimsdk" +IMAGE_REGISTRY=ghcr.io/openimsdk # ====================================== # ========= Network Configuration ====== diff --git a/Makefile b/Makefile index 02050fe11c..1d3544ed62 100644 --- a/Makefile +++ b/Makefile @@ -73,9 +73,9 @@ gen: demo: @$(MAKE) go.demo -## versionchecker: Check version of openim. ✨ -.PHONY: versionchecker -versionchecker: +## version: Check version of openim. ✨ +.PHONY: version +version: @$(MAKE) go.versionchecker ## build: Build binaries by default ✨ diff --git a/config/config.yaml b/config/config.yaml index 0f980b4e4c..1fbd9e58b3 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -19,6 +19,9 @@ # --| target: config/config.yaml # ----------------------------------------------------------------- +envs: + discovery: zookeeper + ###################### Zookeeper ###################### # Zookeeper configuration # It's not recommended to modify the schema @@ -26,9 +29,6 @@ # Zookeeper address # Zookeeper username # Zookeeper password -envs: - discovery: zookeeper - zookeeper: schema: openim address: [ 172.28.0.1:12181 ] @@ -135,14 +135,14 @@ api: # minio.signEndpoint is minio public network address object: enable: "minio" - apiURL: "http://127.0.0.1:10002" + apiURL: "http://14.155.86.214:10002" minio: bucket: "openim" endpoint: "http://172.28.0.1:10005" accessKeyID: "root" secretAccessKey: "openIM123" sessionToken: '' - signEndpoint: "http://127.0.0.1:10005" + signEndpoint: "http://14.155.86.214:10005" publicRead: false cos: bucketURL: https://temp-1252357374.cos.ap-chengdu.myqcloud.com @@ -168,7 +168,6 @@ rpcPort: openImUserPort: [ 10110 ] openImFriendPort: [ 10120 ] openImMessagePort: [ 10130 ] - openImMessageGatewayPort: [ 10140 ] openImGroupPort: [ 10150 ] openImAuthPort: [ 10160 ] openImPushPort: [ 10170 ] @@ -199,7 +198,7 @@ rpcRegisterName: # Whether to output in json format # Whether to include stack trace in logs log: - storageLocation: ../../logs/ + storageLocation: /root/workspaces/openim/Open-IM-Server/logs/ rotationTime: 24 remainRotationCount: 2 remainLogLevel: 6 @@ -216,8 +215,8 @@ log: # Websocket connection handshake timeout longConnSvr: openImWsPort: [ 10001 ] - openImMessageGatewayPort: [ 10140 ] websocketMaxConnNum: 100000 + openImMessageGatewayPort: [ 10140 ] websocketMaxMsgLen: 4096 websocketTimeout: 10 diff --git a/deployments/README.md b/deployments/README.md index d1ae3e2c10..1e20a9759a 100644 --- a/deployments/README.md +++ b/deployments/README.md @@ -1,52 +1,48 @@ -# OpenIM 应用容器化部署指南 +# OpenIM Application Containerization Deployment Guide -OpenIM 支持很多种集群化部署方式,包括但不限于 helm, sealos, kubeam, kubesphere, kubeflow, kuboard, kubespray, k3s, k3d, k3c, k3sup, k3v, k3x +OpenIM supports a variety of cluster deployment methods, including but not limited to `helm`, `sealos`, `kustomize` -**目前还在开发这个模块,预计 v3.2.0 之前会有一个集群方案。** +Various contributors, as well as previous official releases, have provided some referenceable solutions: -目前各个贡献者,以及之前的官方有出过一些可以参考的方案: ++ [k8s-jenkins Repository](https://github.com/OpenIMSDK/k8s-jenkins) ++ [open-im-server-k8s-deploy Repository](https://github.com/openimsdk/open-im-server-k8s-deploy) ++ [openim-charts Repository](https://github.com/OpenIMSDK/openim-charts) ++ [deploy-openim Repository](https://github.com/showurl/deploy-openim) -- https://github.com/OpenIMSDK/k8s-jenkins -- https://github.com/openimsdk/open-im-server-k8s-deploy -- https://github.com/OpenIMSDK/openim-charts -- https://github.com/showurl/deploy-openim - - -### 依赖检查 +### Dependency Check ```bash Kubernetes: >= 1.16.0-0 Helm: >= 3.0 ``` +### Minimum Configuration -### 最低配置 - -建议生产环境的最低配置如下: +The recommended minimum configuration for a production environment is as follows: -```bash +```yaml CPU: 4 Memory: 8G Disk: 100G ``` -## 生成配置文件 +## Configuration File Generation -我们将自动文件全部自动化处理了,所以生成配置文件对于 openim 来说是可选的,但是如果你想要自定义配置,可以参考下面的步骤: +We have automated all the files, making the generation of configuration files optional for OpenIM. However, if you desire custom configurations, you can follow the steps below: ```bash $ make init -# 或者是使用脚本: +# Alternatively, use script: # ./scripts/init-config.sh ``` -此时会帮你在 `deployments/openim/config` 目录下生成配置文件,你可以根据自己的需求进行修改。 +At this point, configuration files will be generated under `deployments/openim/config`, which you can modify as per your requirements. -## 集群搭建 +## Cluster Setup -如果你已经有了一个 `kubernetes` 集群,或者是你希望自己从头开始搭建一个 `kubernetes` 那么你可以直接跳过这一步。 +If you already have a `kubernetes` cluster, or if you wish to build a `kubernetes` cluster from scratch, you can skip this step. -为了快速开始,我使用 [sealos](https://github.com/labring/sealos) 来快速搭建集群,sealos 底层也是对 kubeadm 的封装: +For a quick start, I used [sealos](https://github.com/labring/sealos) to rapidly set up the cluster, with sealos also being a wrapper for kubeadm at its core: ```bash $ SEALOS_VERSION=`curl -s https://api.github.com/repos/labring/sealos/releases/latest | grep -oE '"tag_name": "[^"]+"' | head -n1 | cut -d'"' -f4` && \ @@ -54,21 +50,20 @@ $ SEALOS_VERSION=`curl -s https://api.github.com/repos/labring/sealos/releases/l sh -s ${SEALOS_VERSION} labring/sealos ``` -**支持的版本:** +**Supported Versions:** + docker: `labring/kubernetes-docker`:(v1.24.0~v1.27.0) + containerd: `labring/kubernetes`:(v1.24.0~v1.27.0) +#### Cluster Installation: -#### 安装集群: - -集群的信息如下: +Cluster details are as follows: -| 机器名 | IP地址 | 系统信息 | -|---------|-----------------|------------------------------------------------------------------------------------------------------------| -| master01| 10.0.0.9 | Linux VM-0-9-ubuntu 5.15.0-76-generic #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux | -| node01 | 10.0.0.4 | Linux VM-0-9-ubuntu 5.15.0-76-generic #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux | -| node02 | 10.0.0.10 | Linux VM-0-9-ubuntu 5.15.0-76-generic #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux | +| Hostname | IP Address | System Info | +| -------- | ---------- | ------------------------------------------------------------ | +| master01 | 10.0.0.9 | `Linux VM-0-9-ubuntu 5.15.0-76-generic #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux` | +| node01 | 10.0.0.4 | Similar to master01 | +| node02 | 10.0.0.10 | Similar to master01 | ```bash $ export CLUSTER_USERNAME=ubuntu @@ -80,50 +75,41 @@ $ sudo sealos run labring/kubernetes:v1.25.0 labring/helm:v3.8.2 labring/calico: -p "$CLUSTER_PASSWORD" ``` -> **Node** -> 卸载的方式:使用 `kubeadm` 卸载并不会清除 `etcd` 和 `cni` 相关,所以需要手动清除,或者使用 `sealos` 卸载。 +> **Node** Uninstallation method: using `kubeadm` for uninstallation does not remove `etcd` and `cni` related configurations. Manual clearance or using `sealos` for uninstallation is needed. +> > ```bash -> sealos reset +> $ sealos reset > ``` -### 安装 helm +### Installing helm -helm通过打包的方式,支持发布的版本管理和控制,很大程度上简化了Kubernetes应用的部署和管理。 +Helm simplifies the deployment and management of Kubernetes applications to a large extent by offering version control and release management through packaging. - -**使用脚本:** +**Using Script:** ```bash $ curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash ``` -**Helm Version:** - -```bash -$ helm version -version.BuildInfo{Version:"v3.13.1", GitCommit:"3547a4b5bf5edb5478ce352e18858d8a552a4110", GitTreeState:"clean", GoVersion:"go1.20.8"} -`` - -**添加仓库:** +**Adding Repository:** ```bash $ helm repo add brigade https://openimsdk.github.io/openim-charts ``` -### OpenIM 的镜像策略 +### OpenIM Image Strategy -自动化提供的 aliyun, ghcr, docker hub: https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/images.md +Automated offerings include aliyun, ghcr, docker hub: [Image Documentation](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/images.md) -**本地化测试构建方法:** +**Local Test Build Method:** ```bash $ make image ``` +> This command assists in quickly building the required images locally. For a detailed build strategy, refer to the [Build Documentation](https://github.com/openimsdk/open-im-server/blob/main/build/README.md). -### 容器化安装 +## Installation -具体安装步骤如下: +Explore our Helm-Charts repository and read through: [Helm-Charts Repository](https://github.com/openimsdk/helm-charts) -> **Note** -> 针对中国的用户,阅读我们的 [Docker 镜像标准](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/images.md) 以便使用国内 aliyun 的镜像地址。OpenIM 也有针对中国的 gitee 同步仓库,你可以在 [gitee.com](https://gitee.com/openimsdk) 上找到它。 \ No newline at end of file diff --git a/deployments/templates/init/README.md b/deployments/templates/init/README.md deleted file mode 100644 index b9957dadc1..0000000000 --- a/deployments/templates/init/README.md +++ /dev/null @@ -1,220 +0,0 @@ -# Systemd Configuration, Installation, and Startup - -- [Systemd Configuration, Installation, and Startup](#systemd-configuration-installation-and-startup) - - [1. Introduction](#1-introduction) - - [2. Prerequisites (Requires root permissions)](#2-prerequisites-requires-root-permissions) - - [3. Create `openim-api` systemd unit template file](#3-create-openim-api-systemd-unit-template-file) - - [4. Copy systemd unit template file to systemd config directory (Requires root permissions)](#4-copy-systemd-unit-template-file-to-systemd-config-directory-requires-root-permissions) - - [5. Start systemd service](#5-start-systemd-service) - -## 1. Introduction - -Systemd is the default service management form for the latest Linux distributions, replacing the original init. - -Format introduction: - -```bash -[Unit] : Unit of the service - -Description: Brief description of the service - -[Service]: Configuration of the service's runtime behavior - -ExecStart: Complete path of the program - -Restart: Restart configurations like no, always, on-success, on-failure, on-abnormal, on-abort, on-watchdog - -[Install]: Installation configuration - -WantedBy: Multi-user, etc. -``` - -For more details, refer to: [Systemd Service Manual](https://www.freedesktop.org/software/systemd/man/systemd.service.html) - -Starting command: - -```bash -systemctl daemon-reload && systemctl enable openim-api && systemctl restart openim-api -``` - -Service status: - -```bash -systemctl status openim-api -``` - -Stop command: - -```bash -systemctl stop openim-api -``` - -More command: -```bash -# 列出正在运行的Unit,可以直接使用systemctl -systemctl list-units - -# 列出所有Unit,包括没有找到配置文件的或者启动失败的 -systemctl list-units --all - -# 列出所有没有运行的 Unit -systemctl list-units --all --state=inactive - -# 列出所有加载失败的 Unit -systemctl list-units --failed - -# 列出所有正在运行的、类型为service的Unit -systemctl list-units --type=service - -# 显示某个 Unit 是否正在运行 -systemctl is-active application.service - -# 显示某个 Unit 是否处于启动失败状态 -systemctl is-failed application.service - -# 显示某个 Unit 服务是否建立了启动链接 -systemctl is-enabled application.service - -# 立即启动一个服务 -sudo systemctl start apache.service - -# 立即停止一个服务 -sudo systemctl stop apache.service - -# 重启一个服务 -sudo systemctl restart apache.service - -# 重新加载一个服务的配置文件 -sudo systemctl reload apache.service - -# 重载所有修改过的配置文件 -sudo systemctl daemon-reload -``` - -**Why choose systemd?** - -**Advanced requirements:** - -- Convenient service runtime log recording for problem analysis -- Service management logs -- Option to restart upon abnormal exit - -The daemon does not meet these advanced requirements. - -`nohup` only logs the service's runtime outputs and errors. - -Only systemd can fulfill all of the above requirements. - -> The default logs are enhanced with timestamps, usernames, service names, PIDs, etc., making them user-friendly. You can view logs of abnormal service exits. Advanced customization is possible through the configuration files in `/lib/systemd/system/`. - -In short, systemd is the current mainstream way to manage backend services on Linux, so I've abandoned `nohup` in my new versions of bash scripts, opting instead for systemd. - -## 2. Prerequisites (Requires root permissions) - -1. Configure `environment.sh` based on the comments. -2. Create a data directory: - -```bash -mkdir -p ${OPENIM_DATA_DIR}/{openim-api,openim-crontask} -``` - -3. Create a bin directory and copy `openim-api` and `openim-crontask` executable files: - -```bash -source ./environment.sh -mkdir -p ${OPENIM_INSTALL_DIR}/bin -cp openim-api openim-crontask ${OPENIM_INSTALL_DIR}/bin -``` - -4. Copy the configuration files of `openim-api` and `openim-crontask` to the `${OPENIM_CONFIG_DIR}` directory: - -```bash -mkdir -p ${OPENIM_CONFIG_DIR} -cp openim-api.yaml openim-crontask.yaml ${OPENIM_CONFIG_DIR} -``` - -## 3. Create `openim-api` systemd unit template file - -For each OpenIM service, we will create a systemd unit template. Follow the steps below for each service: - -Run the following shell script to generate the `openim-api.service.template`: - -```bash -source ./environment.sh -cat > openim-api.service.template < $service.service.template < ${OPENIM_CONFIG_DIR}/config.yaml" + openim::util::check_ports ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]} - openim::msggateway::install || return 1 - openim::msgtransfer::install || return 1 - openim::push::install || return 1 - openim::rpc::install || return 1 - openim::crontask::install || return 1 - openim::api::install || return 1 + ${OPENIM_ROOT}/scripts/install/openim-msggateway.sh openim::msggateway::install || return 1 + ${OPENIM_ROOT}/scripts/install/openim-msgtransfer.sh openim::msgtransfer::install || return 1 + ${OPENIM_ROOT}/scripts/install/openim-push.sh openim::push::install || return 1 + ${OPENIM_ROOT}/scripts/install/openim-crontask.sh openim::crontask::install || return 1 + ${OPENIM_ROOT}/scripts/install/openim-rpc.sh openim::rpc::install || return 1 + ${OPENIM_ROOT}/scripts/install/openim-api.sh openim::api::install || return 1 openim::log::success "openim install success" } @@ -96,12 +96,12 @@ function openim::uninstall::uninstall_openim() { openim::log::info "uninstall openim" - openim::msggateway::uninstall || return 1 - openim::msgtransfer::uninstall || return 1 - openim::push::uninstall || return 1 - openim::rpc::uninstall || return 1 - openim::crontask::uninstall || return 1 - openim::api::uninstall || return 1 + ${OPENIM_ROOT}/scripts/install/openim-msggateway.sh openim::msggateway::uninstall || return 1 + ${OPENIM_ROOT}/scripts/install/openim-msgtransfer.sh openim::msgtransfer::uninstall || return 1 + ${OPENIM_ROOT}/scripts/install/openim-push.sh openim::push::uninstall || return 1 + ${OPENIM_ROOT}/scripts/install/openim-crontask.sh openim::crontask::uninstall || return 1 + ${OPENIM_ROOT}/scripts/install/openim-rpc.sh openim::rpc::uninstall || return 1 + ${OPENIM_ROOT}/scripts/install/openim-api.sh openim::api::uninstall || return 1 openim::log::success "openim uninstall success" } @@ -110,12 +110,12 @@ function openim::install::status() { openim::log::info "check openim status" - openim::msggateway::status || return 1 - openim::msgtransfer::status || return 1 - openim::push::status || return 1 - openim::rpc::status || return 1 - openim::crontask::status || return 1 - openim::api::status || return 1 + ${OPENIM_ROOT}/scripts/install/openim-msggateway.sh openim::msggateway::status || return 1 + ${OPENIM_ROOT}/scripts/install/openim-msgtransfer.sh openim::msgtransfer::status || return 1 + ${OPENIM_ROOT}/scripts/install/openim-push.sh openim::push::status || return 1 + ${OPENIM_ROOT}/scripts/install/openim-crontask.sh openim::crontask::status || return 1 + ${OPENIM_ROOT}/scripts/install/openim-rpc.sh openim::rpc::status || return 1 + ${OPENIM_ROOT}/scripts/install/openim-api.sh openim::api::status || return 1 openim::log::success "openim status success" } diff --git a/scripts/install/openim-api.sh b/scripts/install/openim-api.sh index 5239b95e7d..a2d40b7774 100755 --- a/scripts/install/openim-api.sh +++ b/scripts/install/openim-api.sh @@ -92,21 +92,70 @@ function openim::api::start_service() { ###################################### Linux Systemd ###################################### SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" +# Print the necessary information after installation +function openim::api::info() { +cat << EOF +openim-api listen on: ${OPENIM_API_HOST}:${API_OPENIM_PORT} +EOF +} + +# install openim-api function openim::api::install() { openim::log::info "Installing ${SERVER_NAME} ..." + + pushd "${OPENIM_ROOT}" + + # 1. Build openim-api + make build BINS=${SERVER_NAME} + openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}" + openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}" + + # 2. Generate and install the openim-api configuration file (config) + openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/config.yaml" + + # 3. Create and install the ${SERVER_NAME} systemd unit file + echo ${LINUX_PASSWORD} | sudo -S bash -c \ + "SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}" + openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}" + + # 4. Start the openim-api service + openim::common::sudo "systemctl daemon-reload" + openim::common::sudo "systemctl restart ${SERVER_NAME}" + openim::common::sudo "systemctl enable ${SERVER_NAME}" + openim::api::status || return 1 + openim::api::info + + openim::log::info "install ${SERVER_NAME} successfully" + popd } +# Unload function openim::api::uninstall() { openim::log::info "Uninstalling ${SERVER_NAME} ..." + set +o errexit + openim::common::sudo "systemctl stop ${SERVER_NAME}" + openim::common::sudo "systemctl disable ${SERVER_NAME}" + openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}" + openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml" + openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service" + set -o errexit + openim::log::info "uninstall ${SERVER_NAME} successfully" } +# Status Check function openim::api::status() { openim::log::info "Checking ${SERVER_NAME} status ..." + # Check the running status of the ${SERVER_NAME}. If active (running) is displayed, the ${SERVER_NAME} is started successfully. + systemctl status ${SERVER_NAME}|grep -q 'active' || { + openim::log::error "${SERVER_NAME} failed to start, maybe not installed properly" + return 1 + } + openim::util::check_ports ${OPENIM_API_PORT_LISTARIES[@]} } if [[ "$*" =~ openim::api:: ]];then - eval $* -fi \ No newline at end of file + eval $* +fi diff --git a/scripts/install/openim-crontask.sh b/scripts/install/openim-crontask.sh index 455dafa8bc..49e018ad19 100755 --- a/scripts/install/openim-crontask.sh +++ b/scripts/install/openim-crontask.sh @@ -51,7 +51,7 @@ function openim::crontask::start() openim::util::stop_services_with_name ${OPENIM_CRONTASK_BINARY} openim::log::status "start cron_task process, path: ${OPENIM_CRONTASK_BINARY}" - nohup ${OPENIM_CRONTASK_BINARY} >> ${LOG_FILE} 2>&1 & + nohup ${OPENIM_CRONTASK_BINARY} -c ${OPENIM_PUSH_CONFIG} >> ${LOG_FILE} 2>&1 & openim::util::check_process_names ${SERVER_NAME} } @@ -72,18 +72,16 @@ function openim::crontask::install() # 1. Build openim-crontask make build BINS=${SERVER_NAME} - openim::common::sudo "cp ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/bin" - openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}" + openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}" + openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}" # 2. Generate and install the openim-crontask configuration file (openim-crontask.yaml) - echo ${LINUX_PASSWORD} | sudo -S bash -c \ - "./scripts/genconfig.sh ${ENV_FILE} deployments/templates/${SERVER_NAME}.yaml > ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml" - openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml" + openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/config.yaml" # 3. Create and install the ${SERVER_NAME} systemd unit file echo ${LINUX_PASSWORD} | sudo -S bash -c \ - "./scripts/genconfig.sh ${ENV_FILE} deployments/templates/init/${SERVER_NAME}.service > ${SYSTEM_FILE_PATH}" + "SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}" openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}" # 4. Start the openim-crontask service @@ -104,7 +102,7 @@ function openim::crontask::uninstall() set +o errexit openim::common::sudo "systemctl stop ${SERVER_NAME}" openim::common::sudo "systemctl disable ${SERVER_NAME}" - openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}" + openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}" openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml" openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service" set -o errexit @@ -115,15 +113,11 @@ function openim::crontask::uninstall() function openim::crontask::status() { # Check the running status of the ${SERVER_NAME}. If active (running) is displayed, the ${SERVER_NAME} is started successfully. - systemctl status ${SERVER_NAME}|grep -q 'active' || { + if systemctl is-active --quiet "${SERVER_NAME}"; then + openim::log::info "${SERVER_NAME} is running successfully." + else openim::log::error "${SERVER_NAME} failed to start, maybe not installed properly" return 1 - } - - # The listening port is hardcode in the configuration file - if echo | telnet 127.0.0.1 7070 2>&1|grep refused &>/dev/null;then - openim::log::error "cannot access health check port, ${SERVER_NAME} maybe not startup" - return 1 fi } diff --git a/scripts/install/openim-msggateway.sh b/scripts/install/openim-msggateway.sh index 612b7ae16a..79aa6fa15b 100755 --- a/scripts/install/openim-msggateway.sh +++ b/scripts/install/openim-msggateway.sh @@ -74,7 +74,7 @@ SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" # Print the necessary information after installation function openim::msggateway::info() { cat << EOF -openim-msggateway listen on: ${OPENIM_MSGGATEWAY_HOST} +openim-msggateway listen on: ${OPENIM_MSGGATEWAY_HOST}:${OPENIM_MESSAGE_GATEWAY_PORT} EOF } @@ -85,18 +85,15 @@ function openim::msggateway::install() # 1. Build openim-msggateway make build BINS=${SERVER_NAME} - openim::common::sudo "cp ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/bin" - - openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}" + openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}" + openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}" # 2. Generate and install the openim-msggateway configuration file (openim-msggateway.yaml) - echo ${LINUX_PASSWORD} | sudo -S bash -c \ - "./scripts/genconfig.sh ${ENV_FILE} deployments/templates/${SERVER_NAME}.yaml > ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml" - openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml" + # nono # 3. Create and install the ${SERVER_NAME} systemd unit file echo ${LINUX_PASSWORD} | sudo -S bash -c \ - "./scripts/genconfig.sh ${ENV_FILE} deployments/templates/init/${SERVER_NAME}.service > ${SYSTEM_FILE_PATH}" + "SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}" openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}" # 4. Start the openim-msggateway service @@ -117,7 +114,7 @@ function openim::msggateway::uninstall() set +o errexit openim::common::sudo "systemctl stop ${SERVER_NAME}" openim::common::sudo "systemctl disable ${SERVER_NAME}" - openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}" + openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}" openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml" openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service" set -o errexit @@ -134,7 +131,7 @@ function openim::msggateway::status() } # The listening port is hardcode in the configuration file - if echo | telnet 127.0.0.1 7070 2>&1|grep refused &>/dev/null;then + if echo | telnet ${OPENIM_MSGGATEWAY_HOST} ${OPENIM_MESSAGE_GATEWAY_PORT} 2>&1|grep refused &>/dev/null;then openim::log::error "cannot access health check port, ${SERVER_NAME} maybe not startup" return 1 fi diff --git a/scripts/install/openim-msgtransfer.sh b/scripts/install/openim-msgtransfer.sh index 51ac788508..b28ca7efab 100755 --- a/scripts/install/openim-msgtransfer.sh +++ b/scripts/install/openim-msgtransfer.sh @@ -95,18 +95,18 @@ function openim::msgtransfer::install() # 1. Build openim-msgtransfer make build BINS=${SERVER_NAME} - openim::common::sudo "cp ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/bin" + + openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}" + openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}" openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}" # 2. Generate and install the openim-msgtransfer configuration file (openim-msgtransfer.yaml) - echo ${LINUX_PASSWORD} | sudo -S bash -c \ - "./scripts/genconfig.sh ${ENV_FILE} deployments/templates/${SERVER_NAME}.yaml > ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml" - openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml" + # nono # 3. Create and install the ${SERVER_NAME} systemd unit file echo ${LINUX_PASSWORD} | sudo -S bash -c \ - "./scripts/genconfig.sh ${ENV_FILE} deployments/templates/init/${SERVER_NAME}.service > ${SYSTEM_FILE_PATH}" + "SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}" openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}" # 4. Start the openim-msgtransfer service @@ -127,7 +127,7 @@ function openim::msgtransfer::uninstall() set +o errexit openim::common::sudo "systemctl stop ${SERVER_NAME}" openim::common::sudo "systemctl disable ${SERVER_NAME}" - openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}" + openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}" openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml" openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service" set -o errexit @@ -138,15 +138,11 @@ function openim::msgtransfer::uninstall() function openim::msgtransfer::status() { # Check the running status of the ${SERVER_NAME}. If active (running) is displayed, the ${SERVER_NAME} is started successfully. - systemctl status ${SERVER_NAME}|grep -q 'active' || { + if systemctl is-active --quiet "${SERVER_NAME}"; then + openim::log::info "${SERVER_NAME} is running successfully." + else openim::log::error "${SERVER_NAME} failed to start, maybe not installed properly" return 1 - } - - # The listening port is hardcode in the configuration file - if echo | telnet 127.0.0.1 7070 2>&1|grep refused &>/dev/null;then - openim::log::error "cannot access health check port, ${SERVER_NAME} maybe not startup" - return 1 fi } diff --git a/scripts/install/openim-push.sh b/scripts/install/openim-push.sh index 9b1d4d53f1..5197c9948f 100755 --- a/scripts/install/openim-push.sh +++ b/scripts/install/openim-push.sh @@ -83,7 +83,7 @@ SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" # Print the necessary information after installation function openim::push::info() { cat << EOF -openim-push listen on: ${OPENIM_PUSH_HOST} +openim-push listen on: ${OPENIM_PUSH_HOST}:${OPENIM_PUSH_PORT} EOF } @@ -94,18 +94,15 @@ function openim::push::install() # 1. Build openim-push make build BINS=${SERVER_NAME} - openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/bin" + openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}" + openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}" - openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}" - - # 2. Generate and install the openim-push configuration file (openim-push.yaml) - echo ${LINUX_PASSWORD} | sudo -S bash -c \ - "./scripts/genconfig.sh ${ENV_FILE} deployments/templates/${SERVER_NAME}.yaml > ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml" - openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml" + # 2. Generate and install the openim-push configuration file (config) + openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/config.yaml" # 3. Create and install the ${SERVER_NAME} systemd unit file echo ${LINUX_PASSWORD} | sudo -S bash -c \ - "./scripts/genconfig.sh ${ENV_FILE} deployments/templates/init/${SERVER_NAME}.service > ${SYSTEM_FILE_PATH}" + "SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}" openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}" # 4. Start the openim-push service @@ -125,7 +122,7 @@ function openim::push::uninstall() set +o errexit openim::common::sudo "systemctl stop ${SERVER_NAME}" openim::common::sudo "systemctl disable ${SERVER_NAME}" - openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}" + openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}" openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml" openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service" set -o errexit @@ -142,7 +139,7 @@ function openim::push::status() } # The listening port is hardcode in the configuration file - if echo | telnet 127.0.0.1 7071 2>&1|grep refused &>/dev/null;then # Assuming a different port for push + if echo | telnet ${OPENIM_MSGGATEWAY_HOST} ${OPENIM_PUSH_PORT} 2>&1|grep refused &>/dev/null;then # Assuming a different port for push openim::log::error "cannot access health check port, ${SERVER_NAME} maybe not startup" return 1 fi diff --git a/scripts/install/openim-rpc.sh b/scripts/install/openim-rpc.sh index a0a7868f1b..d6000b0932 100755 --- a/scripts/install/openim-rpc.sh +++ b/scripts/install/openim-rpc.sh @@ -160,26 +160,86 @@ function openim::rpc::start_service() { } ###################################### Linux Systemd ###################################### -SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" - -function openim::rpc::install() { - openim::log::info "Installing ${SERVER_NAME} ..." +declare -A SYSTEM_FILE_PATHS +for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do + SYSTEM_FILE_PATHS["$service"]="/etc/systemd/system/${service}.service" +done + +# Print the necessary information after installation +function openim::rpc::info() { + for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do + echo "${service} listen on: ${OPENIM_RPC_PORT_LISTARIES[@]}" + done } -function openim::rpc::uninstall() { - openim::log::info "Uninstalling ${SERVER_NAME} ..." +# install openim-rpc +function openim::rpc::install() +{ + pushd "${OPENIM_ROOT}" -} + # 1. Build openim-rpc + for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do + make build BINS=${service} + openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${service} ${OPENIM_INSTALL_DIR}/${service}" + openim::log::status "${service} binary: ${OPENIM_INSTALL_DIR}/${service}/${service}" + done -function openim::rpc::status() { - openim::log::info "Checking ${SERVER_NAME} status ..." + # 2. Generate and install the openim-rpc configuration file (config) + openim::log::status "openim-rpc config file: ${OPENIM_CONFIG_DIR}/config.yaml" - openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]} - # openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]} + # 3. Create and install the systemd unit files + for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do + echo ${LINUX_PASSWORD} | sudo -S bash -c \ + "SERVER_NAME=${service} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATHS[$service]}" + openim::log::status "${service} systemd file: ${SYSTEM_FILE_PATHS[$service]}" + done - openim::util::check_process_names ${SERVER_NAME} + # 4. Start the openim-rpc services + openim::common::sudo "systemctl daemon-reload" + for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do + openim::common::sudo "systemctl restart ${service}" + openim::common::sudo "systemctl enable ${service}" + done + openim::rpc::status || return 1 + openim::rpc::info + + openim::log::info "install openim-rpc successfully" + popd +} + +# Unload +function openim::rpc::uninstall() +{ + set +o errexit + for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do + openim::common::sudo "systemctl stop ${service}" + openim::common::sudo "systemctl disable ${service}" + openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${service}" + openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${service}.yaml" + openim::common::sudo "rm -f ${SYSTEM_FILE_PATHS[$service]}" + done + set -o errexit + openim::log::info "uninstall openim-rpc successfully" +} + +# Status Check +function openim::rpc::status() +{ + for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do + # Check the running status of the ${service}. If active (running) is displayed, the ${service} is started successfully. + systemctl status ${service}|grep -q 'active' || { + openim::log::error "${service} failed to start, maybe not installed properly" + return 1 + } + + # The listening port is hardcoded in the configuration file + if echo | telnet ${OPENIM_MSGGATEWAY_HOST} ${OPENIM_RPC_PORT_LISTARIES[@]} 2>&1|grep refused &>/dev/null;then + openim::log::error "cannot access health check port, ${service} maybe not startup" + return 1 + fi + done } if [[ "$*" =~ openim::rpc:: ]];then - eval $* -fi \ No newline at end of file + eval $* +fi diff --git a/tools/infra/infra.go b/tools/infra/infra.go index cc20a17c7f..f8d8c75223 100644 --- a/tools/infra/infra.go +++ b/tools/infra/infra.go @@ -1,29 +1,25 @@ -// Copyright © 2023 OpenIM. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package main import ( "fmt" - "log" + + "github.com/fatih/color" ) +// 定义一个函数以打印重要的链接信息 +func printLinks() { + blue := color.New(color.FgBlue).SprintFunc() + fmt.Printf("OpenIM Github: %s\n", blue("https://github.com/OpenIMSDK/Open-IM-Server")) + fmt.Printf("Slack Invitation: %s\n", blue("https://openimsdk.slack.com")) +} + func main() { - log.Println("Current module is still under development.") - message := ` -Current module is still under development. + yellow := color.New(color.FgYellow) + blue := color.New(color.FgBlue, color.Bold) + + yellow.Println("Current module is still under development.") + message := ` ____ _____ __ __ / __ \ |_ _|| \/ | | | | | _ __ ___ _ __ | | | \ / | @@ -36,5 +32,6 @@ ____ _____ __ __ Keep checking for updates! ` - fmt.Println(message) + blue.Println(message) + printLinks() // 调用函数以打印链接信息 } diff --git a/tools/versionchecker/versionchecker.go b/tools/versionchecker/versionchecker.go index e7bc3e3791..b8b04c723c 100644 --- a/tools/versionchecker/versionchecker.go +++ b/tools/versionchecker/versionchecker.go @@ -20,9 +20,12 @@ import ( "os/exec" "runtime" "time" + + "github.com/fatih/color" + "github.com/openimsdk/open-im-server/v3/pkg/common/version" ) -func executeCommand(cmdName string, args ...string) (string, error) { +func ExecuteCommand(cmdName string, args ...string) (string, error) { cmd := exec.Command(cmdName, args...) var out bytes.Buffer var stderr bytes.Buffer @@ -31,19 +34,15 @@ func executeCommand(cmdName string, args ...string) (string, error) { err := cmd.Run() if err != nil { - return "", fmt.Errorf("Error executing %s: %v", cmdName, err) + return "", fmt.Errorf("error executing %s: %v, stderr: %s", cmdName, err, stderr.String()) } return out.String(), nil } func printTime() string { currentTime := time.Now() - - // 使用 Format 函数以优雅的方式格式化日期和时间 - // 2006-01-02 15:04:05 是 Go 中的标准时间格式 formattedTime := currentTime.Format("2006-01-02 15:04:05") - - return fmt.Sprintf("Current Date & Time:", formattedTime) + return fmt.Sprintf("Current Date & Time: %s", formattedTime) } func getGoVersion() string { @@ -54,7 +53,7 @@ func getGoVersion() string { } func getDockerVersion() string { - version, err := executeCommand("docker", "--version") + version, err := ExecuteCommand("docker", "--version") if err != nil { return "Docker is not installed. Please install it to get the version." } @@ -62,7 +61,7 @@ func getDockerVersion() string { } func getDockerComposeVersion() string { - version, err := executeCommand("docker-compose", "--version") + version, err := ExecuteCommand("docker-compose", "--version") if err != nil { return "Docker Compose is not installed. Please install it to get the version." } @@ -70,7 +69,7 @@ func getDockerComposeVersion() string { } func getKubernetesVersion() string { - version, err := executeCommand("kubectl", "version", "--client", "--short") + version, err := ExecuteCommand("kubectl", "version", "--client", "--short") if err != nil { return "Kubernetes is not installed. Please install it to get the version." } @@ -78,7 +77,7 @@ func getKubernetesVersion() string { } func getGitVersion() string { - version, err := executeCommand("git", "branch", "--show-current") + version, err := ExecuteCommand("git", "branch", "--show-current") if err != nil { return "Git is not installed. Please install it to get the version." } @@ -88,28 +87,42 @@ func getGitVersion() string { // NOTE: You'll need to provide appropriate commands for OpenIM versions. func getOpenIMServerVersion() string { // Placeholder - return "OpenIM Server: v3.2" + openimVersion := version.GetSingleVersion() + return "OpenIM Server: " + openimVersion + "\n" } -func getOpenIMClientVersion() string { - // Placeholder - return "OpenIM Client: v3.2" +func getOpenIMClientVersion() (string, error) { + openIMClientVersion, err := version.GetClientVersion() + if err != nil { + return "", err + } + return "OpenIM Client: " + openIMClientVersion.ClientVersion + "\n", nil } func main() { - fmt.Println(printTime()) - fmt.Println("# Diagnostic Tool Result\n") - fmt.Println("## Go Version") + red := color.New(color.FgRed).SprintFunc() + green := color.New(color.FgGreen).SprintFunc() + blue := color.New(color.FgBlue).SprintFunc() + yellow := color.New(color.FgYellow).SprintFunc() + + fmt.Println(green(printTime())) + fmt.Println(yellow("# Diagnostic Tool Result\n")) + fmt.Println(blue("## Go Version")) fmt.Println(getGoVersion()) - fmt.Println("## Branch Type") + fmt.Println(blue("## Branch Type")) fmt.Println(getGitVersion()) - fmt.Println("## Docker Version") + fmt.Println(blue("## Docker Version")) fmt.Println(getDockerVersion()) - fmt.Println("## Docker Compose Version") + fmt.Println(blue("## Docker Compose Version")) fmt.Println(getDockerComposeVersion()) - fmt.Println("## Kubernetes Version") + fmt.Println(blue("## Kubernetes Version")) fmt.Println(getKubernetesVersion()) - fmt.Println("## OpenIM Versions") + fmt.Println(blue("## OpenIM Versions")) fmt.Println(getOpenIMServerVersion()) - fmt.Println(getOpenIMClientVersion()) -} + // clientVersion, err := getOpenIMClientVersion() + // if err != nil { + // fmt.Println(red("Error getting OpenIM Client Version: "), err) + // } else { + // fmt.Println(clientVersion) + // } +} \ No newline at end of file