1、簡介html
sentry是一個強大的分佈式報錯信息收集平臺,圖形化程度很高,能夠幫助咱們直觀的發現當前部署的系統存在哪些問題。node
2、安裝方式介紹python
官網連接:https://docs.sentry.io/linux
官方提供了兩種安裝方式:Docker 和 pythonnginx
注:我這裏選擇使用Docker 的方式來進行安裝配置sentry,緣由是官網說了python這種方式已經被Docker安裝方式代替了,原話以下:
git
This method of installation is deprecated in favor of Docker github
並且使用python安裝sentry必須是python 2.7 以及以上版本,考慮到升級python 會影響系統其它應用,故此選擇Docker的安裝方式。web
3、安裝配置過程redis
一、準備工做docker
在服務器安裝好Centos 7.x 系統,我這裏安裝的是Centos 7.0 ,並且python在Centos 7.0上的版本就是2.7.5
二、安裝docker
官方Docker 安裝方式幫助文檔:
https://docs.sentry.io/server/installation/docker/
安裝docker #yum install docker -y 查看版本信息 #docker info #版本是1.12.6 Containers: 8 Running: 8 Paused: 0 Stopped: 0 Images: 9 Server Version: 1.12.6 Storage Driver: devicemapper Pool Name: docker-8:2-263372-pool Pool Blocksize: 65.54 kB Base Device Size: 10.74 GB Backing Filesystem: xfs Data file: /dev/loop0 Metadata file: /dev/loop1 Data Space Used: 1.391 GB Data Space Total: 107.4 GB Data Space Available: 45.57 GB Metadata Space Used: 3.994 MB Metadata Space Total: 2.147 GB Metadata Space Available: 2.143 GB Thin Pool Minimum Free Space: 10.74 GB Udev Sync Supported: true Deferred Removal Enabled: true Deferred Deletion Enabled: true Deferred Deleted Device Count: 0 Data loop file: /var/lib/docker/devicemapper/devicemapper/data WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device. Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata Library Version: 1.02.140-RHEL7 (2017-05-03) Logging Driver: journald Cgroup Driver: systemd Plugins: Volume: local Network: null host overlay bridge Swarm: inactive Runtimes: docker-runc runc Default Runtime: docker-runc Security Options: seccomp Kernel Version: 3.10.0-693.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 Number of Docker Hooks: 3 CPUs: 2 Total Memory: 1.781 GiB Name: localhost.localdomain ID: 2C6S:WONB:UT5C:3RU7:UQKC:7CIU:HOQ6:XFXI:JE2M:LIMX:5B4S:FGLE Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Insecure Registries: 127.0.0.0/8 Registries: docker.io (secure) 安裝epel源 #yum install epel-release -y 安裝pip #yum install python-pip -y 查看版本: #pip -V pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)
三、安裝docker-compose
Docker Compose 是在使用Docker容器部署分佈式應用時的工具,能夠定義哪一個容器運行哪一個應用,使用Compose 你只需定義一個多容器應用的yml文件,而後使用一條命令便可部署運行全部容器。
參考連接:http://dockone.io/article/834
中文指南網:http://www.widuu.com/docker/compose/install.html
使用pip來安裝docker compose #pip install docker-compose #pip list #能夠看到docker-compose 已經安裝好了 backports.ssl-match-hostname (3.5.0.1) cached-property (1.3.1) certifi (2017.11.5) chardet (3.0.4) configobj (4.7.2) decorator (3.4.0) docker (2.6.1) docker-compose (1.18.0) #已安裝 ……………… #docker-compose --version #查看版本 docker-compose version 1.18.0, build 8dd22a9
四、配置安裝屬於本身的sentry
#mkdir /opt/case -pv #cd /opt/case/ #git clone https://github.com/getsentry/onpremise.git #cd onpremise 根據onpremise目錄中的README.md 內容來操做: #cat README.md ……………… 1. `mkdir -p data/{sentry,postgres}` - Make our local database and sentry config directories. This directory is bind-mounted with postgres so you don't lose state! 2. `docker-compose run --rm web config generate-secret-key` - Generate a secret key. Add it to `docker-compose.yml` in `base` as `SENTRY_SECRET_KEY`. 3. `docker-compose run --rm web upgrade` - Build the database. Use the interactive prompts to create a user account. 4. `docker-compose up -d` - Lift all services (detached/background mode). 5. Access your instance at `localhost:9000`! ……………… #mkdir data/{sentry,postgres} -p 啓動docker #systemctl start docker 加入開機自啓動 #systemctl enable docker 正常啓動以後,會有docker0網卡生成 #ifconfig docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0 ether 02:42:2a:d3:14:d4 txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 在docker-compose.yml中的base位置添加 SENTRY_SECRET_KEY,使用以下命令生成 #docker-compose run --rm web config generate-secret-key #須要很長時間,須要到外網拉取數據,若是中間斷掉了,繼續執行便可。 Creating network "onpremise_default" with the default driver Pulling postgres (postgres:9.5)... Trying to pull repository docker.io/library/postgres ... 9.5: Pulling from docker.io/library/postgres f49cf87b52c1: Downloading [=======> ] 8.109 MB/52.6 MB 67d44cf86769: Download complete f16a15c53831: Download complete f49cf87b52c1: Downloading [============> ] 12.98 MB/52.6 MB c9a1ed29c8a8: Download complete 8862935f78c7: Download complete f49cf87b52c1: Downloading [=====================> ] 22.17 MB/52.6 MB 8c59731cd856: Download complete 12acb5363ee2: Download complete f49cf87b52c1: Downloading [======================> ] 23.25 MB/52.6 MB 8397eb589621: Download complete d3041f255f7a: Download complete 注:若是第一次沒有生成SENTRY_SECRET_KEY,多執行幾回直到生成爲止,我就執行了4次,以下: #docker-compose run --rm web config generate-secret-key Starting onpremise_memcached_1 ... Starting onpremise_redis_1 ... Starting onpremise_memcached_1 ... done Starting onpremise_smtp_1 ... done _&vh6fx-80!q20g+jhvj5m6(!(-jy^x7t46_-7vtz2(=)+=#%v 將上面命令執行結束後生成的最後一行字符串,添加到docker-compose.yml 中,以下: #cat docker-compose.yml ………………………… version: '2' services: base: restart: unless-stopped build: . environment: # Run `docker-compose run web config generate-secret-key` # to get the SENTRY_SECRET_KEY value. # SENTRY_SECRET_KEY: '' SENTRY_SECRET_KEY: '_&vh6fx-80!q20g+jhvj5m6(!(-jy^x7t46_-7vtz2(=)+=#%v' #添加此行 SENTRY_MEMCACHED_HOST: memcached SENTRY_REDIS_HOST: redis SENTRY_POSTGRES_HOST: postgres SENTRY_EMAIL_HOST: smtp volumes: - ./data/sentry:/var/lib/sentry/files …………………… 查看鏡像 #docker images REPOSITORY TAG IMAGE ID CREATED SIZE onpremise_web latest 4178dbde130d 16 minutes ago 535.6 MB docker.io/tianon/exim4 latest f0e5295455c1 7 days ago 173.2 MB docker.io/sentry 8.22-onbuild 6f77c810f869 7 days ago 535.5 MB docker.io/postgres 9.5 cea87be7b432 7 days ago 263.9 MB docker.io/redis 3.2-alpine f60c2c2ed490 2 weeks ago 19.81 MB docker.io/memcached 1.4 bdb0ceca47d8 5 months ago 58.6 MB 繼續執行 Use the interactive prompts to create a user account #docker-compose run --rm web upgrade #Build the database. ……………… Would you like to create a user account now? [Y/n]: y #輸入y 表示建立用戶帳號 Email: xxxx@xx.com #輸入一個郵箱地址 Password: #輸入密碼 Repeat for confirmation: #確認密碼 Should this user be a superuser? [y/N]: y #詢問是不是超級用戶,輸入y User created: xxxx@xx.com Added to organization: sentry - Loading initial data for sentry. Installed 0 object(s) from 0 fixture(s) Running migrations for nodestore: - Migrating forwards to 0001_initial. > nodestore:0001_initial - Loading initial data for nodestore. Installed 0 object(s) from 0 fixture(s) Running migrations for search: - Migrating forwards to 0002_auto__del_searchtoken__del_unique_searchtoken_document_field_token__de. > search:0001_initial > search:0002_auto__del_searchtoken__del_unique_searchtoken_document_field_token__de - Loading initial data for search. Installed 0 object(s) from 0 fixture(s) Running migrations for social_auth: - Migrating forwards to 0004_auto__del_unique_usersocialauth_provider_uid__add_unique_usersocialaut. > social_auth:0001_initial > social_auth:0002_auto__add_unique_nonce_timestamp_salt_server_url__add_unique_associati > social_auth:0003_auto__del_nonce__del_unique_nonce_server_url_timestamp_salt__del_assoc > social_auth:0004_auto__del_unique_usersocialauth_provider_uid__add_unique_usersocialaut …………………… 注:在執行下面一步的時候,須要關閉selinux而且配置docker-compose.yml,不然若是後面再關閉selinux,就會遇到啓動報錯,後面會介紹! #cat /etc/selinux/config SELINUX=disabled #改爲disabled 在docker-compose.yml 中添加選項:privileged: true 以下樣式: #cat docker-compose.yml ……………… version: '2' services: base: privileged: true #添加到這個位置 restart: unless-stopped build: . environment: # Run `docker-compose run web config generate-secret-key` # to get the SENTRY_SECRET_KEY value. # SENTRY_SECRET_KEY: '' SENTRY_SECRET_KEY: '_&vh6fx-80!q20g+jhvj5m6(!(-jy^x7t46_-7vtz2(=)+=#%v' SENTRY_MEMCACHED_HOST: memcached SENTRY_REDIS_HOST: redis SENTRY_POSTGRES_HOST: postgres SENTRY_EMAIL_HOST: smtp volumes: - ./data/sentry:/var/lib/sentry/files smtp: privileged: true #添加到這個位置 restart: unless-stopped image: tianon/exim4 memcached: privileged: true #添加到這位置,下面的服務也是添加到一樣的位置,不在列出 restart: unless-stopped image: memcached:1.4 ……………… 而後重啓系統 #reboot #docker-compose up -d #拉起全部的服務 Lift all services (detached/background mode). creating onpremise_smtp_1 ... creating onpremise_postgres_1 ... creating onpremise_memcached_1 ... creating onpremise_redis_1 ... creating onpremise_postgres_1 ... done creating onpremise_web_1 ... creating onpremise_cron_1 ... creating onpremise_worker_1 ... done 再次執行#docker images 就會多出來幾個: #docker images REPOSITORY TAG IMAGE ID CREATED SIZE onpremise_base latest 4178dbde130d About an hour ago 535.6 MB onpremise_cron latest 4178dbde130d About an hour ago 535.6 MB onpremise_web latest 4178dbde130d About an hour ago 535.6 MB onpremise_worker latest 4178dbde130d About an hour ago 535.6 MB docker.io/tianon/exim4 latest f0e5295455c1 7 days ago 173.2 MB docker.io/sentry 8.22-onbuild 6f77c810f869 7 days ago 535.5 MB docker.io/postgres 9.5 cea87be7b432 8 days ago 263.9 MB docker.io/redis 3.2-alpine f60c2c2ed490 2 weeks ago 19.81 MB docker.io/memcached 1.4 bdb0ceca47d8 5 months ago 58.6 MB #docker-compose images Container Repository Tag Image Id Size ------------------------------------------------------------------------------------ onpremise_base_1 onpremise_base latest 4178dbde130d 511 MB onpremise_cron_1 onpremise_base latest 4178dbde130d 511 MB onpremise_memcached_1 docker.io/memcached 1.4 bdb0ceca47d8 55.9 MB onpremise_postgres_1 docker.io/postgres 9.5 cea87be7b432 252 MB onpremise_redis_1 docker.io/redis 3.2-alpine f60c2c2ed490 18.9 MB onpremise_smtp_1 docker.io/tianon/exim4 latest f0e5295455c1 165 MB onpremise_web_1 onpremise_base latest 4178dbde130d 511 MB onpremise_worker_1 onpremise_base latest 4178dbde130d 511 MB 使用docker-compose 管理服務 #cd /opt/case/onpremise #docker-compose start #將上面的服務所有啓動 Starting postgres ... done Starting redis ... done Starting smtp ... done Starting base ... done Starting memcached ... done Starting worker ... done Starting cron ... done Starting web ... done #docker-compose ps #查看是否啓動ok,能夠看到都是Up狀態 Name Command State Ports --------------------------------------------------------------------------------------- onpremise_base_1 /entrypoint.sh run web Up 9000/tcp onpremise_cron_1 /entrypoint.sh run cron Up 9000/tcp onpremise_memcached_1 docker-entrypoint.sh memcached Up 11211/tcp onpremise_postgres_1 docker-entrypoint.sh postgres Up 5432/tcp onpremise_redis_1 docker-entrypoint.sh redis ... Up 6379/tcp onpremise_smtp_1 entrypoint.sh tini -- exim ... Up 25/tcp onpremise_web_1 /entrypoint.sh run web Up 0.0.0.0:9000->9000/tcp onpremise_worker_1 /entrypoint.sh run worker Up 9000/tcp Access your instance at `localhost:9000`! 即配置訪問實例的ip和端口 #vi docker-compose.yml #在web 配置項添加以下: web: privileged: true restart: unless-stopped extends: base links: - redis - postgres - memcached - smtp ports: - '172.16.60.167:9000:9000' #添加sentry所在服務器的ip地址 而後就能夠在瀏覽器訪問了http://172.16.60.167:900 輸入上面設置的用戶名和密碼,就能夠進入,以下圖
第一次登錄須要進行一些簡單的設置,點擊「登錄」以後,出現以下界面,進行一些設置
設置好以後,直接點擊右下角的「continue」 就會進入到主機面,以下:
至此sentry的安裝配置告一段落,具體建立項目或者其餘操做須要根據開發須要進行配置。
4、遇到的問題
一、執行docker-compose start 報錯 問題描述: 按照/opt/case/onpremise/README.md 中的1-5 操做以後,準備將selinux關閉,因而就在配置文件/etc/selinux/config中將參數改了---> SELINUX=disabled 重啓 系統以後,再次執行#docker-compose start 報錯 以下: Starting postgres ... error Starting redis ... error Starting smtp ... error Starting base ... error Starting memcached ... error Starting worker ... error Starting cron ... error Starting web ... error ERROR: for memcached Cannot start service memcached: devmapper: Error mounting '/dev/mapper/docker-8:2-263372-b60cf0da925b9971fb7103e576b9e0f088451e8203ebb07ebadff4adaee2fb4e' on '/var/lib/docker/devicemapper/mnt/b60cf0da925b9971fb7103e576b9e0f088451e8203ebb07ebadff4adaee2fb4e': invalid argument ERROR: for redis Cannot start service redis: devmapper: Error mounting '/dev/mapper/docker-8:2-263372-eb1a216ef329502e65c8b9157e6cbff34bfcdc31f5fdc24e7450438498ea0e66' on '/var/lib/docker/devicemapper/mnt/eb1a216ef329502e65c8b9157e6cbff34bfcdc31f5fdc24e7450438498ea0e66': invalid argument ERROR: for smtp Cannot start service smtp: devmapper: Error mounting '/dev/mapper/docker-8:2-263372-501013d66a63bfb0e331ee1e3d7924ceddfc5117a0eb13673cdc03c6ba629da0' on '/var/lib/docker/devicemapper/mnt/501013d66a63bfb0e331ee1e3d7924ceddfc5117a0eb13673cdc03c6ba629da0': invalid argument ERROR: for postgres Cannot start service postgres: devmapper: Error mounting '/dev/mapper/docker-8:2-263372-ae89295b83428fe62bc53536f02be7a65a3648b3f4ed8335023cfb30156f79a7' on '/var/lib/docker/devicemapper/mnt/ae89295b83428fe62bc53536f02be7a65a3648b3f4ed8335023cfb30156f79a7': invalid argument ERROR: for base Cannot start service base: devmapper: Error mounting '/dev/mapper/docker-8:2-263372-e46af50ff165debb34ede80daf1c2853ec0f3ee39c0aeb6121c786a56942ca1c' on '/var/lib/docker/devicemapper/mnt/e46af50ff165debb34ede80daf1c2853ec0f3ee39c0aeb6121c786a56942ca1c': invalid argument ERROR: No containers to start 網上找了一些方法,可是不能解決問題,其中一個就是執行umount命令,以下 #umount /var/lib/docker/devicemapper/mnt/xxxx 後來在高人的指點下,說是selinux的問題。由於我是在配置SELINUX=disabled 以前執行的#docker-compose up -d 解決方法: 一、將selinux配置文件中的配置還原:SELINUX=enforcing 而後reboot系統,執行#docker-compose start 就能夠正常啓動了。 二、在/opt/case/onpremise/docker-compose.yml 中添加一個配置項:privileged: true 以下: smtp: privileged: true ##在每個服務下面都要添加這個選項,一共8個 restart: unless-stopped image: tianon/exim4 重啓系統 #reboot 三、再將selinux 配置文件中改成disabled SELINUX=disabled 四、執行docker-compose up #docker-compose up -d #會從新建立服務 Recreating onpremise_smtp_1 ... Recreating onpremise_postgres_1 ... Recreating onpremise_memcached_1 ... Recreating onpremise_redis_1 ... Recreating onpremise_postgres_1 ... done Recreating onpremise_web_1 ... Recreating onpremise_cron_1 ... Recreating onpremise_worker_1 ... done 五、啓動 #docker-compose start Starting postgres ... done Starting redis ... done Starting smtp ... done Starting base ... done Starting memcached ... done Starting worker ... done Starting cron ... done Starting web ... done 注:後面再reboot以後,就不會出現執行docker-compose start 報錯的問題了。
5、使用代理
說明:若是是在生產環境部署sentry,就不但願本身以外的其餘人訪問,這個時候能夠經過nginx設置認證登陸或者代理的方式訪問
這裏介紹使用代理的方式: #cat /opt/app/nginx/conf/conf.d/vhost.conf upstream www { server 172.168.100.26:9000; #服務器內網ip地址 } #----------------------------------------------------------------------------- server { listen 80; server_name sentry.test.com; access_log /opt/logs/nginx/sentry.test.com.access.log main; error_log /opt/logs/nginx/sentry.test.com.error.log warn; location / { proxy_pass http://www; } } server { listen 443; server_name sentry.test.com; access_log /opt/logs/nginx_ssl/sentry.test.com.access.log ssl; error_log /opt/logs/nginx_ssl/sentry.test.com.error.log warn; ssl on; ssl_certificate /opt/app/nginx/conf/ssl/test.com.pem; ssl_certificate_key /opt/app/nginx/conf/ssl/test.com.key; location / { proxy_pass http://www; } } 而後啓動nginx服務 #/opt/app/nginx/sbin/nginx #netstat -tunlp | grep nginx Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3290/nginx: master tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 3290/nginx: master 最後將外網ip地址解析爲sentry.test.com 就能夠經過域名訪問sentry了。
不足之處,請多多指教!