diff options
| author | shizhendong <[email protected]> | 2024-05-17 15:22:28 +0800 |
|---|---|---|
| committer | shizhendong <[email protected]> | 2024-05-17 15:22:28 +0800 |
| commit | 9b19f109af4d1831e9a6fef3bb08b372ee7e5ce7 (patch) | |
| tree | 1ba2353d279ad4feeba68736f6be14d03d052e0a | |
| parent | 12ab9ed60fcb8e9d62d86652db0ee09caa0d4c78 (diff) | |
init: init nz_ipmi_exporter cicdnz_ipmi_exporter-24.01.01
| -rw-r--r-- | .gitlab-ci.yml | 2 | ||||
| -rw-r--r-- | tools/afterinstall.sh | 59 | ||||
| -rw-r--r-- | tools/afterremove.sh | 16 | ||||
| -rw-r--r-- | tools/beforeinstall.sh | 18 | ||||
| -rw-r--r-- | tools/ipmi_local.yml | 11 | ||||
| -rw-r--r-- | tools/package.sh | 23 |
6 files changed, 80 insertions, 49 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4c5e6f9..ed28753 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,7 +26,7 @@ build_rpm: - ./tools/package.sh # 在哪个分支上可用 only: - - /^nz_node_exporter-.*$/i + - /^nz_ipmi_exporter-.*$/i # 指定哪个ci runner跑该工作 tags: - nezha diff --git a/tools/afterinstall.sh b/tools/afterinstall.sh index b015491..c611919 100644 --- a/tools/afterinstall.sh +++ b/tools/afterinstall.sh @@ -1,16 +1,16 @@ #!/bin/bash -WORK_DIR=/opt/nezha/node_exporter +WORK_DIR=/opt/nezha/ipmi_exporter fn_init_service(){ - cat > /usr/lib/systemd/system/nz-node-exporter.service <<"EOF" + cat > /usr/lib/systemd/system/nz-ipmi-exporter.service <<"EOF" [Unit] -Description=nz-node-exporter +Description=nz-ipmi-exporter After=network.target [Service] -WorkingDirectory=/opt/nezha/node_exporter -EnvironmentFile=-/opt/nezha/node_exporter/config.conf -ExecStart=/opt/nezha/node_exporter/node_exporter $OPTION +WorkingDirectory=/opt/nezha/ipmi_exporter +EnvironmentFile=-/opt/nezha/ipmi_exporter/config.conf +ExecStart=/opt/nezha/ipmi_exporter/ipmi_exporter $OPTION RestartSec=10s Restart=always LimitNOFILE=524288 @@ -20,21 +20,21 @@ EOF } fn_init_config(){ - cat > /opt/nezha/node_exporter/config.conf <<EOF -OPTION=" --web.listen-address='0.0.0.0:19100' --collector.textfile.directory='/opt/nezha/node_exporter/prom' --collector.os --collector.cpu.info --collector.meminfo --collector.diskstats --collector.filesystem --collector.netdev --collector.netdev.address-info --collector.systemd --collector.systemd.unit-include='(aksusbd|hasplmd).service' " + cat > /opt/nezha/ipmi_exporter/config.conf <<EOF +OPTION=" --web.listen-address='0.0.0.0:19290' --config.file='/opt/nezha/ipmi_exporter/ipmi_local.yml' " EOF } # 初始化 rsyslog & logrotate 配置 fn_init_syslog_logrotate_config(){ - cat > /etc/rsyslog.d/nz-node-exporter.conf << "EOF" -if $programname == 'node_exporter' then { - /var/log/nezha/nz-node-exporter/nz-node-exporter.log + cat > /etc/rsyslog.d/nz-ipmi-exporter.conf << "EOF" +if $programname == 'ipmi_exporter' then { + /var/log/nezha/nz-ipmi-exporter/nz-ipmi-exporter.log stop } EOF - cat > /etc/logrotate.d/nz-node-exporter << "EOF" -/var/log/nezha/nz-node-exporter/*.log { + cat > /etc/logrotate.d/nz-ipmi-exporter << "EOF" +/var/log/nezha/nz-ipmi-exporter/*.log { daily missingok maxsize 100M @@ -64,8 +64,8 @@ compareMD5(){ } # 还原配置文件 -# $1 需要还原的文件目录 /opt/nezha/node_exporter -# $2 备份文件目录 /tmp/nezha/node_exporter +# $1 需要还原的文件目录 /opt/nezha/ipmi_exporter +# $2 备份文件目录 /tmp/nezha/ipmi_exporter restoreComponentConfig(){ if [ ! -d $1 ] || [ ! -d $2 ];then echo "Directory does not exist" @@ -86,11 +86,24 @@ if [ 1 -eq $1 ];then fn_init_service fn_init_syslog_logrotate_config + # 检查命令是否存在,以此判断是否存在 freeipmi 依赖 + if ! command -v bmc-info &> /dev/null || + ! command -v ipmimonitoring &> /dev/null || + ! command -v ipmi-dcmi &> /dev/null || + ! command -v ipmi-sel &> /dev/null; then + + echo 'freeipmi not found, start install' + rpm -ivh /opt/nezha/ipmi_exporter/deps/freeipmi-1.5.7-3.el7.x86_64.rpm + echo 'freeipmi install completed' + else + echo 'freeipmi already exists' + fi + systemctl daemon-reload - systemctl enable nz-node-exporter && systemctl restart nz-node-exporter + systemctl enable nz-ipmi-exporter && systemctl restart nz-ipmi-exporter systemctl enable crond && systemctl restart crond systemctl enable rsyslog && systemctl restart rsyslog - echo 'install nz-node-exporter success !' + echo 'install nz-ipmi-exporter success !' fi # update @@ -99,18 +112,18 @@ if [ 2 -eq $1 ];then fn_init_service fn_init_syslog_logrotate_config - # restore nz-node-exporter config - NZ_NODE_EXPORTER_PATH=/opt/nezha/node_exporter - TMP_PATH=/tmp/nezha/node_exporter + # restore nz-ipmi-exporter config + NZ_IPMI_EXPORTER_PATH=/opt/nezha/ipmi_exporter + TMP_PATH=/tmp/nezha/ipmi_exporter echo 'move backup config file...' if [ -d $TMP_PATH ];then - restoreComponentConfig $NZ_NODE_EXPORTER_PATH $TMP_PATH + restoreComponentConfig $NZ_IPMI_EXPORTER_PATH $TMP_PATH fi # restart all components systemctl daemon-reload - systemctl enable nz-node-exporter && systemctl restart nz-node-exporter + systemctl enable nz-ipmi-exporter && systemctl restart nz-ipmi-exporter systemctl enable crond && systemctl restart crond systemctl enable rsyslog && systemctl restart rsyslog - echo 'update nz-node-exporter success !' + echo 'update nz-ipmi-exporter success !' fi diff --git a/tools/afterremove.sh b/tools/afterremove.sh index fd5fa76..af18cef 100644 --- a/tools/afterremove.sh +++ b/tools/afterremove.sh @@ -1,21 +1,21 @@ #!/bin/bash # 安装目录 -NZ_NODE_EXPORTER_PATH=/opt/nezha/node_exporter +NZ_IPMI_EXPORTER_PATH=/opt/nezha/ipmi_exporter if [ 0 -eq $1 ];then - echo 'start remove nz-node-exporter from disk...' + echo 'start remove nz-ipmi-exporter from disk...' - systemctl stop nz-node-exporter.service + systemctl stop nz-ipmi-exporter.service - rm -rf $NZ_NODE_EXPORTER_PATH + rm -rf $NZ_IPMI_EXPORTER_PATH - systemctl disable nz-node-exporter.service + systemctl disable nz-ipmi-exporter.service - rm -rf /usr/lib/systemd/system/nz-node-exporter.service - rm -rf /etc/rsyslog.d/nz-node-exporter.conf - rm -rf /etc/logrotate.d/nz-node-exporter + rm -rf /usr/lib/systemd/system/nz-ipmi-exporter.service + rm -rf /etc/rsyslog.d/nz-ipmi-exporter.conf + rm -rf /etc/logrotate.d/nz-ipmi-exporter systemctl daemon-reload systemctl restart rsyslog diff --git a/tools/beforeinstall.sh b/tools/beforeinstall.sh index 15fe3aa..c591940 100644 --- a/tools/beforeinstall.sh +++ b/tools/beforeinstall.sh @@ -1,23 +1,23 @@ #!/bin/bash # 安装目录 -NZ_NODE_EXPORTER_PATH=/opt/nezha/node_exporter +NZ_IPMI_EXPORTER_PATH=/opt/nezha/ipmi_exporter # 临时目录 -TMP_PATH=/tmp/nezha/node_exporter +TMP_PATH=/tmp/nezha/ipmi_exporter # 备份配置 -if [ -d $NZ_NODE_EXPORTER_PATH ];then +if [ -d $NZ_IPMI_EXPORTER_PATH ];then rm -rf $TMP_PATH mkdir -p $TMP_PATH - file=$NZ_NODE_EXPORTER_PATH/config.conf && [ -f "${file}" ] && \cp -f ${file} $TMP_PATH - echo 'backup config file from '${NZ_NODE_EXPORTER_PATH} + file=$NZ_IPMI_EXPORTER_PATH/config.conf && [ -f "${file}" ] && \cp -f ${file} $TMP_PATH + echo 'backup config file from '${NZ_IPMI_EXPORTER_PATH} fi # 停止服务并卸载 -if [ 0 -lt $(rpm -aq nz-node-exporter|wc -w) ];then - echo "stop nz-node-exporter service" - systemctl stop nz-node-exporter.service +if [ 0 -lt $(rpm -aq nz-ipmi-exporter|wc -w) ];then + echo "stop nz-ipmi-exporter service" + systemctl stop nz-ipmi-exporter.service echo 'clean before install...' - rm -rf $NZ_NODE_EXPORTER_PATH + rm -rf $NZ_IPMI_EXPORTER_PATH fi diff --git a/tools/ipmi_local.yml b/tools/ipmi_local.yml new file mode 100644 index 0000000..5fd331b --- /dev/null +++ b/tools/ipmi_local.yml @@ -0,0 +1,11 @@ +modules: + # cloudatlas: + default: + # Available collectors are bmc, bmc-watchdog, ipmi, chassis, dcmi, sel, sel-events and sm-lan-mode + collectors: + - bmc + - ipmi + - dcmi + - chassis + - sel + - sel-events diff --git a/tools/package.sh b/tools/package.sh index f69efb2..74c68c6 100644 --- a/tools/package.sh +++ b/tools/package.sh @@ -2,7 +2,7 @@ set -evx CUR_PWD=`pwd` -PACKAGE_NAME=nz-node-exporter +PACKAGE_NAME=nz-ipmi-exporter BRANCH_ARRAY=(${CI_COMMIT_REF_NAME//-/ }) PACKAGE_VERSION=${BRANCH_ARRAY[1]}.$CI_COMMIT_SHORT_SHA ITERATION=Release @@ -13,21 +13,28 @@ RPM_FULL_NAME=${PACKAGE_NAME}-${PACKAGE_VERSION}-${ITERATION}.x86_64.rpm mc alias set nz $MINIO_HOST $MINIO_USER $MINIO_PWD #依赖包版本 -NODE_EXPORTER_PKG=node_exporter-1.7.0.linux-amd64.tar.gz +IPMI_EXPORTER_PKG=ipmi_exporter-1.8.0.linux-amd64.tar.gz # 拉取依赖文件 -mc cp nz/depends/exporter/$NODE_EXPORTER_PKG ./ +mc cp nz/depends/exporter/$IPMI_EXPORTER_PKG ./ +mc cp nz/depends/exporter/freeipmi-1.5.7-3.el7.x86_64.rpm ./ # rpm 编译目录 BUILD_PATH=$CUR_PWD/build -RPM_NZ_NODE_EXPORTER_PATH=$BUILD_PATH/opt/nezha/node_exporter +RPM_NZ_IPMI_EXPORTER_PATH=$BUILD_PATH/opt/nezha/ipmi_exporter -mkdir -p $BUILD_PATH $RPM_NZ_NODE_EXPORTER_PATH $RPM_NZ_NODE_EXPORTER_PATH/prom +mkdir -p $BUILD_PATH $RPM_NZ_IPMI_EXPORTER_PATH $RPM_NZ_IPMI_EXPORTER_PATH/deps -echo 'packaging begin ...' +echo 'packaging begin ...' # 解压 -tar -xzf ./$NODE_EXPORTER_PKG --strip-components 1 -C $RPM_NZ_NODE_EXPORTER_PATH +tar -xzf ./$IPMI_EXPORTER_PKG --strip-components 1 -C $RPM_NZ_IPMI_EXPORTER_PATH + +# 配置文件 +cp ./tools/ipmi_local.yml $RPM_NZ_IPMI_EXPORTER_PATH + +# 依赖资源 +cp freeipmi-1.5.7-3.el7.x86_64.rpm $RPM_NZ_IPMI_EXPORTER_PATH/deps fpm -s dir -t rpm -n ${PACKAGE_NAME} -v ${PACKAGE_VERSION} --iteration ${ITERATION} --rpm-os 'linux' \ --pre-install ./tools/beforeinstall.sh \ @@ -44,4 +51,4 @@ cd $CUR_PWD mc cp $BUILD_PATH/$RPM_FULL_NAME nz/release/$PACKAGE_NAME/$RPM_FULL_NAME mc cp $BUILD_PATH/$RPM_FULL_NAME.md5sum.txt nz/release/$PACKAGE_NAME/$RPM_FULL_NAME.md5sum.txt -echo 'package finished' +echo 'package finished' |
