centos 配置sentry+釘釘+郵件通知


1.sentry官方推薦docker方式安裝。使用docker-compose,最好是centos7

2.卸載舊版本

yum remove docker  docker-common  docker-selinux  docker-engine

3.安裝依賴包

yum install -y yum-utils   device-mapper-persistent-data   lvm2

4.添加docker yum源

yum-config-manager     --add-repo     https://download.docker.com/linux/centos/docker-ce.repo

5.可選操作:允許拓展最新的不穩定repository

yum-config-manager --enable docker-ce-edge

6.安裝Docker

yum -y install docker-ce

7.啟動Docker

systemctl start docker

8.測試Docker

docker run hello-world

出現這個表示成功

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

9.安裝依賴,需要用到git,docker-compose,pip等組件

yum install epel-release
yum  install -y python-pip
pip  install docker-compose
yum install git

安裝第三個的時候會報錯:

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-SL8ohy/pycparser/
You are using pip version 8.1.2, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

然后我升級了

 pip install --upgrade pip

發現還是報錯:

 ERROR: Complete output from command python setup.py egg_info:
    ERROR: Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-5OHP7Q/pycparser/setup.py", line 65, in <module>
        cmdclass={'install': install, 'sdist': sdist},
      File "/usr/lib64/python2.7/distutils/core.py", line 112, in setup
        _setup_distribution = dist = klass(attrs)
      File "/usr/lib/python2.7/site-packages/setuptools/dist.py", line 269, in __init__
        _Distribution.__init__(self,attrs)
      File "/usr/lib64/python2.7/distutils/dist.py", line 287, in __init__
        self.finalize_options()
      File "/usr/lib/python2.7/site-packages/setuptools/dist.py", line 302, in finalize_options
        ep.load()(self, ep.name, value)
      File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2341, in load
        return self.resolve()
      File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2351, in resolve
        raise ImportError(str(exc))
    ImportError: 'module' object has no attribute 'check_specifier'
    ----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-5OHP7Q/pycparser/

解決:

pip install --upgrade setuptools==30.1.0

如果報這個錯誤:

/usr/lib/python2.7/site-packages/requests/ __init__。py:91: RequestsDependencyWarning: urllib3(1.22)或chardet(2.2.1)與受支持的版本不匹配!  RequestsDependencyWarning)

先卸載

sudo pip uninstall urllib3
sudo pip uninstall chardet
sudo pip install requests

 

 

10.瀏覽器打開:https://github.com/getsentry/onpremise ,查看README.md步驟

[root@iZ2zecyg8c7tlv5yz9c9vhZ www]# mkdir -p data/{sentry,postgres}
[root@iZ2zecyg8c7tlv5yz9c9vhZ www]# ll
total 4
drwxr-xr-x 4 root root 4096 Jun  6 18:18 data
[root@iZ2zecyg8c7tlv5yz9c9vhZ www]# 

11.克隆該項目

git clone https://github.com/getsentry/onpremise.git

 

[root@iZ2zecyg8c7tlv5yz9c9vhZ www]# git clone https://github.com/getsentry/onpremise.git
Cloning into 'onpremise'...
remote: Enumerating objects: 190, done.
remote: Total 190 (delta 0), reused 0 (delta 0), pack-reused 190
Receiving objects: 100% (190/190), 37.55 KiB | 0 bytes/s, done.
Resolving deltas: 100% (90/90), done.
[root@iZ2zecyg8c7tlv5yz9c9vhZ www]# ll
total 8
drwxr-xr-x 4 root root 4096 Jun  6 18:18 data
drwxr-xr-x 3 root root 4096 Jun  6 18:19 onpremise
[root@iZ2zecyg8c7tlv5yz9c9vhZ www]# 

12.進入onpremise目錄

[root@iZ2zecyg8c7tlv5yz9c9vhZ www]# cd onpremise/
[root@iZ2zecyg8c7tlv5yz9c9vhZ onpremise]# ll
total 36
-rw-r--r-- 1 root root  1946 Jun  6 18:19 config.yml
-rw-r--r-- 1 root root  1240 Jun  6 18:19 docker-compose.yml
-rw-r--r-- 1 root root    24 Jun  6 18:19 Dockerfile
-rw-r--r-- 1 root root   500 Jun  6 18:19 Makefile
-rw-r--r-- 1 root root  2306 Jun  6 18:19 README.md
-rw-r--r-- 1 root root    19 Jun  6 18:19 requirements.txt
-rw-r--r-- 1 root root 11257 Jun  6 18:19 sentry.conf.py
[root@iZ2zecyg8c7tlv5yz9c9vhZ onpremise]# cp -n .env.example .env
[root@iZ2zecyg8c7tlv5yz9c9vhZ onpremise]# docker-compose build

13.生成秘鑰:(copy最后一行的秘鑰)

