From aa3b8728b9daec9f8bbd3306f455a1ffc76ff64b Mon Sep 17 00:00:00 2001 From: kev Date: Tue, 24 Mar 2020 16:26:40 +0800 Subject: [PATCH] update graphite --- graphite/Dockerfile | 39 +++++++++++++++++++++---------------- graphite/README.md | 19 ++++++++++++------ graphite/docker-compose.yml | 5 +++-- graphite/nginx.conf | 23 ++++++++++++++++++++++ graphite/supervisord.conf | 12 ++++++++++-- 5 files changed, 71 insertions(+), 27 deletions(-) create mode 100644 graphite/nginx.conf diff --git a/graphite/Dockerfile b/graphite/Dockerfile index 79ae44b..1c7f386 100644 --- a/graphite/Dockerfile +++ b/graphite/Dockerfile @@ -8,7 +8,8 @@ MAINTAINER EasyPi Software Foundation ENV GRAPHITE_VERSION=1.1.7 ENV GRAPHITE_CONF_DIR=/opt/graphite/conf ENV GRAPHITE_STORAGE_DIR=/opt/graphite/storage -ENV PATH=$PATH:/opt/graphite/bin +ENV DJANGO_SETTINGS_MODULE=graphite.settings +ENV PATH=/opt/graphite/bin:$PATH ENV PYTHONPATH=/opt/graphite/lib:/opt/graphite/webapp WORKDIR /opt/graphite @@ -18,32 +19,36 @@ RUN set -xe \ && apk add build-base \ cairo \ curl \ - git \ libffi-dev \ - python \ - python-dev \ - && curl -sSL https://bootstrap.pypa.io/get-pip.py | python \ - && pip install gunicorn scandir supervisor whisper==$GRAPHITE_VERSION \ - && pip install -r https://github.com/graphite-project/graphite-web/raw/$GRAPHITE_VERSION/requirements.txt \ - && pip install carbon==$GRAPHITE_VERSION --install-option="--install-lib=/opt/graphite/lib" \ - && pip install graphite-web==$GRAPHITE_VERSION --install-option="--prefix=/opt/graphite" --install-option="--install-lib=/opt/graphite/webapp" \ - && cd conf \ + nginx \ + python3 \ + python3-dev \ + && curl -sSL https://bootstrap.pypa.io/get-pip.py | python3 \ + && pip3 install gunicorn supervisor \ + && pip3 install --install-option=--prefix=/opt/graphite \ + --install-option=--install-lib=/opt/graphite/lib \ + whisper==$GRAPHITE_VERSION \ + carbon==$GRAPHITE_VERSION \ + && pip3 install --install-option=--prefix=/opt/graphite \ + --install-option=--install-lib=/opt/graphite/webapp \ + graphite-web==$GRAPHITE_VERSION \ + && cd ./webapp \ + && echo "SECRET_KEY = '$(head -c 16 /dev/urandom | base64)'" >> graphite/local_settings.py \ + && cd ../conf \ && cp carbon.conf.example carbon.conf \ && cp storage-schemas.conf.example storage-schemas.conf \ - && cd ../webapp \ - && echo "SECRET_KEY = '$(head -c 16 /dev/urandom | base64)'" > graphite/local_settings.py \ - && curl -sSL https://github.com/graphite-project/graphite-web/raw/master/webapp/manage.py > manage.py \ - && chmod +x manage.py \ - && ./manage.py collectstatic --noinput --settings=graphite.settings \ - && ./manage.py migrate --noinput --run-syncdb \ + && cp aggregation-rules.conf.example aggregation-rules.conf \ + && cd .. \ + && django-admin collectstatic --noinput \ + && django-admin migrate --noinput --run-syncdb \ && apk del build-base \ curl \ - git \ libffi-dev \ python-dev \ && rm -rf /root/.cache/pip \ /var/cache/apk/* +COPY nginx.conf /etc/nginx/conf.d/default.conf COPY supervisord.conf /etc/supervisor/ VOLUME $GRAPHITE_CONF_DIR \ diff --git a/graphite/README.md b/graphite/README.md index 2cd8191..d48ff4b 100644 --- a/graphite/README.md +++ b/graphite/README.md @@ -24,26 +24,32 @@ graphite: volumes: - ./data/conf:/opt/graphite/conf - ./data/storage:/opt/graphite/storage - restart: always + - ./data/storage/log/webapp:/opt/graphite/storage/log/webapp + restart: unless-stopped ``` ## Up and Running ```bash $ cd ~/fig/graphite -$ mkdir -p data/storage/log/webapp + +$ docker-compose run --rm graphite sh +>>> django-admin migrate --noinput --run-syncdb +>>> django-admin createsuperuser +>>> django-admin changepassword +>>> exit + $ docker-compose up -d + $ docker-compose exec graphite sh >>> vi conf/storage-schemas.conf ->>> python webapp/manage.py migrate --noinput --run-syncdb ->>> python webapp/manage.py createsuperuser ->>> python webapp/manage.py changepassword ->>> supervisorctl restart +>>> supervisorctl restart all >>> supervisorctl status carbon-aggregator RUNNING pid 9, uptime 0:00:13 carbon-cache RUNNING pid 8, uptime 0:00:22 graphite-webapp RUNNING pid 7, uptime 0:00:24 >>> exit + $ tree -F -L 4 ├── data/ │   ├── conf/ @@ -59,6 +65,7 @@ $ tree -F -L 4 │   └── whisper/ │   └── carbon/ └── docker-compose.yml + $ curl http://localhost:8080 ``` diff --git a/graphite/docker-compose.yml b/graphite/docker-compose.yml index cd1bb10..3eabb0d 100644 --- a/graphite/docker-compose.yml +++ b/graphite/docker-compose.yml @@ -7,9 +7,10 @@ graphite: - "2023:2023" - "2024:2024" - "7002:7002" - - "8080:8080" + - "48080:8080" - "9001:9001" volumes: - ./data/conf:/opt/graphite/conf - ./data/storage:/opt/graphite/storage - restart: always + - ./data/storage/log/webapp:/opt/graphite/storage/log/webapp + restart: unless-stopped diff --git a/graphite/nginx.conf b/graphite/nginx.conf new file mode 100644 index 0000000..6a3ee71 --- /dev/null +++ b/graphite/nginx.conf @@ -0,0 +1,23 @@ +server { + listen 8080 default_server; + + location = /favicon.ico { + return 204; + } + + location /static { + alias /opt/graphite/static; + expires max; + } + + location / { + proxy_pass_header Server; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Scheme $scheme; + proxy_connect_timeout 10; + proxy_read_timeout 10; + proxy_pass http://127.0.0.1:8000; + } +} diff --git a/graphite/supervisord.conf b/graphite/supervisord.conf index df18535..e17a822 100644 --- a/graphite/supervisord.conf +++ b/graphite/supervisord.conf @@ -14,14 +14,22 @@ serverurl = http://127.0.0.1:9001 command = carbon-cache.py --debug start redirect_stderr = true autorestart = true +priority = 1 [program:carbon-aggregator] command = carbon-aggregator.py --debug start redirect_stderr = true autorestart = true +priority = 2 [program:graphite-webapp] -command = gunicorn -b :8080 graphite.wsgi:application -directory = /opt/graphite/webapp +command = gunicorn -b 127.0.0.1:8000 graphite.wsgi:application redirect_stderr = true autorestart = true +priority = 3 + +[program:nginx] +command = nginx -g "daemon off; pid /run/nginx.pid;" +redirect_stderr = true +autorestart = true +priority = 4