mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
conf script
This commit is contained in:
parent
5b816b095d
commit
ccad06b7b6
@ -222,7 +222,7 @@ func main() {
|
|||||||
initGroup.POST("/set_client_config", clientInit.SetClientInitConfig)
|
initGroup.POST("/set_client_config", clientInit.SetClientInitConfig)
|
||||||
initGroup.POST("/get_client_config", clientInit.GetClientInitConfig)
|
initGroup.POST("/get_client_config", clientInit.GetClientInitConfig)
|
||||||
}
|
}
|
||||||
|
go config.RegisterConf()
|
||||||
go apiThird.MinioInit()
|
go apiThird.MinioInit()
|
||||||
defaultPorts := config.Config.Api.GinPort
|
defaultPorts := config.Config.Api.GinPort
|
||||||
ginPort := flag.Int("port", defaultPorts[0], "get ginServerPort from cmd,default 10002 as port")
|
ginPort := flag.Int("port", defaultPorts[0], "get ginServerPort from cmd,default 10002 as port")
|
||||||
|
@ -9,6 +9,7 @@ etcd:
|
|||||||
etcdAddr: [ 127.0.0.1:2379 ] #单机部署时,默认即可
|
etcdAddr: [ 127.0.0.1:2379 ] #单机部署时,默认即可
|
||||||
userName:
|
userName:
|
||||||
password:
|
password:
|
||||||
|
secret:
|
||||||
|
|
||||||
mysql:
|
mysql:
|
||||||
dbMysqlAddress: [ 127.0.0.1:13306 ] #mysql地址 目前仅支持单机,默认即可
|
dbMysqlAddress: [ 127.0.0.1:13306 ] #mysql地址 目前仅支持单机,默认即可
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
etcd:
|
etcd:
|
||||||
userName:
|
userName:
|
||||||
password:
|
password:
|
||||||
|
secret: # etcd 配置密钥
|
||||||
|
|
||||||
mysql:
|
mysql:
|
||||||
dbMysqlUserName: root #mysql用户名,建议修改
|
dbMysqlUserName: root #mysql用户名,建议修改
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||||
|
"Open_IM/pkg/utils"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -16,6 +18,8 @@ var (
|
|||||||
Root = filepath.Join(filepath.Dir(b), "../../..")
|
Root = filepath.Join(filepath.Dir(b), "../../..")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const confName = "openIMConf"
|
||||||
|
|
||||||
var Config config
|
var Config config
|
||||||
|
|
||||||
type callBackConfig struct {
|
type callBackConfig struct {
|
||||||
@ -157,6 +161,7 @@ type config struct {
|
|||||||
EtcdAddr []string `yaml:"etcdAddr"`
|
EtcdAddr []string `yaml:"etcdAddr"`
|
||||||
UserName string `yaml:"userName"`
|
UserName string `yaml:"userName"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
|
Secret string `yaml:"secret"`
|
||||||
}
|
}
|
||||||
Log struct {
|
Log struct {
|
||||||
StorageLocation string `yaml:"storageLocation"`
|
StorageLocation string `yaml:"storageLocation"`
|
||||||
@ -563,6 +568,7 @@ type usualConfig struct {
|
|||||||
Etcd struct {
|
Etcd struct {
|
||||||
UserName string `yaml:"userName"`
|
UserName string `yaml:"userName"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
|
Secret string `yaml:"secret"`
|
||||||
} `yaml:"etcd"`
|
} `yaml:"etcd"`
|
||||||
Mysql struct {
|
Mysql struct {
|
||||||
DBUserName string `yaml:"dbMysqlUserName"`
|
DBUserName string `yaml:"dbMysqlUserName"`
|
||||||
@ -647,13 +653,15 @@ func unmarshalConfig(config interface{}, configName string) {
|
|||||||
func init() {
|
func init() {
|
||||||
unmarshalConfig(&Config, "config.yaml")
|
unmarshalConfig(&Config, "config.yaml")
|
||||||
unmarshalConfig(&UsualConfig, "usualConfig.yaml")
|
unmarshalConfig(&UsualConfig, "usualConfig.yaml")
|
||||||
fmt.Println(UsualConfig)
|
|
||||||
if Config.Etcd.UserName == "" {
|
if Config.Etcd.UserName == "" {
|
||||||
Config.Etcd.UserName = UsualConfig.Etcd.UserName
|
Config.Etcd.UserName = UsualConfig.Etcd.UserName
|
||||||
}
|
}
|
||||||
if Config.Etcd.Password == "" {
|
if Config.Etcd.Password == "" {
|
||||||
Config.Etcd.Password = UsualConfig.Etcd.Password
|
Config.Etcd.Password = UsualConfig.Etcd.Password
|
||||||
}
|
}
|
||||||
|
if Config.Etcd.Secret == "" {
|
||||||
|
Config.Etcd.Secret = UsualConfig.Etcd.Secret
|
||||||
|
}
|
||||||
|
|
||||||
if Config.Mysql.DBUserName == "" {
|
if Config.Mysql.DBUserName == "" {
|
||||||
Config.Mysql.DBUserName = UsualConfig.Mysql.DBUserName
|
Config.Mysql.DBUserName = UsualConfig.Mysql.DBUserName
|
||||||
@ -720,5 +728,17 @@ func init() {
|
|||||||
if Config.TokenPolicy.AccessSecret == "" {
|
if Config.TokenPolicy.AccessSecret == "" {
|
||||||
Config.TokenPolicy.AccessSecret = UsualConfig.Tokenpolicy.AccessSecret
|
Config.TokenPolicy.AccessSecret = UsualConfig.Tokenpolicy.AccessSecret
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterConf() {
|
||||||
|
bytes, err := yaml.Marshal(Config)
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
secretMD5 := utils.Md5(Config.Etcd.Secret)
|
||||||
|
confBytes, err := utils.AesEncrypt(bytes, []byte(secretMD5[0:16]))
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
getcdv3.RegisterConf(getcdv3.GetPrefix(Config.Etcd.EtcdSchema, confName), string(confBytes))
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package getcdv3
|
package getcdv3
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
@ -127,3 +128,25 @@ func UnRegisterEtcd() {
|
|||||||
rEtcd.cancel()
|
rEtcd.cancel()
|
||||||
rEtcd.cli.Delete(rEtcd.ctx, rEtcd.key)
|
rEtcd.cli.Delete(rEtcd.ctx, rEtcd.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RegisterConf(key, conf string) {
|
||||||
|
etcdAddr := strings.Join(config.Config.Etcd.EtcdAddr, ",")
|
||||||
|
cli, err := clientv3.New(clientv3.Config{
|
||||||
|
Endpoints: strings.Split(etcdAddr, ","), DialTimeout: 5 * time.Second})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
//lease
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
resp, err := cli.Grant(ctx, 10)
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
if _, err := cli.Put(ctx, key, conf, clientv3.WithLease(resp.ID)); err != nil {
|
||||||
|
fmt.Println("panic, params: ")
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
14
script/init_pwd.sh
Normal file
14
script/init_pwd.sh
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source ../.env
|
||||||
|
|
||||||
|
nameList=(dbMysqlUserName, dbUserName, dbUserName, accessKeyID)
|
||||||
|
pwdList=(dbMysqlPassword, dbPassword, dbPassWord, secretAccessKey)
|
||||||
|
|
||||||
|
for i in ${nameList[*]}; do
|
||||||
|
sed -i 's/{$i}: [a-z]/{$i}: {$USER}/g' ../config/usualConfig.yaml
|
||||||
|
done
|
||||||
|
|
||||||
|
for i in ${pwdList[*]}; do
|
||||||
|
sed -i 's/{$i}: [a-z]/{$i}: {$PASSWORD}/g' ../config/usualConfig.yaml
|
||||||
|
done
|
Loading…
x
Reference in New Issue
Block a user