[root@iZ2zecyg8c7tlv5yz9c9vhZ onpremise]# docker-compose run --rm web config generate-secret-key
/usr/lib/python2.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.24.1) or chardet (2.2.1) doesn't match a supported version!
  RequestsDependencyWarning)
Creating network "onpremise_default" with the default driver
ERROR: Volume sentry-data declared as external, but could not be found. Please create the volume manually using `docker volume create --name=sentry-data` and try again.
[root@iZ2zecyg8c7tlv5yz9c9vhZ onpremise]# docker volume create --name=sentry-data && docker volume create --name=sentry-postgres
sentry-data
sentry-postgres
Status: Downloaded newer image for memcached:1.5-alpine
Creating onpremise_postgres_1  ... done
Creating onpremise_smtp_1      ... done
Creating onpremise_redis_1     ... done
Creating onpremise_memcached_1 ... done
38v@*^_b&&00%4yk8uvthl^8h3ycg3)1ovuf&&q+=^5#vrsj0h

14 將秘鑰添加進入docker-compose.yml

vim docker-compose.yml
environment:
    SENTRY_SECRET_KEY: '38v@*^_b&&00%4yk8uvthl^8h3ycg3)1ovuf&&q+=^5#vrsj0h'
    SENTRY_MEMCACHED_HOST: memcached
    SENTRY_REDIS_HOST: redis
    SENTRY_POSTGRES_HOST: postgres
    SENTRY_EMAIL_HOST: smtp
  volumes:

15.創建數據庫(在創建數據的時候會提示我們是否需要創建管理員,我們選擇Y,填入對應的郵箱地址和密碼,等一下登陸WEB需要,是否是超級管理員也選擇Y)

docker-compose run --rm web upgrade

16.啟動所有服務

docker-compose up -d

17.驗證docker啟動狀態

docker ps

到此我們的sentry就已經部署完成了,訪問我們的  服務器ip:9000端口就可以看見sentry的界面

root@iZ2zecyg8c7tlv5yz9c9vhZ onpremise]# docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                    NAMES
bf6f7118caae        onpremise_worker       "/entrypoint.sh run …"   57 seconds ago      Up 56 seconds       9000/tcp                 onpremise_worker_1
e4becbb4b226        onpremise_cron         "/entrypoint.sh run …"   57 seconds ago      Up 56 seconds       9000/tcp                 onpremise_cron_1
320e80f03c7c        onpremise_web          "/entrypoint.sh run …"   57 seconds ago      Up 56 seconds       0.0.0.0:9000->9000/tcp   onpremise_web_1
4b534ff5ffdb        memcached:1.5-alpine   "docker-entrypoint.s…"   8 minutes ago       Up 8 minutes        11211/tcp                onpremise_memcached_1
c45bbcd62618        redis:3.2-alpine       "docker-entrypoint.s…"   8 minutes ago       Up 8 minutes        6379/tcp                 onpremise_redis_1
1c1c90b47c0b        postgres:9.5           "docker-entrypoint.s…"   8 minutes ago       Up 8 minutes        5432/tcp                 onpremise_postgres_1
d3ba6bef6c12        tianon/exim4           "docker-entrypoint.s…"   8 minutes ago       Up 8 minutes        25/tcp                   onpremise_smtp_1

18.瀏覽器輸入服務器ip+9000端口就可以訪問

 

19.點擊用戶可更改中文模式和時間

20.配置釘釘通知:

 vim requirements.txt 

# Add plugins here
sentry-dingtalk-new
django-smtp-ssl~=1.0
redis-py-cluster==1.3.4
docker-compose build
docker-compose restart

在web端,創建項目,配置,查看是否有dingtalk。在釘釘拉一個組,創建自定義機器人。將連接copy放入dingtalkRoot 里,保存,點擊test plugin 測試查看消息

 

21.配置郵箱:

vim config.yml 

username 郵箱地址

password不是密碼。是客戶端授權密碼

mail.backend: 'django_smtp_ssl.SSLEmailBackend'  # Use dummy if you want to disable email entirely
mail.host: 'smtphz.qiye.163.com'
mail.port: 994
mail.username: 'xxxx@xxx.com'
mail.password: 'xxxx'
mail.use-tls: true
# The email address to send on behalf of
mail.from: 'xxx@xxxcom'
$ docker-compose build
$ docker-compose up -d

然后重新運行

 

22.在c# 中

導入 sentry 包

x1:公鑰,x2:私鑰,xxx:服務器ip,5=項目id

using Sentry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SentryTest {
    class Program {
        static void Main(string[] args) {
            using (SentrySdk.Init("http://x1:x2@xxx:9000/5")) {
                try {
                    var s = (0/1);
                    SentrySdk.CaptureMessage("ppp9");
                }
                catch (Exception ex) {
                    //SentrySdk.CaptureException(ex);
                }
            }
        }

    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM