标签:
一、获取graphite-centos docker image
sudo docker pull steeef/graphite-centos
(参见:https://registry.hub.docker.com/u/steeef/graphite-centos/)
二、运行一个graphite容器
docker run -d --name graphite -v /data/uxin/graphite:/var/lib/graphite/storage/whisper -p 8880:80 -p 2003:2003 -p 2004:2004 -p 7002:7002 steeef/graphite-centos
三、在容器中执行bash
1.进入graphite容器:
sudo docker exec -t -i graphite /bin/bash
2.修改graphite配置:
1)修改graphite显示时间:
TIME_ZONE = ‘Asia/Shanghai‘
2)修改系统时区
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
3.为nginx的登录增加用户名和密码(见另一篇博文)
4.重新启动服务
将/etc/supervisor.conf中关于nginx的启动去掉,改为在/tmp/start.sh中启动nginx,并且nginx.conf配置ngingx的启动方式为daemon启动,需要将daemon off注释掉。
这样做的原因是使用supervisor来启动nginx会将CPU占用率位置在90%以上。
执行启动所有服务/tmp/start.sh
四、使用docker停止、重新启动容器
sudo docker stop graphite sudo docker restart graphite sudo docker top graphite
附录1:Dockerfile
FROM centos:latest MAINTAINER Stephen Price <steeef@gmail.com> RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm # Install required packages RUN yum -y install gcc python-devel pycairo pyOpenSSL python-memcached bitmap bitmap-fonts python-pip python-django-tagging python-sqlite2 python-rrdtool memcached python-simplejson python-gunicorn supervisor openssh-server sudo nginx # Use pip to install graphite, carbon, and deps RUN pip-python install whisper RUN pip-python install Twisted==11.1.0 RUN pip-python install --install-option="--prefix=/var/lib/graphite" --install-option="--install-lib=/var/lib/graphite/lib" carbon RUN pip-python install --install-option="--prefix=/var/lib/graphite" --install-option="--install-lib=/var/lib/graphite/webapp" graphite-web RUN mkdir -p /var/run/sshd RUN chmod -rx /var/run/sshd RUN useradd -d /home/graphite -m -s /bin/bash graphite RUN echo graphite:graphite | chpasswd RUN echo ‘graphite ALL=(ALL) NOPASSWD:ALL‘ >> /etc/sudoers.d/graphite RUN chmod 0440 /etc/sudoers.d/graphite # Add system service config ADD nginx.conf /etc/nginx/nginx.conf ADD supervisord.conf /etc/supervisord.conf # ## Add graphite config ADD initial_data.json /var/lib/graphite/webapp/graphite/initial_data.json ADD local_settings.py /var/lib/graphite/webapp/graphite/local_settings.py ADD carbon.conf /var/lib/graphite/conf/carbon.conf ADD storage-schemas.conf /var/lib/graphite/conf/storage-schemas.conf RUN mkdir -p /var/lib/graphite/storage/whisper RUN touch /var/lib/graphite/storage/graphite.db /var/lib/graphite/storage/index RUN chown -R nginx /var/lib/graphite/storage RUN chmod 0775 /var/lib/graphite/storage /var/lib/graphite/storage/whisper RUN chmod 0664 /var/lib/graphite/storage/graphite.db RUN cd /var/lib/graphite/webapp/graphite && python manage.py syncdb --noinput # Nginx EXPOSE 80 # Carbon line receiver port EXPOSE 2003 # Carbon pickle receiver port EXPOSE 2004 # Carbon cache query port EXPOSE 7002 # ssh EXPOSE 22 ADD start.sh /tmp/start.sh RUN chmod +x /tmp/start.sh ENTRYPOINT /tmp/start.sh
附录2:容器运行后,第一个执行的命令 /tmp/start.sh(nginx.conf配置ngingx的启动方式为daemon启动,需要将daemon off注释掉)
#!/bin/bash if [ -n "${SECRET_KEY}" ]; then sed -E -i "s/^environment = (.*)$/environment = \1,SECRET_KEY=‘$SECRET_KEY‘/" /etc/supervisord.conf fi #ssh-keygen -q -t rsa -f /etc/ssh/ssh_host_rsa_key -C ‘‘ -N ‘‘ #ssh-keygen -q -t dsa -f /etc/ssh/ssh_host_dsa_key -C ‘‘ -N ‘‘ #ssh-keygen -q -t rsa1 -f /etc/ssh/ssh_host_key -C ‘‘ -N ‘‘ /usr/bin/supervisord
/usr/sbin/nginx /usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no
附录3:supervisor.conf
bash-4.1# vi /etc/supervisord.conf [supervisord] environment = GRAPHITE_STORAGE_DIR=/var/lib/graphite/storage,GRAPHITE_CONF_DIR=/var/lib/graphite/conf logfile = /var/log/supervisor/supervisord.log #[program:nginx] #command = /usr/sbin/nginx #autorestart = true #log_stdout = true #log_stderr = true #logfile_maxbytes=5MB #logfile_backups=10 #logfile = /var/log/supervisor/nginx.log [program:carbon-cache] user = nginx command = /var/lib/graphite/bin/carbon-cache.py start logfile = /var/log/supervisor/carbon-cache.log autorestart = true log_stdout = true log_stderr = true logfile_maxbytes=5MB logfile_backups=10 [program:graphite-webapp] user = nginx directory = /var/lib/graphite/webapp command = /usr/bin/gunicorn_django -b127.0.0.1:8000 --pythonpath=/var/lib/graphite/webapp/graphite --preload -w2 --settings=settings logfile = /var/log/supervisor/graphite.log autorestart = true autostart = true log_stdout = true log_stderr = true logfile_maxbytes=5MB logfile_backups=10
标签:
原文地址:http://www.cnblogs.com/Totoro-gong/p/4286691.html