Skip to content

Commit

Permalink
Merge pull request #6361 from Tencent/r1731
Browse files Browse the repository at this point in the history
R1731
  • Loading branch information
irwinsun authored Mar 18, 2022
2 parents 4fe96c9 + 616dc45 commit 56deb93
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 12 deletions.
16 changes: 10 additions & 6 deletions scripts/bk-ci-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,22 @@ install_ci__ms_common (){
tip_dir_exist "$BK_CI_SRC_DIR/$MS_NAME" || return 16
# 检查安装java
install_java || return $?
# 备份配置文件
backup_time=$(date +'%Y%m%d%H%M')
mkdir -p /tmp/ci/$backup_time
find "$BK_CI_HOME" -name "*.env"|xargs -i -n 1 cp -rvnP --parents {} /tmp/ci/$backup_time/ > /dev/null
# 增量复制.
rsync -ra "$BK_CI_SRC_DIR/$MS_NAME/" "$BK_CI_HOME/$MS_NAME"
rsync -ra --delete "$BK_CI_SRC_DIR/$MS_NAME/" "$BK_CI_HOME/$MS_NAME"
for f in agent-package jars-public jars-private scripts VERSION; do
[ -e "$BK_CI_SRC_DIR/$f" ] || continue
echo "install $BK_CI_SRC_DIR/$f to $BK_CI_HOME."
rsync -ra "$BK_CI_SRC_DIR/${f%/}" "$BK_CI_HOME"
rsync -ra --delete "$BK_CI_SRC_DIR/${f%/}" "$BK_CI_HOME"
done
echo "change mode for agent-package dir."
find "$BK_CI_HOME/agent-package/" -type d -exec chmod -c a+rx {} \;
find "$BK_CI_HOME/agent-package/" -type f -exec chmod -c a+r {} \;
# 保持微服务部分子目录的强一致性.
rsync -ra --del "$BK_CI_SRC_DIR/$MS_NAME/lib" "$BK_CI_SRC_DIR/$MS_NAME/com" "$BK_CI_HOME/$MS_NAME"
rsync -ra --delete "$BK_CI_SRC_DIR/$MS_NAME/lib" "$BK_CI_SRC_DIR/$MS_NAME/com" "$BK_CI_HOME/$MS_NAME"
}

install_ci_dockerhost (){
Expand Down Expand Up @@ -141,10 +145,10 @@ install_ci_gateway (){
local proj=$1
install_openresty || return $?
rsync -ra "$BK_CI_SRC_DIR/gateway" "$BK_CI_HOME" # 不能del, 会删除codecc注入的配置文件.
rsync -ra --del "$BK_CI_SRC_DIR/frontend" "$BK_CI_HOME" # frontend不必verbose.
rsync -ra "$BK_CI_SRC_DIR/agent-package" "$BK_CI_HOME" # #3707 网关提供jars下载.
rsync -ra --delete "$BK_CI_SRC_DIR/frontend" "$BK_CI_HOME" # frontend不必verbose.
rsync -ra --delete "$BK_CI_SRC_DIR/agent-package" "$BK_CI_HOME" # #3707 网关提供jars下载.
if [ -d "$BK_CI_SRC_DIR/docs" ]; then
rsync -ra --del "$BK_CI_SRC_DIR/docs" "$BK_CI_HOME" || return $? # 可选docs
rsync -ra --delete "$BK_CI_SRC_DIR/docs" "$BK_CI_HOME" || return $? # 可选docs
fi
}

Expand Down
90 changes: 90 additions & 0 deletions scripts/bk-ci-reg-influxdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash
SELF_DIR=$(dirname "$(readlink -f "$0")")
set -eu
trap "on_ERR;" ERR
on_ERR (){
local fn=$0 ret=$? lineno=${BASH_LINENO:-$LINENO}
echo >&2 "ERROR $fn exit with $ret at line $lineno: $(sed -n ${lineno}p $0)."
}

source ${CTRL_DIR:-/data/install}/load_env.sh
source ${CTRL_DIR:-/data/install}/bin/04-final/ci.env
export INFLUXDB_PORT=8086
INFLUXDB_VERSION=1.7.10

if [[ ${LAN_IP} != "${BK_CI_IP0}" ]] ; then echo "仅支持在CI第一台服务运行" ; exit 1 ; fi
if grep -w "disable rsyslog rate limit" /etc/rsyslog.conf ; then sed -i -e '/disable rsyslog rate limit/s/^/#&/' /etc/rsyslog.conf ; fi
if grep -w "disable journald rate limit" /etc/rsyslog.conf ; then sed -i -e '/disable journald rate limit/s/^/#&/' /etc/rsyslog.conf ; fi

port_test () {
ip="$1"
port=$2
resFile=/tmp/influxdb_test_temptelnnfdswg

#echo "telnet $ip $port..."
/usr/bin/expect >${resFile} 2>&1 <<EOF
set timeout 5
spawn telnet $ip $port
expect {
"Connected*" {
send "q\r"
exit 0
}
"Connection refused" {
puts "refused\r"
exit 1
}
timeout {
puts "timeout\r"
exit 2
}
}
exit
expect eof
EOF
}

if rpm -qa|grep -w influxdb-${INFLUXDB_VERSION} ; then
echo "influxdb already installed"
else
echo "install influxdb now"
if ${CTRL_DIR}/bin/install_influxdb.sh -b 0.0.0.0 -P ${INFLUXDB_PORT} -d ${INSTALL_PATH}/public/influxdb -l ${INSTALL_PATH}/logs/influxdb -w ${INSTALL_PATH}/public/influxdb/wal -p ${BK_INFLUXDB_ADMIN_PASSWORD} -u admin ; then
echo "influxdb install success"
else
echo "influxdb install failed" ; exit 1
fi
fi

#port_test $BK_INFLUXDB_IP0 $INFLUXDB_PORT
#
#if [[ ! -z `grep -w "Escape" /tmp/influxdb_test_temptelnnfdswg` ]] ; then
# echo "bkmonitorv3 influxdb exist"
# if influx -host $BK_INFLUXDB_IP0 -port $INFLUXDB_PORT -username $BK_INFLUXDB_ADMIN_USER -password $BK_INFLUXDB_ADMIN_PASSWORD -execute "SHOW DATABASES;"|grep agentMetrix ; then
# echo "ci influxdb database agentMetrix already created on bkmonitorv3 influxdb"
# else
# if influx -host $BK_INFLUXDB_IP0 -port $INFLUXDB_PORT -username $BK_INFLUXDB_ADMIN_USER -password $BK_INFLUXDB_ADMIN_PASSWORD -execute "CREATE DATABASE agentMetrix" ; then
# echo "ci influxdb database agentMetrix create success on bkmonitorv3 influxdb"
# else
# echo "ci influxdb database agentMetrix create failed on bkmonitorv3 influxdb" ; exit 2
# fi
# fi
#else
# echo "bkmonitorv3 influxdb not exist , create influxdb on ci-01"
systemctl start influxd.service ; sleep 5
if systemctl status influxd.service|grep -w "active (running)" ; then
echo "influxdb start success installed"
if influx -host $BK_CI_IP0 -port $INFLUXDB_PORT -username $BK_INFLUXDB_ADMIN_USER -password $BK_INFLUXDB_ADMIN_PASSWORD -execute "SHOW DATABASES;"|grep agentMetrix ; then
echo "influxdb agentMetrix already created on ci-01 influxdb"
else
if influx -host $BK_CI_IP0 -port $INFLUXDB_PORT -username $BK_INFLUXDB_ADMIN_USER -password $BK_INFLUXDB_ADMIN_PASSWORD -execute "CREATE DATABASE agentMetrix" ; then
echo "influxdb agentMetrix create success on ci-01 influxdb"
else
echo "influxdb agentMetrix create failed on ci-01 influxdb" ; exit 3
fi
fi
else
echo "influxdb start failed" ; exit 5
fi
#fi

#rm -f /tmp/influxdb_test_temptelnnfdswg
9 changes: 8 additions & 1 deletion scripts/bkce-set-env03.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ set_env03 BK_HTTP_SCHEMA=http \
BK_CI_PAAS_LOGIN_URL=\$BK_PAAS_PUBLIC_URL/login/\?c_url= \
BK_CI_REPOSITORY_GITLAB_URL=http://\$BK_CI_FQDN \
BK_CI_APP_CODE=bk_ci \
BK_CI_APP_TOKEN=$(uuid_v4)
BK_CI_APP_TOKEN=$(uuid_v4) \
BK_REPO_GATEWAY_IP=$BK_REPO_GATEWAY_IP \
BK_CI_INFLUXDB_ADDR=$BK_CI_IP0:8086 \
BK_CI_INFLUXDB_DB=agentMetrix \
BK_CI_INFLUXDB_HOST=$BK_CI_IP0 \
BK_CI_INFLUXDB_PASSWORD=$BK_INFLUXDB_ADMIN_PASSWORD \
BK_CI_INFLUXDB_PORT=8086 \
BK_CI_INFLUXDB_USER=admin
# 复用es7, 读取账户密码, 刷新03env.
set_env03 BK_CI_ES_REST_ADDR=$BK_ES7_IP BK_CI_ES_USER=elastic BK_CI_ES_PASSWORD=$BK_ES7_ADMIN_PASSWORD
# 复用rabbitmq, 生成密码并创建账户, 刷新03env.
Expand Down
6 changes: 3 additions & 3 deletions scripts/bkenv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ BK_CI_ES_REST_ADDR=127.0.0.1
BK_CI_ES_REST_PORT=9200
# BK_CI_ES_USER无默认值. 按需修改. ElasticSearch用户名, 如设置则启用认证.
BK_CI_ES_USER=
# BK_CI_INFLUXDB_ADDR默认为127.0.0.1:8086. 按需修改. 第三方构建机状态上报时用. BK_CI_ENVIRONMENT_AGENT_COLLECTOR_ON
BK_CI_INFLUXDB_ADDR=127.0.0.1:8086
# BK_CI_INFLUXDB_DB默认为agentMetrix. 请勿修改. 采集数据的数据库名.
# BK_CI_INFLUXDB_ADDR默认为http://127.0.0.1:8086. 按需修改. 第三方构建机状态上报还要设置 BK_CI_ENVIRONMENT_AGENT_COLLECTOR_ON
BK_CI_INFLUXDB_ADDR=http://127.0.0.1:8086
# BK_CI_INFLUXDB_DB默认为agentMetrix. 请勿修改. 采集数据的数据库名. 请创建数据库:CREATE DATABASE agentMetrix
BK_CI_INFLUXDB_DB=agentMetrix
# BK_CI_INFLUXDB_HOST默认为127.0.0.1. 按需修改. 网关目前需要分别指定主机名及端口
BK_CI_INFLUXDB_HOST=127.0.0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ class InfluxdbClient {
val influxdbPassword: String = ""

private val influxdb by lazy {
if (influxdbUserName.isBlank())
if (influxdbUserName.isBlank()) {
InfluxDBFactory.connect(influxdbServer)
else
} else {
InfluxDBFactory.connect(influxdbServer, influxdbUserName, influxdbPassword)
}
}

fun getInfluxDb(): InfluxDB? {
Expand Down
3 changes: 3 additions & 0 deletions support-files/templates/gateway#core#devops.server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ server {
# 文档中心
include docs.conf;

# 构建机状态采集上报 influxdb
include influxdb.conf;

# 重定向
include vhosts/devops.redirect.conf;
}

0 comments on commit 56deb93

Please sign in to comment.