优化部署
This commit is contained in:
		
							parent
							
								
									50b362f40d
								
							
						
					
					
						commit
						f55e94035f
					
				@ -22,6 +22,10 @@ import (
 | 
			
		||||
	"strconv"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	log.SetFlags(log.LstdFlags | log.Llongfile)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 初始化日志
 | 
			
		||||
func InitLogs() (fn func(), err error) {
 | 
			
		||||
	logger := logs.NewLog(
 | 
			
		||||
@ -40,13 +44,23 @@ func InitLogs() (fn func(), err error) {
 | 
			
		||||
// 初始化mysql连接
 | 
			
		||||
func InitMysql() (fn func(), err error) {
 | 
			
		||||
	config := model.GlobConfig.Comm.Mysql
 | 
			
		||||
	dbSource := fmt.Sprintf(
 | 
			
		||||
		"%s:%s@tcp(%s:%s)/%s",
 | 
			
		||||
		config.Username,
 | 
			
		||||
		config.Pwd,
 | 
			
		||||
		config.IP,
 | 
			
		||||
		config.Port,
 | 
			
		||||
		config.DbName)
 | 
			
		||||
	dbSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&parseTime=True",
 | 
			
		||||
		config.Username, config.Pwd, config.IP, config.Port, config.DbName)
 | 
			
		||||
	dbNotDbSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/?charset=utf8&parseTime=True",
 | 
			
		||||
		config.Username, config.Pwd, config.IP, config.Port)
 | 
			
		||||
 | 
			
		||||
	sqlX, err := db.NewSQLX("mysql", dbNotDbSource, config.MaxOpenConns, config.MaxIdleConns)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("创建不指定数据库的mysql连接池报错:%v", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 数据库不存在,创建它
 | 
			
		||||
	sql := fmt.Sprintf(`create database if not exists %s default charset utf8mb4 collate utf8mb4_unicode_ci`, config.DbName)
 | 
			
		||||
	if _, e := sqlX.Exec(sql); e != nil {
 | 
			
		||||
		return nil, fmt.Errorf("failed to create database:%v", e)
 | 
			
		||||
	}
 | 
			
		||||
	_ = sqlX.Close()
 | 
			
		||||
 | 
			
		||||
	db.Sqlx, err = db.NewSQLX(
 | 
			
		||||
		"mysql",
 | 
			
		||||
		dbSource,
 | 
			
		||||
@ -70,18 +84,9 @@ func InitClickHouse() (fn func(), err error) {
 | 
			
		||||
	config := model.GlobConfig.Comm.ClickHouse
 | 
			
		||||
	dbSource := fmt.Sprintf(
 | 
			
		||||
		"tcp://%s:%s?username=%s&password=%s&database=%s&compress=true",
 | 
			
		||||
		config.IP,
 | 
			
		||||
		config.Port,
 | 
			
		||||
		config.Username,
 | 
			
		||||
		config.Pwd,
 | 
			
		||||
		config.DbName,
 | 
			
		||||
	)
 | 
			
		||||
	db.ClickHouseSqlx, err = db.NewSQLX(
 | 
			
		||||
		"clickhouse",
 | 
			
		||||
		dbSource,
 | 
			
		||||
		config.MaxOpenConns,
 | 
			
		||||
		config.MaxIdleConns,
 | 
			
		||||
		config.IP, config.Port, config.Username, config.Pwd, config.DbName,
 | 
			
		||||
	)
 | 
			
		||||
	db.ClickHouseSqlx, err = db.NewSQLX("clickhouse", dbSource, config.MaxOpenConns, config.MaxIdleConns)
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return fn, fmt.Errorf("init clickhouse error:%v", err)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										6
									
								
								build_all_bin_linux.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										6
									
								
								build_all_bin_linux.sh
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
export GOOS=linux && \
 | 
			
		||||
  go build  -tags netgo -ldflags "-s -w" -trimpath -buildvcs=false -o bin/linux/manager cmd/manager/main.go && \
 | 
			
		||||
  go build  -tags netgo -ldflags "-s -w" -trimpath -buildvcs=false -o bin/linux/report_server cmd/report_server/main.go && \
 | 
			
		||||
  go build  -tags netgo -ldflags "-s -w" -trimpath -buildvcs=false -o bin/linux/sinker cmd/sinker/main.go && \
 | 
			
		||||
  go build  -tags netgo -ldflags "-s -w" -trimpath -buildvcs=false -o bin/linux/init_app cmd/init_app/main.go
 | 
			
		||||
echo "build success"
 | 
			
		||||
@ -1,6 +1,7 @@
 | 
			
		||||
 cd vue && npm run build:prod \
 | 
			
		||||
  && cd .. && export GOOS=linux&&go build  -ldflags="-w -s" -o bin/linux/manager cmd/manager/main.go  \
 | 
			
		||||
  && go build  -ldflags="-w -s" -o bin/linux/report_server cmd/report_server/main.go \
 | 
			
		||||
  && go build  -ldflags="-w -s" -o bin/linux/sinker cmd/sinker/main.go \
 | 
			
		||||
  && go build  -ldflags="-w -s" -o bin/linux/init_app cmd/init_app/main.go
 | 
			
		||||
  && cd .. && export GOOS=linux \
 | 
			
		||||
  && go build  -tags netgo -ldflags "-s -w" -trimpath -buildvcs=false -o bin/linux/manager cmd/manager/main.go  \
 | 
			
		||||
  && go build  -tags netgo -ldflags "-s -w" -trimpath -buildvcs=false -o bin/linux/report_server cmd/report_server/main.go \
 | 
			
		||||
  && go build  -tags netgo -ldflags "-s -w" -trimpath -buildvcs=false -o bin/linux/sinker cmd/sinker/main.go \
 | 
			
		||||
  && go build  -tags netgo -ldflags "-s -w" -trimpath -buildvcs=false -o bin/linux/init_app cmd/init_app/main.go
 | 
			
		||||
echo "build success"
 | 
			
		||||
@ -8,9 +8,19 @@ import (
 | 
			
		||||
	"log"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
//初始化clickhouse 表数据
 | 
			
		||||
func Init() {
 | 
			
		||||
func CreateDb() (func(), error) {
 | 
			
		||||
	config := model.GlobConfig.Comm.ClickHouse
 | 
			
		||||
	dbSource := fmt.Sprintf(
 | 
			
		||||
		"tcp://%s:%s?username=%s&password=%s&compress=true&database=default",
 | 
			
		||||
		config.IP, config.Port, config.Username, config.Pwd)
 | 
			
		||||
 | 
			
		||||
	var err error
 | 
			
		||||
	db.ClickHouseSqlx, err = db.NewSQLX("clickhouse", dbSource, config.MaxOpenConns, config.MaxIdleConns)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Println(fmt.Sprintf("clickhouse 创建 "+model.GlobConfig.Comm.ClickHouse.DbName+" 失败:%s", err.Error()))
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
	defer db.ClickHouseSqlx.Close()
 | 
			
		||||
 | 
			
		||||
	_, err = db.ClickHouseSqlx.Exec(` create database if not exists ` + model.GlobConfig.Comm.ClickHouse.DbName + ` ` + sinker.GetClusterSql())
 | 
			
		||||
 | 
			
		||||
@ -18,6 +28,12 @@ func Init() {
 | 
			
		||||
		log.Println(fmt.Sprintf("clickhouse 建库 "+model.GlobConfig.Comm.ClickHouse.DbName+" 失败:%s", err.Error()))
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
	return func() {}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 初始化clickhouse 表数据
 | 
			
		||||
func Init() (func(), error) {
 | 
			
		||||
	var err error
 | 
			
		||||
 | 
			
		||||
	_, err = db.ClickHouseSqlx.Exec(`DROP TABLE IF EXISTS xwl_acceptance_status` + sinker.GetClusterSql() + `;`)
 | 
			
		||||
 | 
			
		||||
@ -102,4 +118,6 @@ func Init() {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	log.Println("初始化CK数据完成!")
 | 
			
		||||
 | 
			
		||||
	return func() {}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -36,6 +36,7 @@ func main() {
 | 
			
		||||
		application.WithConfigFileExt(configFileExt),
 | 
			
		||||
		application.RegisterInitFnObserver(application.InitLogs),
 | 
			
		||||
		application.RegisterInitFnObserver(application.InitMysql),
 | 
			
		||||
		application.RegisterInitFnObserver(ck.CreateDb),
 | 
			
		||||
		application.RegisterInitFnObserver(application.InitClickHouse),
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -36,8 +36,8 @@
 | 
			
		||||
    "mysql": {
 | 
			
		||||
      "username":"root",
 | 
			
		||||
      "pwd":"dev123",
 | 
			
		||||
      "ip":"192.168.78.128",
 | 
			
		||||
      "port":"3306",
 | 
			
		||||
      "ip":"192.168.6.83",
 | 
			
		||||
      "port":"13306",
 | 
			
		||||
      "dbName":"databi",
 | 
			
		||||
      "maxOpenConns":10,
 | 
			
		||||
      "maxIdleConns":10
 | 
			
		||||
@ -45,7 +45,7 @@
 | 
			
		||||
    "clickhouse": {
 | 
			
		||||
      "username":"root",
 | 
			
		||||
      "pwd":"dev123",
 | 
			
		||||
      "ip":"192.168.78.128",
 | 
			
		||||
      "ip":"192.168.6.83",
 | 
			
		||||
      "port":"9000",
 | 
			
		||||
      "dbName":"databi",
 | 
			
		||||
      "clusterName":"",
 | 
			
		||||
@ -66,7 +66,7 @@
 | 
			
		||||
      "realTimeDataGroup": "realTimeDataGroup2"
 | 
			
		||||
    },
 | 
			
		||||
    "redis": {
 | 
			
		||||
      "addr":"192.168.78.128:6379",
 | 
			
		||||
      "addr":"192.168.6.83:6379",
 | 
			
		||||
      "passwd":"",
 | 
			
		||||
      "db": 7,
 | 
			
		||||
      "maxIdle": 10,
 | 
			
		||||
 | 
			
		||||
@ -57,7 +57,7 @@ func NewSQLX(driverName, dbSource string, maxOpenConns, maxIdleConns int) (db *s
 | 
			
		||||
		for {
 | 
			
		||||
			err = db.Ping()
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				log.Println("mysql db can't connect!")
 | 
			
		||||
				log.Printf("mysql db can't connect!:%v", err)
 | 
			
		||||
			}
 | 
			
		||||
			time.Sleep(time.Minute)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -1,8 +1,11 @@
 | 
			
		||||
FROM openjdk:8-jdk-alpine
 | 
			
		||||
FROM harbor.devops.u.niu/tools/alpine:3.21
 | 
			
		||||
 | 
			
		||||
RUN apk add libc6-compat && apk add tzdata
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
WORKDIR /data
 | 
			
		||||
 | 
			
		||||
COPY init_app .
 | 
			
		||||
COPY linux/init_app .
 | 
			
		||||
 | 
			
		||||
RUN mkdir -p config
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,8 +1,10 @@
 | 
			
		||||
FROM openjdk:8-jdk-alpine
 | 
			
		||||
FROM harbor.devops.u.niu/tools/alpine:3.21
 | 
			
		||||
 | 
			
		||||
RUN apk add libc6-compat && apk add tzdata
 | 
			
		||||
 | 
			
		||||
WORKDIR /data
 | 
			
		||||
 | 
			
		||||
COPY manager .
 | 
			
		||||
COPY linux/manager .
 | 
			
		||||
 | 
			
		||||
RUN mkdir -p config
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										11
									
								
								ops/docker/Dockerfile_reporter
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								ops/docker/Dockerfile_reporter
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
FROM harbor.devops.u.niu/tools/alpine:3.21
 | 
			
		||||
 | 
			
		||||
RUN apk add libc6-compat && apk add tzdata
 | 
			
		||||
 | 
			
		||||
WORKDIR /data
 | 
			
		||||
 | 
			
		||||
COPY linux/report_server .
 | 
			
		||||
 | 
			
		||||
RUN mkdir -p config
 | 
			
		||||
 | 
			
		||||
CMD ["./report_server", "-configFileDir=./config"]
 | 
			
		||||
							
								
								
									
										11
									
								
								ops/docker/Dockerfile_sinker
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								ops/docker/Dockerfile_sinker
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
FROM harbor.devops.u.niu/tools/alpine:3.21
 | 
			
		||||
 | 
			
		||||
RUN apk add libc6-compat && apk add tzdata
 | 
			
		||||
 | 
			
		||||
WORKDIR /data
 | 
			
		||||
 | 
			
		||||
COPY linux/sinker .
 | 
			
		||||
 | 
			
		||||
RUN mkdir -p config
 | 
			
		||||
 | 
			
		||||
CMD ["./sinker", "-configFileDir=./config"]
 | 
			
		||||
							
								
								
									
										18
									
								
								ops/docker/build_all.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										18
									
								
								ops/docker/build_all.sh
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,18 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
set -e
 | 
			
		||||
 | 
			
		||||
apps=(init manager reporter sinker)
 | 
			
		||||
build_ctx="../../bin/linux"
 | 
			
		||||
img_prefix="harbor.gamegold.net.cn/bi"
 | 
			
		||||
img_tag="1.0.1"
 | 
			
		||||
 | 
			
		||||
cp -rf ../../bin/linux .
 | 
			
		||||
 | 
			
		||||
for app in "${apps[@]}"; do
 | 
			
		||||
  echo "准备构建:$app"
 | 
			
		||||
  docker build -t $img_prefix/$app:$img_tag --file Dockerfile_$app .
 | 
			
		||||
  docker push $img_prefix/$app:$img_tag
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
rm -rf linux
 | 
			
		||||
							
								
								
									
										30
									
								
								ops/docker/docker-compose.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								ops/docker/docker-compose.yaml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,30 @@
 | 
			
		||||
services:
 | 
			
		||||
  manager:
 | 
			
		||||
    image: harbor.devops.u.niu/bi/manager:1.0.0
 | 
			
		||||
    restart: always
 | 
			
		||||
    volumes:
 | 
			
		||||
      - ./logs:/data/logs
 | 
			
		||||
      - ./config:/data/config
 | 
			
		||||
      - /etc/localtime:/etc/localtime
 | 
			
		||||
      - /etc/timezone:/etc/timezone
 | 
			
		||||
    ports:
 | 
			
		||||
      - 11090:8090
 | 
			
		||||
  reporter:
 | 
			
		||||
    image: harbor.devops.u.niu/bi/reporter:1.0.0
 | 
			
		||||
    restart: always
 | 
			
		||||
    volumes:
 | 
			
		||||
      - ./logs:/data/logs
 | 
			
		||||
      - ./config:/data/config
 | 
			
		||||
      - /etc/localtime:/etc/localtime
 | 
			
		||||
      - /etc/timezone:/etc/timezone
 | 
			
		||||
    ports:
 | 
			
		||||
      - 11091:8091
 | 
			
		||||
 | 
			
		||||
  sinker:
 | 
			
		||||
    image: harbor.devops.u.niu/bi/sinker:1.0.0
 | 
			
		||||
    restart: always
 | 
			
		||||
    volumes:
 | 
			
		||||
      - ./logs:/data/logs
 | 
			
		||||
      - ./config:/data/config
 | 
			
		||||
      - /etc/localtime:/etc/localtime
 | 
			
		||||
      - /etc/timezone:/etc/timezone
 | 
			
		||||
							
								
								
									
										8
									
								
								ops/docker/run.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								ops/docker/run.sh
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
set -e
 | 
			
		||||
 | 
			
		||||
docker pull harbor.devops.u.niu/bi/init:1.0.0
 | 
			
		||||
docker run -ti -v ./config:/data/config -v /etc/localtime:/etc/localtime -v /etc/timezone:/etc/timezone harbor.devops.u.niu/bi/init:1.0.0
 | 
			
		||||
 | 
			
		||||
docker compose up -d
 | 
			
		||||
@ -10,7 +10,14 @@ import (
 | 
			
		||||
var TokenBucket sync.Map
 | 
			
		||||
 | 
			
		||||
func GetUUid() string {
 | 
			
		||||
	flake := sonyflake.NewSonyflake(sonyflake.Settings{})
 | 
			
		||||
	flake := sonyflake.NewSonyflake(sonyflake.Settings{
 | 
			
		||||
		MachineID: func() (uint16, error) {
 | 
			
		||||
			return uint16(1), nil
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
	if flake == nil {
 | 
			
		||||
		log.Printf("new sony flake error!!")
 | 
			
		||||
	}
 | 
			
		||||
	id, err := flake.NextID()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Println("err", err)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								views/dist/index.html
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								views/dist/index.html
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										1
									
								
								views/dist/static/js/chunk-689cea2e.29aa4e27.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								views/dist/static/js/chunk-689cea2e.29aa4e27.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@ -3,7 +3,8 @@ ENV = 'development'
 | 
			
		||||
 | 
			
		||||
# base api
 | 
			
		||||
# 开发环境
 | 
			
		||||
VUE_APP_BASE_API = 'http://localhost:8090/'
 | 
			
		||||
#VUE_APP_BASE_API = 'http://192.168.6.83:11090/'
 | 
			
		||||
VUE_APP_BASE_API = 'http://192.168.78.128:8090/'
 | 
			
		||||
VUE_APP_BASE_TITLE = '铸龙-埋点数据分析平台(开发)'
 | 
			
		||||
# vue-cli uses the VUE_CLI_BABEL_TRANSPILE_MODULES environment variable,
 | 
			
		||||
# to control whether the babel-plugin-dynamic-import-node plugin is enabled.
 | 
			
		||||
 | 
			
		||||
@ -598,6 +598,7 @@ export default {
 | 
			
		||||
        return
 | 
			
		||||
      }
 | 
			
		||||
      this.metaEventList = res.data.event_name_list
 | 
			
		||||
      console.log("get meta zhibiao:", res.data)
 | 
			
		||||
 | 
			
		||||
      const attributeMap = res.data.attributeMap
 | 
			
		||||
      const allAttrOptions = []
 | 
			
		||||
 | 
			
		||||
@ -50,7 +50,7 @@ module.exports = {
 | 
			
		||||
        changeOrigin: true,
 | 
			
		||||
      },*/
 | 
			
		||||
      [process.env.VUE_APP_BASE_API]: {
 | 
			
		||||
        target: `http://192.168.78.128:${port}`,
 | 
			
		||||
        target: `http://192.168.78.128:${port}/mock`,
 | 
			
		||||
        changeOrigin: true,
 | 
			
		||||
        pathRewrite: {
 | 
			
		||||
          ['^' + process.env.VUE_APP_BASE_API]: ''
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user