Merge remote-tracking branch 'origin/tuoyun' into tuoyun

pull/218/head
skiffer-git 3 years ago
commit 6de569537f

@ -0,0 +1,37 @@
---
name: "\U0001F41E Bug"
about: File a bug/issue
title: "[BUG] <title>"
labels: ''
assignees: ''
---
<!--
Note: Please search to see if an issue already exists for the bug you encountered.
-->
### Environment:
<!-- linux? windows? or Mac?
Example:
- OS: Ubuntu 20.04 -->
### Physical Memory Capacity:
<!-- 8G or above is better -->
### Docker Image:
<!-- Did you pull the docker image before execute docker images -->
### Code Version:
<!-- Did you pull code from github? Make sure the code is up to date-->
### Component installation:
<!-- Has etcd, mysql, mongodb, redis or Kafka been installed on the server before Open-IM-Server deployment-->
### Log File:
<!-- view log file(logs/openIM.log) content. -->
### screenshot:
<!---->

@ -0,0 +1,36 @@
---
name: Deployment issues
about: Deployment issues
title: ''
labels: ''
assignees: ''
---
If you are deploying OpenIM for the first time
```
git clone https://github.com/OpenIMSDK/Open-IM-Server.git --recursive
```
screenshot here
```
cd Open-IM-Server/script ; chmod +x *.sh ; ./env_check.sh
```
screenshot here
```
cd .. ; docker-compose up -d
```
screenshot here
```
cd script ; ./docker_check_service.sh
```
screenshot here

@ -0,0 +1,38 @@
---
name: 'update '
about: update docker image
title: update docker image
labels: ''
assignees: ''
---
```
cd Open-IM-Server ; docker-compose down
```
screenshot here
```
git pull
```
screenshot here
```
docker-compose pull
```
screenshot here
```
chmod +x script/*.sh ; docker-compose up -d
```
screenshot here
```
cd script ; ./docker_check_service.sh
```
screenshot here

1
.gitignore vendored

@ -7,6 +7,7 @@ out-test
.github
.idea
deploy/open_im_demo
deploy/open_im_api
deploy/open_im_msg_gateway

@ -92,6 +92,7 @@ All images are available at https://hub.docker.com/r/lyt1123/open_im_server
4. Start docker-compose with one click(Docker automatically pulls all images)
```
cd Open-IM-Server
docker-compose up -d
```
@ -99,6 +100,7 @@ All images are available at https://hub.docker.com/r/lyt1123/open_im_server
```
./docker_check_service.sh
./check_all.sh
```
![OpenIMServersondockerpng](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/Open-IM-Servers-on-docker.png)

@ -79,6 +79,7 @@ func main() {
thirdGroup := r.Group("/third")
{
thirdGroup.POST("/tencent_cloud_storage_credential", apiThird.TencentCloudStorageCredential)
thirdGroup.POST("/ali_oss_credential", apiThird.AliOSSCredential)
thirdGroup.POST("/minio_storage_credential", apiThird.MinioStorageCredential)
thirdGroup.POST("/minio_upload", apiThird.MinioUploadFile)
}
@ -119,13 +120,9 @@ func main() {
officeGroup.POST("/send_msg_to_tag", office.SendMsg2Tag)
officeGroup.POST("/get_send_tag_log", office.GetTagSendLogs)
}
apiThird.MinioInit()
log.NewPrivateLog("api")
ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port")
flag.Parse()
err := r.Run(":" + strconv.Itoa(*ginPort))
if err != nil {
log.NewError("", utils.GetSelfFuncName(), "start gin failed", err.Error())
}
r.Run(":" + strconv.Itoa(*ginPort))
}

@ -19,7 +19,8 @@ mysql:
dbMaxLifeTime: 120
mongo:
dbAddress: [ 127.0.0.1:37017 ] #redis地址 目前仅支持单机,默认即可
dbUri: ""#当dbUri值不为空则直接使用该值
dbAddress: [ 127.0.0.1:37017 ] #mongo地址 目前仅支持单机,默认即可
dbDirect: false
dbTimeout: 10
dbDatabase: openIM #mongo db 默认即可
@ -91,9 +92,20 @@ credential: #腾讯cos发送图片、视频、文件时需要请自行申
minio: #MinIO 发送图片、视频、文件时需要,请自行申请后替换,必须修改。 客户端初始化InitSDK中 object_storage参数为minio
bucket: openim
location: us-east-1
endpoint: http://43.128.5.63:9000
endpoint: http://127.0.0.1:9000
accessKeyID: user12345
secretAccessKey: key12345
ali: # ali oss
regionID: "oss-cn-beijing"
accessKeyID: ""
accessKeySecret: ""
stsEndpoint: "sts.cn-beijing.aliyun.com"
ossEndpoint: "oss-cn-beijing.aliyuncs.com"
bucket: "bucket1"
finalHost: "http://bucket1.oss-cn-beijing.aliyuncs.com"
stsDurationSeconds: 3600
OssRoleArn: "acs:ram::xxx:role/xxx"
rpcport: #rpc服务端口 默认即可
@ -136,7 +148,7 @@ log:
rotationTime: 24
remainRotationCount: 3 #日志数量
#日志级别 6表示全都打印测试阶段建议设置为6
remainLogLevel: 6
remainLogLevel: 4
elasticSearchSwitch: false
elasticSearchAddr: [ 127.0.0.1:9201 ]
elasticSearchUser: ""

