prometheus制作rpm包

参考:Prometheus打rpm包_怎么会这样!的博客-CSDN博客_prometheus rpm

1.安装工具

[root@centos-02 ~]# yum -y install rpm-build
[root@centos-02 ~]# cd /opt
安装npm
[root@centos-02 ~]# wget https://npm.taobao.org/mirrors/node/v10.14.1/node-v10.14.1-linux-x64.tar.gz
[root@centos-02 ~]# tar -xvf  node-v10.14.1-linux-x64.tar.gz
[root@centos-02 ~]# mv node-v10.14.1-linux-x64 node
[root@centos-02 ~]# vi /etc/profile
export NODE_HOME=/opt/node
export PATH=$NODE_HOME/bin:$PATH
[root@centos-02 ~]# source /etc/profile
[root@centos-02 ~]# node -v 
v10.14.1
[root@centos-02 ~]# npm -v
6.4.1
安装go
[root@centos-02 ~]# wget https://golang.google.cn/dl/go1.17.6.linux-amd64.tar.gz
[root@centos-02 ~]# tar -C /usr/local -xzf go1.17.6.linux-amd64.tar.gz
[root@centos-02 ~]# vim /etc/profile
export PATH=$PATH:/usr/local/go/bin
[root@centos-02 ~]# source /etc/profile
[root@centos-02 ~]# go version
go version go1.17.6 linux/amd64
安装yarn
[root@centos-02 ~]# npm install -g yarn
[root@centos-02 ~]# yarn -v
1.22.19

2.生成目录结构

rpmbuild -ba xxx.spec ##输入任意 **.spec,

这一步报错,此时将自动生成目录 error: failed to stat /root/nginx.spec: No such file or directory

ls /root/rpmbuild/ ##查看自动生成的目录结构

BUILD BUILDROOT RPMS SOURCES SPECS SRPMS

3.上传压缩包到SOURCES并编写service和yml文件

[root@centos-02 SOURCES]# ll
total 13452
-rw-r--r-- 1 root root 13764715 Dec 23 08:39 prometheus-2.20.1.tar.gz
-rw-r--r-- 1 root root      625 Dec 23 09:51 prometheus.service
-rw-r--r-- 1 root root      915 Dec 23 09:50 prometheus.yml
[root@centos-02 SOURCES]# cat prometheus.service 
[Unit]
Description=The Prometheus 2 monitoring system and time series database.
Documentation=https://prometheus.io
After=network.target

[Service]
User=prometheus
ExecStart=/usr/bin/prometheus \
          --web.console.libraries=/usr/share/prometheus/console_libraries \
          --web.console.templates=/usr/share/prometheus/consoles \
          --web.enable-lifecycle \
          --web.listen-address=:9999 --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus/data
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=5s
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

[root@centos-02 SOURCES]# cat prometheus.yml 
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9999"]

4、创建修改SPEC配置文件

[root@centos-02 SPECS]# cat prometheus.spec
%define debug_package %{nil}
%{!?upstream_version: %global upstream_version %{version}%{?milestone}}
%global with_doc 0
%global service prometheus

Name:          prometheus
Version:       2.20.1
Release:      1%{?dist}
Summary:      The Prometheus 2.x monitoring system and time series database.
License:      ASL 2.0
#Group
URL:            test.rpm.com
Source0:      %{service}-%{version}.tar.gz
Source1:          prometheus.service
Source3:          prometheus.yml
#Source11:         prometheus_manage.service
#Source31:         prometheus_manage.yml
#BuildRequires:        gcc, pcre2-devel,openssl-devel
#Requires: 
%description 
build prometheus
%prep 
%autosetup -n %{service}-%{upstream_version}
%setup -q
%build
make build
%install 
mkdir -vp %{buildroot}%{_sharedstatedir}/prometheus
mkdir -vp %{buildroot}%{_sharedstatedir}/prometheus_manage
install -D -m 755 prometheus %{buildroot}%{_bindir}/prometheus
install -D -m 755 promtool %{buildroot}%{_bindir}/promtool
for dir in console_libraries consoles; do
  for file in ${dir}/*; do
    install -D -m 644 ${file} %{buildroot}%{_datarootdir}/prometheus/${file}
  done
done
install -D -m 644 %{SOURCE3} %{buildroot}%{_sysconfdir}/prometheus/prometheus.yml
#install -D -m 644 %{SOURCE31} %{buildroot}%{_sysconfdir}/prometheus_manage/prometheus_manage.yml
install -D -m 644 %{SOURCE1} %{buildroot}%{_unitdir}/prometheus.service
#install -D -m 644 %{SOURCE11} %{buildroot}%{_unitdir}/prometheus_manage.service

%pre
getent group prometheus >/dev/null || groupadd -r prometheus
getent passwd prometheus >/dev/null || \
  useradd -r -g prometheus -d %{_sharedstatedir}/prometheus -s /sbin/nologin \
          -c "Prometheus services" prometheus
  useradd -r -g prometheus -d %{_sharedstatedir}/prometheus_manage -s /sbin/nologin \
          -c "Prometheus services" prometheus
exit 0

%post
%systemd_post prometheus.service
#%systemd_post prometheus_manage.service

%preun
%systemd_preun prometheus.service
#%systemd_preun prometheus_manage.service

%postun
%systemd_postun prometheus.service
#%systemd_postun prometheus_manage.service
%files 
%defattr(-,root,root,-)
%{_bindir}/prometheus
%{_bindir}/promtool
%config(noreplace) %{_sysconfdir}/prometheus/prometheus.yml
#%config(noreplace) %{_sysconfdir}/prometheus_manage/prometheus_manage.yml
%{_datarootdir}/prometheus
%{_unitdir}/prometheus.service
#%{_unitdir}/prometheus_manage.service
%dir %attr(755, prometheus, prometheus)%{_sharedstatedir}/prometheus
#%dir %attr(755, prometheus, prometheus)%{_sharedstatedir}/prometheus_manage
%doc
#%changelog

5.构建

[root@centos-02 ~]# rpmbuild -ba /root/rpmbuild/SPECS/prometheus.spec
[root@centos-02 x86_64]# pwd
/root/rpmbuild/RPMS/x86_64
[root@centos-02 x86_64]# ll
total 22552
-rw-r--r-- 1 root root 23092408 Dec 23 09:59 prometheus-2.20.1-1.el7.x86_64.rpm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值