Docker 搭建一個 Sentry

不忘初心發表於2017-03-30

APT-GET更新

$ apt-get update

安裝DOCKER

$ curl -sSL https://get.daocloud.io/docker | sh

安裝DOCKER-COMPOSE

$ curl -L https://get.daocloud.io/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
配置 NETWORK 192.168.247.* br1
$ docker network create -d bridge --subnet 192.168.247.0/24 --gateway 192.168.247.1 -o parent=eth0 br1

安裝POSTGRES資料庫

$ docker run -d --name sentry-postgres -e POSTGRES_PASSWORD=secret -e POSTGRES_USER=sentry --net=br1 --ip=192.168.247.211 postgres

安裝REDIS

$ docker run -d --name sentry-redis --net=br1 --ip=192.168.247.212 redis

生成SENTRY KEY (下面都要用到生成的KEY)

$ docker run --rm sentry config generate-secret-key

安裝SENTRY

$ docker run -d --name my-sentry -e SENTRY_SECRET_KEY='生成的KEY' --net=br1 --ip=192.168.247.213  -e SENTRY_SERVER_EMAIL='xxxxx@163.com' -e SENTRY_EMAIL_HOST='smtp.163.com' -e SENTRY_EMAIL_PORT='25' -e SENTRY_EMAIL_USER='xxxxx@163.com' -e SENTRY_EMAIL_PASSWORD='xxxxxouthxxxxx' -e SENTRY_REDIS_HOST=192.168.247.212 -e SENTRY_REDIS_PORT=6379 -e SENTRY_POSTGRES_HOST=192.168.247.211 -e SENTRY_POSTGRES_PORT=5432 -e SENTRY_DB_USER='sentry' -e SENTRY_DB_PASSWORD='secret' --link sentry-postgres:postgres --link sentry-redis:redis sentry

啟動SENTRY-WORKER 這個worker 可以啟動多個 給不同的 name 和 ip 即可

$ docker run -d --name sentry-worker-1 -e SENTRY_SECRET_KEY='^生成的KEY' --net=br1 --ip=192.168.247.214  -e SENTRY_SERVER_EMAIL='xxxxx@163.com' -e SENTRY_EMAIL_HOST='smtp.163.com' -e SENTRY_EMAIL_PORT='25' -e SENTRY_EMAIL_USER='xxxxx@163.com' -e SENTRY_EMAIL_PASSWORD='xxxxxouthxxxxx' -e SENTRY_REDIS_HOST=192.168.247.212 -e SENTRY_REDIS_PORT=6379 -e SENTRY_POSTGRES_HOST=192.168.247.211 -e SENTRY_POSTGRES_PORT=5432 -e SENTRY_DB_USER='sentry' -e SENTRY_DB_PASSWORD='secret' --link sentry-postgres:postgres --link sentry-redis:redis sentry run worker

啟動SENTRY CRON 定時指令碼

$ docker run -d --name sentry-cron -e SENTRY_SECRET_KEY='生成的KEY' --net=br1 --ip=192.168.247.215  -e SENTRY_SERVER_EMAIL='xxxxx@163.com' -e SENTRY_EMAIL_HOST='smtp.163.com' -e SENTRY_EMAIL_PORT='25' -e SENTRY_EMAIL_USER='xxxxx@163.com' -e SENTRY_EMAIL_PASSWORD='xxxxxouthxxxxx' -e SENTRY_REDIS_HOST=192.168.247.212 -e SENTRY_REDIS_PORT=6379 -e SENTRY_POSTGRES_HOST=192.168.247.211 -e SENTRY_POSTGRES_PORT=5432 -e SENTRY_DB_USER='sentry' -e SENTRY_DB_PASSWORD='secret' --link sentry-postgres:postgres --link sentry-redis:redis sentry run cron

更新SENTRY 後期升級可直接升級SENTRY

$ docker run -it --rm -e SENTRY_SECRET_KEY='^生成的KEY' --net=br1 --ip=192.168.247.216  -e SENTRY_SERVER_EMAIL='xxxxx@163.com' -e SENTRY_EMAIL_HOST='smtp.163.com' -e SENTRY_EMAIL_PORT='25' -e SENTRY_EMAIL_USER='xxxxx@163.com' -e SENTRY_EMAIL_PASSWORD='xxxxxouthxxxxx' -e SENTRY_REDIS_HOST=192.168.247.212 -e SENTRY_REDIS_PORT=6379 -e SENTRY_POSTGRES_HOST=192.168.247.211 -e SENTRY_POSTGRES_PORT=5432 -e SENTRY_DB_USER='sentry' -e SENTRY_DB_PASSWORD='secret' --link sentry-postgres:postgres --link sentry-redis:redis sentry upgrade

安裝一個NGINX

$ mkdir -p ~/dockerfile/docker-shared/nginx/config

$ mkdir -p  ~/dockerfile/docker-shared/nginx/logs

$ docker run -d -p 80:80 -p 443:443 --name webserver -v ~/dockerfile/docker-shared/nginx/config:/etc/nginx/conf.d -v ~/dockerfile/docker-shared/nginx/logs:/var/log/nginx --net=br1 --ip=192.168.247.184 nginx

配置NGINX

$ cd ~/dockerfile/docker-shared/nginx/config

$ mkdir certs config ssl

$ vim sentry.xxx.com.conf
------------------------------------------------------------------------
server {
    listen        443 ssl;
    #include /etc/nginx/conf.d/ssl/sentry.xxx.com.ssl;
    server_name  sentry.xxx.com;
    access_log /var/log/nginx/sentry_access.log main;
    error_log /var/log/nginx/sentry_error.log;

    location / {
         proxy_set_header  X-Real-IP  $remote_addr;
         proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header  Host $host;
         #proxy_redirect off;

         proxy_connect_timeout 180;
         proxy_read_timeout 180;
         proxy_send_timeout 180;
         proxy_pass   http://192.168.247.213:9000/;
   }
}

server {
        listen 80;
        server_name sentry.xxx.com;
        rewrite ^/(.*) https://sentry.xxx.com/$1 permanent;
}

連線DOCKER NGINX

$ docker exec -it webserver /bin/bash

$ nginx -t

$ service nginx reload

SENTRY 清理記錄資料日誌

$ docker exec -it  my-sentry /bin/bash

$ sentry cleanup --days 30

注: sentry cleanup --days 30 對postgresql進行遠端cleanup 刪除當前日期間30日前的資料
但是資料不會真正的被清理 我們需要 使用者 VACUUM 將這些標記為 DEAD 行記錄所佔用的空間徹底釋放
如果不釋放 這些資料還會佔用你的空間

VACUUM

$ docker exec -it sentry-postgres  /bin/bash

$ vacuumdb -U sentry -d postgres -v -f --analyze
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章