壓縮nagios 原始檔案
-- nagios need file
tar --exclude="/usr/local/pnp4nagios/var/perfdata/*" --exclude="/usr/local/nagios/var/archives/*" \
-cvzf /home/mikeschsieh/DOCKER/NAGIOS/nagiosfull_20230512_v4.4.11.tar.gz \
/usr/lib/systemd/system/nagios.service \
/usr/lib/systemd/system/xinetd.service \
/etc/xinetd.d/live \
/etc/init.d/npcd \
/etc/init.d/pnp_gearman_worker \
/usr/local/nagios \
/usr/local/nagvis \
/usr/local/nrdp \
/usr/local/pnp4nagios \
/etc/httpd/conf.d/nagvis.conf \
/etc/httpd/conf.d/pnp4nagios.conf \
/etc/httpd/conf.d/nagios.conf
---
- entrypoint.sh
#!/bin/bash
echo "Starting PHP-FPM in background"
php-fpm -D
echo "Starting nagios"
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
/usr/local/pnp4nagios/bin/npcd -d -f /usr/local/pnp4nagios/etc/npcd.cfg
echo "start httpd "
/usr/sbin/httpd -f /etc/httpd/conf/httpd.conf
/usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid
bash
---
Dockerfile
FROM rockylinux:8.7.20230215
LABEL maintainer="MikeSCHsieh <cc.vbhsieh@gmail.com>"
LABEL maintainer="website : https://jeffwen0105.com/"
RUN yum install -y perl php httpd xinetd net-snmp-perl net-snmp-utils java \
net-snmp rrdtool perl-rrdtool perl-Time-HiRes php-gd php-xml net-tools \
php-json php-mbstring php-pdo graphviz
ENV TZ="Asia/Taipei"
# 更新系统并安装所需的软件包
RUN dnf update -y && \
dnf install -y tzdata && \
dnf clean all
# 将/etc/localtime链接到正确的时区文件
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
echo $TZ > /etc/timezone
RUN useradd -u 1001 nagios
RUN groupadd -g 1003 nagcmd
RUN usermod -a -G apache nagios
RUN usermod -a -G nagcmd nagios
RUN usermod -a -G nagcmd apache
RUN mkdir /run/php-fpm
COPY ./nagiosfull_20230508_v4.4.11.tar.gz /tmp/nagiosfull.tar.gz
COPY ./php.ini /etc/php.ini
RUN tar -C / -zxvf /tmp/nagiosfull.tar.gz
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
CMD ["/usr/local/bin/entrypoint.sh"]
---
- run.sh
docker run -i -t -d -p 80:80 -p 6557:6557 \
-v /usr/local/nagios/libexec:/usr/local/nagios/libexec \
-v /usr/local/nagios/etc/objects/config:/usr/local/nagios/etc/objects/config \
-v /usr/local/nagios/etc/nagios.cfg:/usr/local/nagios/etc/nagios.cfg \
-v /etc/hosts:/etc/hosts \
-v /usr/local/pnp4nagios/var/perfdata:/usr/local/pnp4nagios/var/perfdata \
nagios
--
原始主機加入
~/.bash_profile
加入:
DN=/home/mikeschsieh/DOCKER/NAGIOS
alias RUN='sh $DN/run.sh'
alias cdNAGIOS='cd $DN'
alias BUILD='docker build -t nagios .'
alias PS='docker ps -a'
GETPID(){
PID=`docker ps | awk '{if(NR>1)print $1}'`
}
CMD(){
GETPID
docker exec -it $PID bash
}
RM(){
GETPID
docker rm -f $PID
}