Advertisement
kazoda

Dockerfile (CentOS, Zabbix20)

Oct 14th, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. # Dockerfile CentOS + sshd + Zabbix(Apache, MySQL)
  2. FROM centos:centos6
  3. MAINTAINER kaz
  4.  
  5. ## yum plugin fastestmirror
  6. RUN echo "prefer=ftp.iij.ad.jp" >> /etc/yum/pluginconf.d/fastestmirror.conf
  7.  
  8. # Time Zone
  9. RUN echo 'ZONE="Asia/Tokyo"' > /etc/sysconfig/clock
  10. RUN rm -f /etc/localtime
  11. RUN ln -fs /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
  12.  
  13. # refer to https://www.mail-archive.com/centos@centos.org/msg105095.html
  14. RUN sed -i 's|mirrorlist=\(.*\)\&repo=updates$|#mirrorlist=\1\&repo=updates|g' /etc/yum.repos.d/CentOS-Base.repo
  15. RUN sed -i 's|#baseurl=.*updates/$basearch/$|baseurl=http://ftp.iij.ad.jp/pub/linux/centos/$releasever/updates/$basearch/|g' /etc/yum.repos.d/CentOS-Base.repo
  16.  
  17. RUN yum clean all
  18.  
  19. ## Install
  20. #RUN yum groupinstall -y 'Base'
  21.  
  22. RUN yum install -y sudo openssh-server yum-plugin-priorities.noarch yum-plugin-downloadonly
  23.  
  24. RUN rpm -ivh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
  25. RUN rpm -ivh http://repo.zabbix.com/zabbix/2.0/rhel/6/x86_64/zabbix-release-2.0-1.el6.noarch.rpm
  26.  
  27. RUN yum clean all
  28.  
  29. RUN yum install -y mysql-community-server
  30.  
  31. RUN yum install -y zabbix zabbix-server zabbix-server-mysql zabbix-web zabbix-web-mysql fping iksemel
  32. RUN yum remove -y zabbix zabbix-server zabbix-server-mysql zabbix-web zabbix-web-mysql
  33. RUN yum install --downloadonly --downloaddir=/tmp -y zabbix zabbix-server zabbix-server-mysql zabbix-web zabbix-web-mysql || echo "OK"
  34. RUN sed -ri 's/excludedocs 1/excludedocs 0/g' /etc/rpm/macros.imgcreate
  35. RUN rpm -ivh /tmp/zabbix*
  36.  
  37. ## create user
  38. RUN useradd kaz
  39. RUN passwd -u -f kaz
  40. RUN mkdir /home/kaz/.ssh; chown kaz. /home/kaz/.ssh; chmod 700 /home/kaz/.ssh
  41. ADD ./authorized_keys /home/kaz/.ssh/
  42. RUN chown kaz. /home/kaz/.ssh/authorized_keys
  43. RUN chmod 600 /home/kaz/.ssh/authorized_keys
  44.  
  45. ## sudo
  46. RUN echo "kaz ALL=(ALL) ALL" >> /etc/sudoers.d/kaz
  47.  
  48. ## sshd
  49. RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
  50. RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config
  51. RUN sed -ri 's/#GSSAPIAuthentication no/GSSAPIAuthentication no/' /etc/ssh/sshd_config
  52. RUN sed -ri 's/GSSAPIAuthentication yes/#GSSAPIAuthentication yes/' /etc/ssh/sshd_config
  53. RUN /etc/init.d/sshd start && sleep 5 && /etc/init.d/sshd stop
  54. #RUN /etc/init.d/sshd stop
  55.  
  56. ## mysql & zabbix server
  57. RUN /etc/init.d/mysqld start && sleep 5 && /etc/init.d/mysqld stop
  58. RUN echo -e "/etc/init.d/mysqld start\nsleep 5\n/usr/bin/mysql -uroot -e 'create database zabbix character set utf8 collate utf8_bin'" > /home/kaz/zabbix.sql
  59. RUN echo "/usr/bin/mysql -uroot -e 'grant all privileges on zabbix.* to \"zabbix\"@\"localhost\" identified by \"zabbix\"'" >> /home/kaz/zabbix.sql
  60. RUN echo "/usr/bin/mysql -uroot zabbix < /usr/share/doc/zabbix-server-mysql-2.0.13/create/schema.sql" >> /home/kaz/zabbix.sql
  61. RUN echo "/usr/bin/mysql -uroot zabbix < /usr/share/doc/zabbix-server-mysql-2.0.13/create/images.sql" >> /home/kaz/zabbix.sql
  62. RUN echo -e "/usr/bin/mysql -uroot zabbix < /usr/share/doc/zabbix-server-mysql-2.0.13/create/data.sql\nsleep 5\n/etc/init.d/mysqld stop" >> /home/kaz/zabbix.sql
  63. RUN chmod u+x /home/kaz/zabbix.sql
  64. RUN ["/bin/bash","-c","/home/kaz/zabbix.sql"]
  65. RUN rm -f /etc/zabbix/zabbix_server.conf
  66. ADD zabbix_server.conf /etc/zabbix/zabbix_server.conf
  67.  
  68. ##
  69. RUN touch /run.sh
  70. RUN echo -e "#!/bin/bash\n/sbin/service mysqld start\n/sbin/service zabbix-server start\n/sbin/service httpd start\n/sbin/service sshd start\n\nwhile true\ndo\n sleep 10\ndone\n" > /run.sh
  71. RUN chmod u+x /run.sh
  72.  
  73. EXPOSE 22 3306 10050 10051
  74. CMD ["/run.sh"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement