1、打nginx原始包
ROM nginx
ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8
ENV TZ Asia/Singapore
# 设置时区,同样保持在一层
RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime && \
echo "${TZ}" > /etc/timezone
RUN apt-get update && \
apt-get install -y logrotate cron iputils-ping vim procps net-tools && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
curl -o /etc/logrotate.d/nginx https://ichamet-test.oss-ap-southeast-1.aliyuncs.com/jdk/nginx && \
curl -o /opt/clear_disk_logs_nginx.sh https://ichamet-test.oss-ap-southeast-1.aliyuncs.com/jdk/clear_disk_logs_nginx.sh && \
chmod +x /opt/clear_disk_logs_nginx.sh && \
(crontab -l 2>/dev/null; echo "0 6 * * * /bin/sh /opt/clear_disk_logs_nginx.sh") | crontab -u root -
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
对应用到的脚本文件
[webadmin@test jdk]$ cat nginx
/var/log/nginx/*.log {
daily
missingok
rotate 3
compress
delaycompress
notifempty
create 640 nginx adm
sharedscripts
postrotate
if [ -f /var/run/nginx.pid ]; then
kill -USR1 `cat /var/run/nginx.pid`
fi
endscript
}
[webadmin@test jdk]$ cat clear_disk_logs_nginx.sh
#!/bin/sh
for item in $(find /var/log/nginx/ -name "*.log")
do
stdout_num=$(du -sk "$item" | awk '{print $1}')
if [ $stdout_num -gt 10 ]
then
echo "$(date +'%Y%m%d %H:%M:%S') clear disk" > "$item"
fi
done
- 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.
2、服务java使用的原始包
FROM centos:centos7.8.2003
# 设置环境变量,合并为一层处理
ENV JAVA_HOME /usr/lib/jvm/jdk1.8.0_131
ENV PATH ${JAVA_HOME}/bin:${PATH}
ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8
ENV TZ Asia/Singapore
# 设置时区,同样保持在一层
RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime && \
echo "${TZ}" > /etc/timezone
# 更新yum源并安装必要的软件包,同时清理yum缓存
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo && \
yum install -y kde-l10n-Chinese glibc-common telnet net-tools lrzsz wget cronie && \
yum clean all && \
localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
# 合并COPY和解压JDK到一个RUN指令中,减少镜像层数
RUN mkdir -p /usr/lib/jvm && \
curl -o /opt/clear_disk_logs.sh https://xxx.aliyuncs.com/jdk/clear_disk_logs.sh && \
chmod +x /opt/clear_disk_logs.sh && \
(crontab -l 2>/dev/null; echo "0 * * * * /bin/bash /opt/clear_disk_logs.sh") | crontab -u root - && \
curl -o /opt/liveProbe.sh https://xxx.aliyuncs.com/jdk/liveProbe.sh && \
chmod +x /opt/liveProbe.sh && \
curl -o /opt/offline.sh https://xxx.aliyuncs.com/jdk/offline.sh && \
chmod +x /opt/offline.sh && \
curl -o /tmp/jdk1.8.0_131.tar https://xxx.aliyuncs.com/jdk/jdk1.8.0_131.tar && \
tar -xvf /tmp/jdk1.8.0_131.tar -C /usr/lib/jvm/ && \
rm /tmp/jdk1.8.0_131.tar && \
rm -rf /usr/lib/jvm/jdk1.8.0_131/*src.zip \
/usr/lib/jvm/jdk1.8.0_131/*src.jar \
/usr/lib/jvm/jdk1.8.0_131/*/THIRDPARTY_README.txt \
/usr/lib/jvm/jdk1.8.0_131/*/LICENSE
- 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.
- 35.
- 36.
使用到的文件脚本
[webadmin@test jdk]$ cat clear_disk_logs.sh
#!/bin/bash
find /data2/logs/ -name "*log" -mmin +180 -exec rm -f {} \;
#find /data2/logs/ -name "common.log2*" -exec rm -f {} \;
for item in `find /data2/logs/ -name "stdout.log"`
do
stdout_num=`du -sh $item|awk '{print +$1}'|awk -F "." '{print $1}'`
if [[ $stdout_num -gt 10 ]]
then
echo "`date +"%Y%m%d %H:%M:%S"` clear disk" >$item
fi
done
[webadmin@test jdk]$ cat liveProbe.sh
#!/bin/bash
pscounts=`ps -ef|grep java|grep "/data2/java" | grep -v 'grep'|awk '{print $2}' | wc -l`
if (( $pscounts == 0 )); then
echo "pscounts failed" >&2
exit 1
fi
[webadmin@test jdk]$ cat offline.sh
#!/bin/bash
(sleep 1;
echo "offline"
sleep 2;
#echo quit
)|telnet localhost 33302
- 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.
3、编包使用到的命令
docker build . -t harbor.xxx.com/nginx/production/nginx:v24.11.01.1200
- 1.
- 2.