dockerfile
构建telegraf_py
版及oracle
客户端
概览:
容器内:
- 部署telegraf
- 部署oracle客户端
- 安装python3环境
- 安装cx_Oracle库
脚本用于构建telegraf python
环境 配合python
脚本用于监控oracle
功能
- 内部配置完成python环境
- 容器内可访问外部网络
- 内部部署oracle客户端容器构建完成后可连接oracle数据库
一. 启动脚本
1 2 3 4 5 6 7 8 9 10 11 12
| #!/bin/bash
export ORACLE_HOME=/home/oracle/instantclient_11_2 export TNS_ADMIN=$ORACLE_HOME/network/admin
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 export LD_LIBRARY_PATH=$ORACLE_HOME export PATH=$ORACLE_HOME:$PATH
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
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/
RUN chmod a+x /opt/telegraf-1.20.4/qidong.sh
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/
EXPOSE 8092 EXPOSE 8094 EXPOSE 8152
CMD ["bash /opt/telegraf-1.20.4/qidong.sh"]
|
build
1 2 3 4 5
| docker build -f /home/Dockerfile/Dockerfile -t zznn/telegraf .
docker pull registry.cn-hangzhou.aliyuncs.com/zznn/mycentos:telegraf_oracle-py
|
二. 利用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 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
|
结语祝好!