dockerfile构建telegraf_py版及oracle客户端

概览:

容器内:

  1. 部署telegraf
  2. 部署oracle客户端
  3. 安装python3环境
  4. 安装cx_Oracle库

脚本用于构建telegraf python环境 配合python脚本用于监控oracle

功能

  1. 内部配置完成python环境
  2. 容器内可访问外部网络
  3. 内部部署oracle客户端容器构建完成后可连接oracle数据库

一. 启动脚本

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash

#oracle
export ORACLE_HOME=/home/oracle/instantclient_11_2
export TNS_ADMIN=$ORACLE_HOME/network/admin
#export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export LD_LIBRARY_PATH=$ORACLE_HOME
export PATH=$ORACLE_HOME:$PATH
#source /etc/profile
nohup /opt/telegraf-1.20.4/usr/bin/telegraf --config /opt/telegraf-1.20.4/etc/telegraf/telegraf.conf \
--config-directory /opt/telegraf-1.20.4/etc/telegraf/telegraf.d &

二. dockerfile脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
FROM centos:7
RUN yum update -y
RUN yum install -y python3 \
&& yum -y install epel-release
#yum update -y \
#yum install -y python3 \
RUN yum install -y python-pip
RUN pip3 install --upgrade pip==19.3.1
RUN pip3 install cx_Oracle
RUN yum install -y unzip \
&& mkdir -p /opt/telegraf
ADD ./telegraf-1.20.4_linux_amd64.tar.gz /opt/
RUN chmod a+x /opt/telegraf-1.20.4/usr/bin/telegraf
COPY ./telegraf.conf /opt/telegraf-1.20.4/etc/telegraf/
COPY ./qidong.sh /opt/telegraf-1.20.4/
#COPY ./telegraf.conf /opt/telegraf/
RUN chmod a+x /opt/telegraf-1.20.4/qidong.sh
#构建oracle客客户端
COPY ./profile /etc
RUN mkdir -p /home/oracle \
&& chmod 755 /home/oracle -R \
&& yum install -y libaio* \
&& yum install -y vim
ADD ./instantclient_11_2.tar.gz /home/oracle/
#RUN unzip /home/oracle/instantclient-basic-linux.x64-11.2.0.4.0.zip \
#&& unzip /home/oracle/instantclient-precomp-linux-11.2.0.4.0.zip \
#&& unzip /home/oracle/instantclient-sdk-linux.x64-11.2.0.4.0.zip \
#&& unzip /home/oracle/instantclient-sqlplus-linux.x64-11.2.0.4.0.zip
EXPOSE 8092
EXPOSE 8094
EXPOSE 8152
#CMD ["/opt/telegraf-1.20.4/usr/bin/telegraf --config /opt/telegraf-1.20.4/etc/telegraf/telegraf.conf \
#--config-directory /opt/telegraf-1.20.4/etc/telegraf/telegraf.d"]
CMD ["bash /opt/telegraf-1.20.4/qidong.sh"]

build

1
2
3
4
5
# 构建
docker build -f /home/Dockerfile/Dockerfile -t zznn/telegraf .
# push到私人仓库
# 拉取
docker pull registry.cn-hangzhou.aliyuncs.com/zznn/mycentos:telegraf_oracle-py

image-20230512142122678

二. 利用docker-compose使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
version: "3.0"
services:
telegraf-py: #采集工具一个
image: registry.cn-hangzhou.aliyuncs.com/zznn/mycentos:telegraf_oracle-py
restart: always
container_name: telegraf-py
hostname: telegraf
environment:
TZ: Asia/Shanghai
ports:
- 9273:9273
volumes:
- ./telegraf.conf:/opt/telegraf-1.20.4/etc/telegraf/telegraf.conf
# - ./telegraf/telegraf.d/:/etc/telegraf/telegraf.d/
# - ./telegraf/mibs/:/usr/share/snmp/mibs/
# - ./telegraf/etc:/etc/snmp/
command: /opt/telegraf-1.20.4/usr/bin/telegraf --config /opt/telegraf-1.20.4/etc/telegraf/telegraf.conf --config-directory /opt/telegraf-1.20.4/etc/telegraf/telegraf.d

结语祝好!