夜莺以及mail-sender的安装和配置

官方安装文档https://n9e.didiyun.com/zh/docs/install/compile/

1.源码编译

# 该项目没有使用go module管理,需要放到github.com/didi下编译
mkdir -p $GOROOT/src/github.com/didi
cd $GOROOT/src/github.com/didi

# clone代码并编译打包,pack时会自动build,打包成一个tar.gz
git clone https://github.com/didi/nightingale.git
cd nightingale && ./control build && ./control pack

2.依赖软件安装

安装myql,redis,nginx,可自行百度安装配置

3.初始化数据库

安装mysql,进入$GOROOT/src/github.com/didi/nightingale/sql目录, 将准备好的sql文件直接导入mysql即可:

mysql -uroot -p < sql/n9e_hbs.sql
mysql -uroot -p < sql/n9e_mon.sql
mysql -uroot -p < sql/n9e_uic.sql

4.修改相关配置文件

配置文件在etc目录,着重看一下mysql.yml,修改mysql访问的用户名和密码,另外redis密码默认为空,如果配置了redis的访问密码,需要对应的修改monapi和judge的配置文件,将redis密码配置好。另外在etc/address.yml下可以看到各个模块监听的端口,如果与本地其他服务端口冲突了,需要手工修改一下。

5.配置Nginx

修改nginx配置文件etc/nginx.conf,下面是一个线上可用的配置,注意要把upstream的地址以及location指向pub目录的地址修改为自己的地址。

user root;

worker_processes auto;
worker_cpu_affinity auto;

error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    use epoll;
    worker_connections 204800;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /usr/local/nginx/conf/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;


    proxy_connect_timeout   500ms;
    proxy_send_timeout      1000ms;
    proxy_read_timeout      3000ms;
    proxy_buffers           64 8k;
    proxy_busy_buffers_size    128k;
    proxy_temp_file_write_size 64k;
    proxy_redirect off;
    proxy_next_upstream error invalid_header timeout http_502 http_504;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Real-Port $remote_port;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_comp_level 2;
    gzip_types application/javascript application/x-javascript text/css text/javascript image/jpeg image/gif image/png;
    gzip_vary off;
    gzip_disable "MSIE [1-6]\.";

    upstream n9e.monapi {
        server 127.0.0.1:5800;
        keepalive 10;
    }

    upstream n9e.index {
        server 127.0.0.1:5830;
        keepalive 10;
    }

    upstream n9e.transfer {
        server 127.0.0.1:5810;
        keepalive 10;
    }

    server {
        listen       8080 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            root /home/bigZ/go/src/github.com/didi/nightingale/pub;
        }

        location /api/portal {
            proxy_pass http://n9e.monapi;
        }

        location /api/index {
            proxy_pass http://n9e.index;
        }

        location /api/transfer {
            proxy_pass http://n9e.transfer;
        }
    }

}

6.启动各模块进程

发布包里默认提供了一个control脚本,用来启停服务,直接执行./control start all即可启动所有模块,./control status可以查看各模块进程是否都已启动,夜莺共有6个核心模块,注意一下进程数是否正确。

7.安装mail-sender模块

  • 编译安装
    cd $GOPATH/src
    mkdir -p github.com/n9e
    cd github.com/n9e
    git clone https://github.com/n9e/mail-sender.git
    cd mail-sender
    ./control build
  • 修改配置文件etc/mail-sender.yml
    ---
    logger:
      dir: "logs/mail-sender"
      level: "DEBUG"
      keepHours: 24
    
    #修改redis地址和密码
    redis:
      addr: "127.0.0.1:6379"
      pass: ""
      idle: 5
      db: 0
      timeout:
        conn: 500
        read: 3000
        write: 3000
    
    # 这个配置不用动,worker是调用smtp的并发数
    consumer:
      queue: "/n9e/sender/mail"
      worker: 10
    
    #修改下面的smtp服务配置
    smtp:
      host: ""
      port: 80
      user: ""
      pass: ""
      insecureSkipVerify: true
    
  • 添加mail-sender服务
    cp -a etc/mail-sender.service /usr/lib/systemd/system
    vim /usr/lib/systemd/system/mail-sender.service  #修改execStart WorkingDirectory为真实路径
    systemctl daemon-reload
    systemctl start mail-sender
    systemctl status mail-sender

8.检查各模块进程正常启动

执行./control status如果可以看到下面7个进程,说明所有进程都正常启动了

夜莺以及mail-sender的安装和配置_第1张图片

你可能感兴趣的:(夜莺,安装配置)