@ -19,6 +19,7 @@ mysql:
dbMaxLifeTime: 120
mongo:
dbUri: ""#当dbUri值不为空则直接使用该值
dbAddress: [ openim_mongo:27017 ]
dbDirect: false
dbTimeout: 10

@ -32,6 +32,7 @@ services:
# - MONGO_INITDB_ROOT_USERNAME=openIM
# - MONGO_INITDB_ROOT_PASSWORD=openIM
#TZ: Asia/Shanghai
restart: always
@ -93,7 +94,7 @@ services:
command: /usr/local/bin/etcd --name etcd0 --data-dir /etcd-data --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379 --listen-peer-urls http://0.0.0.0:2380 --initial-advertise-peer-urls http://0.0.0.0:2380 --initial-cluster etcd0=http://0.0.0.0:2380 --initial-cluster-token tkn --initial-cluster-state new
open_im_server:
image: openim/open_im_server:v2.0.2
image: openim/open_im_server:v2.0.5
container_name: open_im_server
volumes:
- ./logs:/Open-IM-Server/logs

@ -7,6 +7,7 @@ require (
github.com/Shopify/toxiproxy v2.1.4+incompatible // indirect
github.com/alibabacloud-go/darabonba-openapi v0.1.11
github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8
github.com/alibabacloud-go/sts-20150401 v1.1.0
github.com/alibabacloud-go/tea v1.1.17
github.com/antonfisher/nested-logrus-formatter v1.3.0
github.com/bwmarrin/snowflake v0.3.0
@ -21,7 +22,7 @@ require (
github.com/gin-gonic/gin v1.7.0
github.com/go-playground/validator/v10 v10.4.1
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gogo/protobuf v1.3.2
github.com/golang-jwt/jwt/v4 v4.1.0
github.com/golang/protobuf v1.5.2
github.com/golang/snappy v0.0.4 // indirect
@ -59,6 +60,7 @@ require (
google.golang.org/protobuf v1.27.1
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
sigs.k8s.io/yaml v1.2.0 // indirect

@ -53,6 +53,7 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/alibabacloud-go/darabonba-openapi v0.1.7/go.mod h1:6FV1Bt1AItYIlC2rVopPTumrRNtkfPBmrPVAZ8v2bLk=
github.com/alibabacloud-go/darabonba-openapi v0.1.11 h1:w59gtSA0s87p0U5NNG/N/PIHsRP3rtj7qCP9hx9+GL8=
github.com/alibabacloud-go/darabonba-openapi v0.1.11/go.mod h1:MPJMxv7HYrFm5m9uOZWkDYsAWyZztEgnBRfk9Fg0eIU=
github.com/alibabacloud-go/darabonba-string v1.0.0/go.mod h1:93cTfV3vuPhhEwGGpKKqhVW4jLe7tDpo3LUM0i0g6mA=
@ -62,8 +63,11 @@ github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8 h1:KXMiCg99Jx7B6V+DlRFbWw
github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8/go.mod h1:8aL6tSyQIWJygF7W/Vqxdf/QDbN2S+u57k36bEA8hD8=
github.com/alibabacloud-go/endpoint-util v1.1.0 h1:r/4D3VSw888XGaeNpP994zDUaxdgTSHBbVfZlzf6b5Q=
github.com/alibabacloud-go/endpoint-util v1.1.0/go.mod h1:O5FuCALmCKs2Ff7JFJMudHs0I5EBgecXXxZRyswlEjE=
github.com/alibabacloud-go/openapi-util v0.0.8/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws=
github.com/alibabacloud-go/openapi-util v0.0.9 h1:Z0DP4LFzkM/rW2nxOMiiLoQVZSeE3jVc5jrZ9Fd/UX0=
github.com/alibabacloud-go/openapi-util v0.0.9/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws=
github.com/alibabacloud-go/sts-20150401 v1.1.0 h1:1yVyKz02ES6aKo3xVjmoPLBH1OAmmSqPkhKRdjEkmYs=
github.com/alibabacloud-go/sts-20150401 v1.1.0/go.mod h1:QW4O/c7Hp4krHYt+6xwnoG8EyZW3V9GYkl6EgIBmxJc=
github.com/alibabacloud-go/tea v1.1.0/go.mod h1:IkGyUSX4Ba1V+k4pCtJUc6jDpZLFph9QMy2VUPTwukg=
github.com/alibabacloud-go/tea v1.1.7/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
github.com/alibabacloud-go/tea v1.1.8/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
@ -1095,6 +1099,8 @@ gopkg.in/ini.v1 v1.56.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.57.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.63.2 h1:tGK/CyBg7SMzb60vP1M03vNZ3VDu3wGQJwn7Sxi9r3c=
gopkg.in/ini.v1 v1.63.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI=
gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw=
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=

@ -259,7 +259,7 @@ func CreateGroup(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
req.OwnerUserID = req.OpUserID
req.OwnerUserID = params.OwnerUserID
req.OperationID = params.OperationID
log.NewInfo(req.OperationID, "CreateGroup args ", req.String())

@ -0,0 +1,95 @@
package apiThird
import (
api "Open_IM/pkg/base_info"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
"fmt"
openapi "github.com/alibabacloud-go/darabonba-openapi/client"
sts20150401 "github.com/alibabacloud-go/sts-20150401/client"
"github.com/alibabacloud-go/tea/tea"
"github.com/fatih/structs"
//"github.com/fatih/structs"
"github.com/gin-gonic/gin"
"net/http"
"time"
)
var stsClient *sts20150401.Client
/**
* 使AK&SKClient
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
func getStsClient() *sts20150401.Client {
if stsClient != nil {
return stsClient
}
conf := &openapi.Config{
// 您的AccessKey ID
AccessKeyId: tea.String(config.Config.Credential.Ali.AccessKeyID),
// 您的AccessKey Secret
AccessKeySecret: tea.String(config.Config.Credential.Ali.AccessKeySecret),
// Endpoint
Endpoint: tea.String(config.Config.Credential.Ali.StsEndpoint),
}
result, err := sts20150401.NewClient(conf)
if err != nil {
log.NewError("", "alists client初始化失败 ", err)
}
stsClient = result
return stsClient
}
func AliOSSCredential(c *gin.Context) {
req := api.OSSCredentialReq{}
if err := c.BindJSON(&req); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
if !ok {
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
log.NewInfo(req.OperationID, "AliOSSCredential args ", userID)
stsResp, err := getStsClient().AssumeRole(&sts20150401.AssumeRoleRequest{
DurationSeconds: tea.Int64(config.Config.Credential.Ali.StsDurationSeconds),
Policy: nil,
RoleArn: tea.String(config.Config.Credential.Ali.OssRoleArn),
RoleSessionName: tea.String(fmt.Sprintf("%s-%d", userID, time.Now().Unix())),
})
resp := api.OSSCredentialResp{}
if err != nil {
resp.ErrCode = constant.ErrTencentCredential.ErrCode
resp.ErrMsg = err.Error()
} else {
resp = api.OSSCredentialResp{
CommResp: api.CommResp{},
OssData: api.OSSCredentialRespData{
Endpoint: config.Config.Credential.Ali.OssEndpoint,
AccessKeyId: *stsResp.Body.Credentials.AccessKeyId,
AccessKeySecret: *stsResp.Body.Credentials.AccessKeySecret,
Token: *stsResp.Body.Credentials.SecurityToken,
Bucket: config.Config.Credential.Ali.Bucket,
FinalHost: config.Config.Credential.Ali.FinalHost,
},
Data: nil,
}
}
resp.Data = structs.Map(&resp.OssData)
log.NewInfo(req.OperationID, "AliOSSCredential return ", resp)
c.JSON(http.StatusOK, resp)
}

@ -17,6 +17,7 @@ import (
type ParamsSetPassword struct {
Email string `json:"email"`
Name string `json:"name"`
PhoneNumber string `json:"phoneNumber"`
Password string `json:"password"`
VerificationCode string `json:"verificationCode"`
@ -38,6 +39,9 @@ func SetPassword(c *gin.Context) {
} else {
account = params.PhoneNumber
}
if params.Name == "" {
params.Name = account
}
if params.VerificationCode != config.Config.Demo.SuperCode {
accountKey := account + "_" + constant.VerificationCodeForRegisterSuffix
v, err := db.DB.GetAccountCode(accountKey)
@ -54,7 +58,7 @@ func SetPassword(c *gin.Context) {
openIMRegisterReq.OperationID = params.OperationID
openIMRegisterReq.Platform = params.Platform
openIMRegisterReq.UserID = account
openIMRegisterReq.Nickname = account
openIMRegisterReq.Nickname = params.Name
openIMRegisterReq.Secret = config.Config.Secret
openIMRegisterResp := api.UserRegisterResp{}
bMsg, err := http2.Post(url, openIMRegisterReq, 2)
@ -69,7 +73,7 @@ func SetPassword(c *gin.Context) {
if err != nil {
log.NewError(params.OperationID, utils.GetSelfFuncName(), err.Error())
}
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: "+openIMRegisterResp.ErrMsg})
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: " + openIMRegisterResp.ErrMsg})
return
}
log.Info(params.OperationID, "begin store mysql", account, params.Password)

@ -21,7 +21,7 @@ type ImportFriendReq struct {
FromUserID string `json:"fromUserID" binding:"required"`
}
type UserIDResult struct {
UserID string `json:"userID""`
UserID string `json:"userID"`
Result int32 `json:"result"`
}
type ImportFriendResp struct {

@ -0,0 +1,22 @@
package base_info
type OSSCredentialReq struct {
OperationID string `json:"operationID"`
Filename string `json:"filename"`
FileType string `json:"file_type"`
}
type OSSCredentialRespData struct {
Endpoint string `json:"endpoint"`
AccessKeyId string `json:"access_key_id"`
AccessKeySecret string `json:"access_key_secret"`
Token string `json:"token"`
Bucket string `json:"bucket"`
FinalHost string `json:"final_host"`
}
type OSSCredentialResp struct {
CommResp
OssData OSSCredentialRespData `json:"-"`
Data map[string]interface{} `json:"data"`
}

@ -45,6 +45,17 @@ type config struct {
SecretID string `yaml:"secretID"`
SecretKey string `yaml:"secretKey"`
}
Ali struct {
RegionID string `yaml:"regionID"`
AccessKeyID string `yaml:"accessKeyID"`
AccessKeySecret string `yaml:"accessKeySecret"`
StsEndpoint string `yaml:"stsEndpoint"`
OssEndpoint string `yaml:"ossEndpoint"`
Bucket string `yaml:"bucket"`
FinalHost string `yaml:"finalHost"`
StsDurationSeconds int64 `yaml:"stsDurationSeconds"`
OssRoleArn string `yaml:"OssRoleArn"`
}
Minio struct {
Bucket string `yaml:"bucket"`
Location string `yaml:"location"`
@ -66,6 +77,7 @@ type config struct {
DBMaxLifeTime int `yaml:"dbMaxLifeTime"`
}
Mongo struct {
DBUri string `yaml:"dbUri"` // 当dbUri值不为空则直接使用该值
DBAddress []string `yaml:"dbAddress"`
DBDirect bool `yaml:"dbDirect"`
DBTimeout int `yaml:"dbTimeout"`

@ -41,12 +41,17 @@ func init() {
// mongo init
// "mongodb://sysop:moon@localhost/records"
uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority"
uri = fmt.Sprintf("mongodb://%s/%s/?connect=direct&maxPoolSize=%d",
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase,
config.Config.Mongo.DBMaxPoolSize)
if config.Config.Mongo.DBUri != "" {
// example: mongodb://$user:$password@mongo1.mongo:27017,mongo2.mongo:27017,mongo3.mongo:27017/$DBDatabase/?replicaSet=rs0&readPreference=secondary&authSource=admin&maxPoolSize=$DBMaxPoolSize
uri = config.Config.Mongo.DBUri
} else {
uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d",
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase,
config.Config.Mongo.DBMaxPoolSize)
}
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
if err != nil {
if err != nil{
log.NewError(" mongo.Connect failed, try ", utils.GetSelfFuncName(), err.Error(), uri)
time.Sleep(time.Duration(30) * time.Second)
mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))

@ -44,4 +44,4 @@ if [ $check -ge 1 ]; then
echo -e ${SKY_BLUE_PREFIX}"LISTENING_PORT: "${COLOR_SUFFIX}${YELLOW_PREFIX}${allPorts}${COLOR_SUFFIX}
else
echo -e ${YELLOW_PREFIX}${demo_server_name}${COLOR_SUFFIX}${RED_PREFIX}"SERVICE START ERROR, PLEASE CHECK openIM.log"${COLOR_SUFFIX}
fi
fi

@ -8,3 +8,4 @@ sleep 30
echo "check OpenIM................................"
./check_all.sh

@ -17,4 +17,3 @@ if [ $available -lt 2000 ] ; then
else
echo -e ${GREEN_PREFIX} "Memory is ok, available is: "$available"m${COLOR_SUFFIX}"
fi

@ -80,4 +80,3 @@ service_names=(

@ -16,4 +16,3 @@ for i in ${need_to_start_server_shell[*]}; do
chmod +x $i
./$i
done

@ -65,4 +65,4 @@ for ((i = 0; i < ${#service_filename[*]}; i++)); do
pid="netstat -ntlp|grep $j |awk '{printf \$7}'|cut -d/ -f1"
echo -e "${RED_PREFIX}${service_filename[$i]} Service is started,port number:$j pid:$(eval $pid)$COLOR_SUFFIX"
done
done
done
Loading…
Cancel
Save