feat: add config path config

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
Xinwei Xiong(cubxxw-openim)
2023-08-11 21:19:19 +08:00
parent d9e4899da5
commit 2d035f0029
18 changed files with 822 additions and 168 deletions
+185 -80
View File
@@ -13,107 +13,212 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# This is a file that initializes variables for the automation script that initializes the config file
# You need to supplement the script according to the specification.
# Read: https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/init_config.md
OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
# 生成文件存放目录
LOCAL_OUTPUT_ROOT="${OPENIM_ROOT}/${OUT_DIR:-_output}"
# 定义只读变量,如果变量未定义,则使用默认值
function def() {
local var_name="$1"
local default_value="$2"
eval "readonly $var_name=\${$var_name:-$default_value}"
}
# app要能访问到此ip和端口或域名
readonly API_URL=${API_URL:-http://127.0.0.1:10002/object/}
readonly DATA_DIR=${DATA_DIR:-${OPENIM_ROOT}}
def "API_URL" "http://127.0.0.1:10002/object/"
def "DATA_DIR" "${OPENIM_ROOT}"
# 设置统一的用户名,方便记忆
readonly USER=${USER:-'root'} # Setting a username
def "USER" "root"
# 设置统一的密码,方便记忆
readonly PASSWORD=${PASSWORD:-'openIM123'} # Setting a password
def "PASSWORD" "openIM123"
# Linux系统 openim 用户
readonly LINUX_USERNAME=${LINUX_USERNAME:-openim}
# Linux root & openim 用户密码
readonly LINUX_PASSWORD=${LINUX_PASSWORD:-${PASSWORD}}
def "LINUX_USERNAME" "openim"
def "LINUX_PASSWORD" "${PASSWORD}"
# 设置安装目录
readonly INSTALL_DIR=${INSTALL_DIR:-/tmp/installation}
def "INSTALL_DIR" "${LOCAL_OUTPUT_ROOT}/installs"
mkdir -p ${INSTALL_DIR}
readonly ENV_FILE=${OPENIM_ROOT}/scripts/install/environment.sh
# MINIO 配置信息
readonly OBJECT_ENABLE=${OBJECT_ENABLE:-minio}
readonly OBJECT_APIURL=${OBJECT_APIURL:-http://127.0.0.1:10002/object/}
readonly MINIO_BUCKET=${MINIO_BUCKET:-openim}
readonly MINIO_ENDPOINT=${MINIO_ENDPOINT:-http://127.0.0.1:10005}
readonly MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY:-root}
readonly MINIO_SECRET_KEY=${MINIO_SECRET_KEY:-openIM123}
readonly COS_BUCKET_URL=${COS_BUCKET_URL:-https://temp-1252357374.cos.ap-chengdu.myqcloud.com}
readonly OSS_ENDPOINT=${OSS_ENDPOINT:-http://oss-cn-chengdu.aliyuncs.com}
readonly OSS_BUCKET=${OSS_BUCKET:-demo-9999999}
readonly OSS_BUCKET_URL=${OSS_BUCKET_URL:-https://demo-9999999.oss-cn-chengdu.aliyuncs.com}
readonly OSS_ACCESS_KEY_ID=${OSS_ACCESS_KEY_ID:-root}
def "ENV_FILE" "${OPENIM_ROOT}/scripts/install/environment.sh"
# MariaDB 配置信息
readonly MARIADB_ADMIN_USERNAME=${MARIADB_ADMIN_USERNAME:-root} # MariaDB root 用户
readonly MARIADB_ADMIN_PASSWORD=${MARIADB_ADMIN_PASSWORD:-${PASSWORD}} # MariaDB root 用户密码
readonly MARIADB_HOST=${MARIADB_HOST:-127.0.0.1:3306} # MariaDB 主机地址
readonly MARIADB_DATABASE=${MARIADB_DATABASE:-openim} # MariaDB openim 应用使用的数据库名
readonly MARIADB_USERNAME=${MARIADB_USERNAME:-openim} # openim 数据库用户名
readonly MARIADB_PASSWORD=${MARIADB_PASSWORD:-${PASSWORD}} # openim 数据库密码
###################### Zookeeper 配置信息 ######################
def "ZOOKEEPER_SCHEMA" "openim" # Zookeeper的模式
def "ZOOKEEPER_ADDRESS" "127.0.0.1:2181" # Zookeeper的地址
def "ZOOKEEPER_USERNAME" "" # Zookeeper的用户名
def "ZOOKEEPER_PASSWORD" "" # Zookeeper的密码
# Redis 配置信息
readonly REDIS_HOST=${REDIS_HOST:-127.0.0.1} # Redis 主机地址
readonly REDIS_PORT=${REDIS_PORT:-6379} # Redis 监听端口
readonly REDIS_USERNAME=${REDIS_USERNAME:-''} # Redis 用户名
readonly REDIS_PASSWORD=${REDIS_PASSWORD:-${PASSWORD}} # Redis 密码
###################### MySQL 配置信息 ######################
def "MYSQL_ADDRESS" "127.0.0.1:13306" # MySQL的地址
def "MYSQL_USERNAME" "root" # MySQL的用户名
def "MYSQL_PASSWORD" "openIM123" # MySQL的密码
def "MYSQL_DATABASE" "openIM_v3" # MySQL的数据库名
def "MYSQL_MAX_OPEN_CONN" "1000" # 最大打开的连接数
def "MYSQL_MAX_IDLE_CONN" "100" # 最大空闲连接数
def "MYSQL_MAX_LIFETIME" "60" # 连接可以重用的最大生命周期(秒)
def "MYSQL_LOG_LEVEL" "4" # 日志级别
def "MYSQL_SLOW_THRESHOLD" "500" # 慢查询阈值(毫秒)
###################### MongoDB 配置信息 ######################
def "MONGO_URI" "" # MongoDB的URI
def "MONGO_ADDRESS" "127.0.0.1:37017" # MongoDB的地址
def "MONGO_DATABASE" "openIM_v3" # MongoDB的数据库名
def "MONGO_USERNAME" "root" # MongoDB的用户名
def "MONGO_PASSWORD" "openIM123" # MongoDB的密码
def "MONGO_MAX_POOL_SIZE" "100" # 最大连接池大小
###################### Object 配置信息 ######################
def "OBJECT_ENABLE" "minio" # 对象是否启用
def "OBJECT_APIURL" "http://127.0.0.1:10002/object/" # 对象的API地址
def "MINIO_BUCKET" "openim" # MinIO的存储桶名称
def "MINIO_ENDPOINT" "http://127.0.0.1:10005" # MinIO的端点URL
def "MINIO_ACCESS_KEY" "root" # MinIO的访问密钥ID
def "MINIO_SECRET_KEY" "openIM123" # MinIO的密钥
def "MINIO_SESSION_TOKEN" "" # MinIO的会话令牌
def "COS_BUCKET_URL" "https://temp-1252357374.cos.ap-chengdu.myqcloud.com" # 腾讯云COS的存储桶URL
def "COS_SECRET_ID" "" # 腾讯云COS的密钥ID
def "COS_SECRET_KEY" "" # 腾讯云COS的密钥
def "COS_SESSION_TOKEN" "" # 腾讯云COS的会话令牌
def "OSS_ENDPOINT" "https://oss-cn-chengdu.aliyuncs.com" # 阿里云OSS的端点URL
def "OSS_BUCKET" "demo-9999999" # 阿里云OSS的存储桶名称
def "OSS_BUCKET_URL" "https://demo-9999999.oss-cn-chengdu.aliyuncs.com" # 阿里云OSS的存储桶URL
def "OSS_ACCESS_KEY_ID" "root" # 阿里云OSS的访问密钥ID
def "OSS_ACCESS_KEY_SECRET" "" # 阿里云OSS的密钥
def "OSS_SESSION_TOKEN" "" # 阿里云OSS的会话令牌
###################### Redis 配置信息 ######################
def "REDIS_ADDRESS" "127.0.0.1:16379" # Redis的地址
def "REDIS_USERNAME" "" # Redis的用户名
def "REDIS_PASSWORD" "openIM123" # Redis的密码
###################### Kafka 配置信息 ######################
def "KAFKA_USERNAME" "" # Kafka的用户名
def "KAFKA_PASSWORD" "" # Kafka的密码
def "KAFKA_ADDR" "127.0.0.1:9092" # Kafka的地址
def "KAFKA_LATESTMSG_REDIS_TOPIC" "latestMsgToRedis" # Kafka的最新消息到Redis的主题
def "KAFKA_OFFLINEMSG_MONGO_TOPIC" "offlineMsgToMongoMysql" # Kafka的离线消息到Mongo的主题
def "KAFKA_MSG_PUSH_TOPIC" "msgToPush" # Kafka的消息到推送的主题
def "KAFKA_CONSUMERGROUPID_REDIS" "redis" # Kafka的消费组ID到Redis
def "KAFKA_CONSUMERGROUPID_MONGO" "mongo" # Kafka的消费组ID到Mongo
def "KAFKA_CONSUMERGROUPID_MYSQL" "mysql" # Kafka的消费组ID到MySql
def "KAFKA_CONSUMERGROUPID_PUSH" "push" # Kafka的消费组ID到推送
###################### RPC 配置信息 ######################
def "RPC_REGISTER_IP" "" # RPC的注册IP
def "RPC_LISTEN_IP" "0.0.0.0" # RPC的监听IP
###################### API 配置信息 ######################
def "API_OPENIM_PORT" "10002" # API的开放端口
def "API_LISTEN_IP" "0.0.0.0" # API的监听IP
###################### RPC Port Configuration Variables ######################
def "OPENIM_USER_PORT" "10110" # OpenIM用户服务端口
def "OPENIM_FRIEND_PORT" "10120" # OpenIM朋友服务端口
def "OPENIM_MESSAGE_PORT" "10130" # OpenIM消息服务端口
def "OPENIM_MESSAGE_GATEWAY_PORT" "10140" # OpenIM消息网关服务端口
def "OPENIM_GROUP_PORT" "10150" # OpenIM组服务端口
def "OPENIM_AUTH_PORT" "10160" # OpenIM授权服务端口
def "OPENIM_PUSH_PORT" "10170" # OpenIM推送服务端口
def "OPENIM_CONVERSATION_PORT" "10180" # OpenIM对话服务端口
def "OPENIM_THIRD_PORT" "10190" # OpenIM第三方服务端口
###################### RPC Register Name Variables ######################
def "OPENIM_USER_NAME" "User" # OpenIM用户服务名称
def "OPENIM_FRIEND_NAME" "Friend" # OpenIM朋友服务名称
def "OPENIM_MSG_NAME" "Msg" # OpenIM消息服务名称
def "OPENIM_PUSH_NAME" "Push" # OpenIM推送服务名称
def "OPENIM_MESSAGE_GATEWAY_NAME" "MessageGateway" # OpenIM消息网关服务名称
def "OPENIM_GROUP_NAME" "Group" # OpenIM组服务名称
def "OPENIM_AUTH_NAME" "Auth" # OpenIM授权服务名称
def "OPENIM_CONVERSATION_NAME" "Conversation" # OpenIM对话服务名称
def "OPENIM_THIRD_NAME" "Third" # OpenIM第三方服务名称
###################### Log Configuration Variables ######################
def "LOG_STORAGE_LOCATION" "../../../../../logs/" # 日志存储位置
def "LOG_ROTATION_TIME" "24" # 日志轮替时间
def "LOG_REMAIN_ROTATION_COUNT" "2" # 保留的日志轮替数量
def "LOG_REMAIN_LOG_LEVEL" "6" # 保留的日志级别
def "LOG_IS_STDOUT" "false" # 是否将日志输出到标准输出
def "LOG_IS_JSON" "false" # 日志是否为JSON格式
def "LOG_WITH_STACK" "false" # 日志是否带有堆栈信息
###################### Variables definition ######################
def "OPENIM_WS_PORT" "10001" # OpenIM WS端口
def "WEBSOCKET_MAX_CONN_NUM" "100000" # Websocket最大连接数
def "WEBSOCKET_MAX_MSG_LEN" "4096" # Websocket最大消息长度
def "WEBSOCKET_TIMEOUT" "10" # Websocket超时
def "PUSH_ENABLE" "getui" # 推送是否启用
def "GETUI_PUSH_URL" "https://restapi.getui.com/v2/$appId" # GeTui推送URL
def "FCM_SERVICE_ACCOUNT" "x.json" # FCM服务账户
def "JPNS_APP_KEY" "" # JPNS应用密钥
def "JPNS_MASTER_SECRET" "" # JPNS主密钥
def "JPNS_PUSH_URL" "" # JPNS推送URL
def "JPNS_PUSH_INTENT" "" # JPNS推送意图
def "MANAGER_USERID_1" "openIM123456" # 管理员ID 1
def "MANAGER_USERID_2" "openIM654321" # 管理员ID 2
def "MANAGER_USERID_3" "openIMAdmin" # 管理员ID 3
def "NICKNAME_1" "system1" # 昵称1
def "NICKNAME_2" "system2" # 昵称2
def "NICKNAME_3" "system3" # 昵称3
def "MULTILOGIN_POLICY" "1" # 多登录策略
def "CHAT_PERSISTENCE_MYSQL" "true" # 聊天持久化MySQL
def "MSG_CACHE_TIMEOUT" "86400" # 消息缓存超时
def "GROUP_MSG_READ_RECEIPT" "true" # 群消息已读回执启用
def "SINGLE_MSG_READ_RECEIPT" "true" # 单一消息已读回执启用
def "RETAIN_CHAT_RECORDS" "365" # 保留聊天记录
def "CHAT_RECORDS_CLEAR_TIME" "0 2 * * 3" # 聊天记录清理时间
def "MSG_DESTRUCT_TIME" "0 2 * * *" # 消息销毁时间
def "SECRET" "openIM123" # 密钥
def "TOKEN_EXPIRE" "90" # Token到期时间
def "FRIEND_VERIFY" "false" # 朋友验证
def "IOS_PUSH_SOUND" "xxx" # IOS推送声音
def "IOS_BADGE_COUNT" "true" # IOS徽章计数
def "IOS_PRODUCTION" "false" # IOS生产
###################### Prometheus 配置信息 ######################
def "PROMETHEUS_ENABLE" "false" # 是否启用 Prometheus
def "USER_PROM_PORT" "20110" # User 服务的 Prometheus 端口
def "FRIEND_PROM_PORT" "20120" # Friend 服务的 Prometheus 端口
def "MESSAGE_PROM_PORT" "20130" # Message 服务的 Prometheus 端口
def "MSG_GATEWAY_PROM_PORT" "20140" # Message Gateway 服务的 Prometheus 端口
def "GROUP_PROM_PORT" "20150" # Group 服务的 Prometheus 端口
def "AUTH_PROM_PORT" "20160" # Auth 服务的 Prometheus 端口
def "PUSH_PROM_PORT" "20170" # Push 服务的 Prometheus 端口
def "CONVERSATION_PROM_PORT" "20230" # Conversation 服务的 Prometheus 端口
def "RTC_PROM_PORT" "21300" # RTC 服务的 Prometheus 端口
def "THIRD_PROM_PORT" "21301" # Third 服务的 Prometheus 端口
def "MSG_TRANSFER_PROM_PORTS" "21400, 21401, 21402, 21403" # Message Transfer 服务的 Prometheus 端口列表
# MongoDB 配置
readonly MONGO_ADMIN_USERNAME=${MONGO_ADMIN_USERNAME:-root} # MongoDB root 用户
readonly MONGO_ADMIN_PASSWORD=${MONGO_ADMIN_PASSWORD:-${PASSWORD}} # MongoDB root 用户密码
readonly MONGO_HOST=${MONGO_HOST:-127.0.0.1} # MongoDB 地址
readonly MONGO_PORT=${MONGO_PORT:-27017} # MongoDB 端口
readonly MONGO_USERNAME=${MONGO_USERNAME:-openim} # MongoDB 用户名
readonly MONGO_PASSWORD=${MONGO_PASSWORD:-${PASSWORD}} # MongoDB 密码
# openim 配置
readonly OPENIM_DATA_DIR=${OPENIM_DATA_DIR:-/data/openim} # openim 各组件数据目录
readonly OPENIM_INSTALL_DIR=${OPENIM_INSTALL_DIR:-/opt/openim} # openim 安装文件存放目录
readonly OPENIM_CONFIG_DIR=${OPENIM_CONFIG_DIR:-/etc/openim} # openim 配置文件存放目录
readonly OPENIM_LOG_DIR=${OPENIM_LOG_DIR:-/var/log/openim} # openim 日志文件存放目录
readonly CA_FILE=${CA_FILE:-${OPENIM_CONFIG_DIR}/cert/ca.pem} # CA
def "OPENIM_DATA_DIR" "/data/openim"
def "OPENIM_INSTALL_DIR" "/opt/openim"
def "OPENIM_CONFIG_DIR" "/etc/openim"
def "OPENIM_LOG_DIR" "/var/log/openim"
def "CA_FILE" "${OPENIM_CONFIG_DIR}/cert/ca.pem"
# openim-apiserver 配置
readonly OPENIM_APISERVER_HOST=${OPENIM_APISERVER_HOST:-127.0.0.1} # openim-apiserver 部署机器 IP 地址
readonly OPENIM_APISERVER_GRPC_BIND_ADDRESS=${OPENIM_APISERVER_GRPC_BIND_ADDRESS:-0.0.0.0}
readonly OPENIM_APISERVER_GRPC_BIND_PORT=${OPENIM_APISERVER_GRPC_BIND_PORT:-8081}
readonly OPENIM_APISERVER_INSECURE_BIND_ADDRESS=${OPENIM_APISERVER_INSECURE_BIND_ADDRESS:-127.0.0.1}
readonly OPENIM_APISERVER_INSECURE_BIND_PORT=${OPENIM_APISERVER_INSECURE_BIND_PORT:-8080}
readonly OPENIM_APISERVER_SECURE_BIND_ADDRESS=${OPENIM_APISERVER_SECURE_BIND_ADDRESS:-0.0.0.0}
readonly OPENIM_APISERVER_SECURE_BIND_PORT=${OPENIM_APISERVER_SECURE_BIND_PORT:-8443}
readonly OPENIM_APISERVER_SECURE_TLS_CERT_KEY_CERT_FILE=${OPENIM_APISERVER_SECURE_TLS_CERT_KEY_CERT_FILE:-${OPENIM_CONFIG_DIR}/cert/openim-apiserver.pem}
readonly OPENIM_APISERVER_SECURE_TLS_CERT_KEY_PRIVATE_KEY_FILE=${OPENIM_APISERVER_SECURE_TLS_CERT_KEY_PRIVATE_KEY_FILE:-${OPENIM_CONFIG_DIR}/cert/openim-apiserver-key.pem}
# openim-authz-server 配置
readonly OPENIM_AUTHZ_SERVER_HOST=${OPENIM_AUTHZ_SERVER_HOST:-127.0.0.1} # openim-authz-server 部署机器 IP 地址
readonly OPENIM_AUTHZ_SERVER_INSECURE_BIND_ADDRESS=${OPENIM_AUTHZ_SERVER_INSECURE_BIND_ADDRESS:-127.0.0.1}
readonly OPENIM_AUTHZ_SERVER_INSECURE_BIND_PORT=${OPENIM_AUTHZ_SERVER_INSECURE_BIND_PORT:-9090}
readonly OPENIM_AUTHZ_SERVER_SECURE_BIND_ADDRESS=${OPENIM_AUTHZ_SERVER_SECURE_BIND_ADDRESS:-0.0.0.0}
readonly OPENIM_AUTHZ_SERVER_SECURE_BIND_PORT=${OPENIM_AUTHZ_SERVER_SECURE_BIND_PORT:-9443}
readonly OPENIM_AUTHZ_SERVER_SECURE_TLS_CERT_KEY_CERT_FILE=${OPENIM_AUTHZ_SERVER_SECURE_TLS_CERT_KEY_CERT_FILE:-${OPENIM_CONFIG_DIR}/cert/openim-authz-server.pem}
readonly OPENIM_AUTHZ_SERVER_SECURE_TLS_CERT_KEY_PRIVATE_KEY_FILE=${OPENIM_AUTHZ_SERVER_SECURE_TLS_CERT_KEY_PRIVATE_KEY_FILE:-${OPENIM_CONFIG_DIR}/cert/openim-authz-server-key.pem}
readonly OPENIM_AUTHZ_SERVER_CLIENT_CA_FILE=${OPENIM_AUTHZ_SERVER_CLIENT_CA_FILE:-${CA_FILE}}
readonly OPENIM_AUTHZ_SERVER_RPCSERVER=${OPENIM_AUTHZ_SERVER_RPCSERVER:-${OPENIM_APISERVER_HOST}:${OPENIM_APISERVER_GRPC_BIND_PORT}}
# openim-pump 配置
readonly OPENIM_PUMP_HOST=${OPENIM_PUMP_HOST:-127.0.0.1} # openim-pump 部署机器 IP 地址
readonly OPENIM_PUMP_COLLECTION_NAME=${OPENIM_PUMP_COLLECTION_NAME:-openim_analytics}
readonly OPENIM_PUMP_MONGO_URL=${OPENIM_PUMP_MONGO_URL:-mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOST}:${MONGO_PORT}/${OPENIM_PUMP_COLLECTION_NAME}?authSource=${OPENIM_PUMP_COLLECTION_NAME}}
# openim-watcher配置
readonly OPENIM_WATCHER_HOST=${OPENIM_WATCHER_HOST:-127.0.0.1} # openim-watcher 部署机器 IP 地址
# openim-api 配置
def "OPENIM_APISERVER_HOST" "127.0.0.1"
def "OPENIM_APISERVER_GRPC_BIND_ADDRESS" "0.0.0.0"
def "OPENIM_APISERVER_GRPC_BIND_PORT" "8081"
def "OPENIM_APISERVER_INSECURE_BIND_ADDRESS" "127.0.0.1"
def "OPENIM_APISERVER_INSECURE_BIND_PORT" "8080"
def "OPENIM_APISERVER_SECURE_BIND_ADDRESS" "0.0.0.0"
def "OPENIM_APISERVER_SECURE_BIND_PORT" "8443"
def "OPENIM_APISERVER_SECURE_TLS_CERT_KEY_CERT_FILE" "${OPENIM_CONFIG_DIR}/cert/openim-apiserver.pem"
def "OPENIM_APISERVER_SECURE_TLS_CERT_KEY_PRIVATE_KEY_FILE" "${OPENIM_CONFIG_DIR}/cert/openim-apiserver-key.pem"
# openimctl 配置
readonly CONFIG_USER_USERNAME=${CONFIG_USER_USERNAME:-admin}
readonly CONFIG_USER_PASSWORD=${CONFIG_USER_PASSWORD:-Admin@2021}
readonly CONFIG_USER_CLIENT_CERTIFICATE=${CONFIG_USER_CLIENT_CERTIFICATE:-${HOME}/.openim/cert/admin.pem}
readonly CONFIG_USER_CLIENT_KEY=${CONFIG_USER_CLIENT_KEY:-${HOME}/.openim/cert/admin-key.pem}
readonly CONFIG_SERVER_ADDRESS=${CONFIG_SERVER_ADDRESS:-${OPENIM_APISERVER_HOST}:${OPENIM_APISERVER_SECURE_BIND_PORT}}
readonly CONFIG_SERVER_CERTIFICATE_AUTHORITY=${CONFIG_SERVER_CERTIFICATE_AUTHORITY:-${CA_FILE}}
def "CONFIG_USER_USERNAME" "admin"
def "CONFIG_USER_PASSWORD" "Admin@2021"
def "CONFIG_USER_CLIENT_CERTIFICATE" "${HOME}/.openim/cert/admin.pem"
def "CONFIG_USER_CLIENT_KEY" "${HOME}/.openim/cert/admin-key.pem"
def "CONFIG_SERVER_ADDRESS" "${OPENIM_APISERVER_HOST}:${OPENIM_APISERVER_SECURE_BIND_PORT}"
def "CONFIG_SERVER_CERTIFICATE_AUTHORITY" "${CA_FILE}"
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# 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.
# The root of the build/dist directory
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
source "${OPENIM_ROOT}/scripts/install/common.sh"
+89
View File
@@ -0,0 +1,89 @@
#!/usr/bin/env bash
# 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.
# The root of the build/dist directory
IAM_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
[[ -z ${COMMON_SOURCED} ]] && source ${IAM_ROOT}/scripts/install/common.sh
# Print the necessary information after installation
function openim::redis::info() {
cat << EOF
Redis Login: redis-cli --no-auth-warning -h ${REDIS_HOST} -p ${REDIS_PORT} -a '${REDIS_PASSWORD}'
EOF
}
# 安装
function openim::redis::install()
{
# 1. 安装 Redis
openim::common::sudo "apt-get -y install redis-server"
# 2. 配置 Redis
# 2.1 修改 `/etc/redis/redis.conf` 文件,将 daemonize 由 no 改成 yes,表示允许 Redis 在后台启动
echo ${LINUX_PASSWORD} | sudo -S sed -i '/^daemonize/{s/no/yes/}' /etc/redis/redis.conf
# 2.2 在 `bind 127.0.0.1` 前面添加 `#` 将其注释掉,默认情况下只允许本地连接,注释掉后外网可以连接 Redis
echo ${LINUX_PASSWORD} | sudo -S sed -i '/^# bind 127.0.0.1/{s/# //}' /etc/redis/redis.conf
# 2.3 修改 requirepass 配置,设置 Redis 密码
echo ${LINUX_PASSWORD} | sudo -S sed -i 's/^# requirepass.*$/requirepass '"${REDIS_PASSWORD}"'/' /etc/redis/redis.conf
# 2.4 因为我们上面配置了密码登录,需要将 protected-mode 设置为 no,关闭保护模式
echo ${LINUX_PASSWORD} | sudo -S sed -i '/^protected-mode/{s/yes/no/}' /etc/redis/redis.conf
# 3. 为了能够远程连上 Redis,需要执行以下命令关闭防火墙,并禁止防火墙开机启动(如果不需要远程连接,可忽略此步骤)
openim::common::sudo "sudo ufw disable"
openim::common::sudo "sudo ufw status"
# 4. 启动 Redis
openim::common::sudo "redis-server /etc/redis/redis.conf"
openim::redis::status || return 1
openim::redis::info
openim::log::info "install Redis successfully"
}
# 卸载
function openim::redis::uninstall()
{
set +o errexit
openim::common::sudo "/etc/init.d/redis-server stop"
openim::common::sudo "apt-get -y remove redis-server"
openim::common::sudo "rm -rf /var/lib/redis"
set -o errexit
openim::log::info "uninstall Redis successfully"
}
# 状态检查
function openim::redis::status()
{
if [[ -z "`pgrep redis-server`" ]];then
openim::log::error_exit "Redis not running, maybe not installed properly"
return 1
fi
redis-cli --no-auth-warning -h ${REDIS_HOST} -p ${REDIS_PORT} -a "${REDIS_PASSWORD}" --hotkeys || {
openim::log::error "can not login with ${REDIS_USERNAME}, redis maybe not initialized properly"
return 1
}
openim::log::info "redis-server status active"
}
#eval $*
if [[ "$*" =~ openim::redis:: ]];then
eval $*
fi
-10
View File
@@ -22,15 +22,6 @@ OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
source $SCRIPTS_ROOT/lib/init.sh
source $SCRIPTS_ROOT/path_info.sh
cd $SCRIPTS_ROOT
echo -e "${BACKGROUND_GREEN}${CYAN_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}"
echo -e "${BACKGROUND_GREEN}${CYAN_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}"
echo -e "${BACKGROUND_GREEN}${CYAN_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}"
bin_dir="$BIN_DIR"
logs_dir="$OPENIM_ROOT/logs"
#service filename
service_filename=(
#api
@@ -106,7 +97,6 @@ for ((i = 0; i < ${#service_filename[*]}; i++)); do
if [ $i -eq 0 -o $i -eq 1 ]; then
cmd="./${service_filename[$i]} --port ${service_ports[$j]}"
fi
echo $cmd
echo "=====================start ${service_filename[$i]}======================">>$OPENIM_ROOT/logs/openIM.log
nohup $cmd >>$OPENIM_ROOT/logs/openIM.log 2>&1 &
sleep 1