我已在docker上安装了crontabs,并在/etc/cron.allow中逐行在cron.allow文件中添加了两个用户root,elasticsearch。
这使我可以为两个用户root(elasticsearch)插入cronjobs。
对于root用户,crond start正在启动,但是对于用户elasticsearch crond没有入门并出现错误: crond:无法打开或创建/var/run/crond.pid:权限被拒绝
这是我的docker文件:
FROM docker.elastic.co/elasticsearch/elasticsearch:6.6.0
ENV PATH=$PATH:/usr/share/elasticsearch/bin
RUN yum -y update
RUN yum -y install crontabs
RUN echo "root" > /etc/cron.allow
RUN echo "elasticsearch" >> /etc/cron.allow
RUN echo "" >> /etc/cron.allow
RUN chmod -R 755 /etc/cron.allow
RUN cd /etc/ && cat cron.allow && cat cron.deny
RUN chown -R elasticsearch /etc/cron.d
RUN chmod -R 755 /etc/cron.d
RUN chown -R elasticsearch /var/spool/cron
RUN chmod -R 755 /var/spool/cron
RUN chown -R elasticsearch /etc/crontab
RUN chmod -R 755 /etc/crontab
RUN chown -R elasticsearch /etc/cron.d
RUN chmod -R 755 /etc/cron.d
COPY ./purge.sh /usr/share/elasticsearch
RUN ls -l /etc/crontab
RUN ls -l /etc/cron.d
RUN touch /usr/share/elasticsearch/cron.log
ADD ./cron /etc/cron.d/cron_test
RUN chmod 0755 /etc/cron.d/cron_test
RUN cd /etc/cron.d && cat cron_test
RUN chown -R elasticsearch /etc/cron.d/cron_test
RUN ls -l /etc/cron.d/cron_test
USER elasticsearch
RUN crontab /etc/cron.d/cron_test
RUN crontab -l
RUN chmod 600 /var/spool/cron/elasticsearch
ENTRYPOINT crond start && pgrep cron && tail -f && tail -f /usr/share/elasticsearch/cron.log/usr/share/elasticsearch/cron.log
CMD elasticsearch
RUN cd /var/run && ls
EXPOSE 9200 9300
构建成功,但在运行时: $ docker run -p 9200:9200 -p 9300:9300 -e“ discovery.type =单节点” crontabtest crond:无法打开或创建/var/run/crond.pid:权限被拒绝
如何允许Elasticsearch用户启动crond服务?