目录
夜莺的服务端有两个模块:n9e-webapi 和 n9e-server,n9e-webapi 用于提供 API 给前端 JavaScript 使用,n9e-server 的职责是告警引擎和数据转发器。依赖的组件有 MySQL、Redis、时序库,时序库我们这里使用 Prometheus。
1.1 安装依赖组件
1. install prometheus
[root@localhost ~]# mkdir -p /opt/prometheus
[root@localhost ~]# wget https://s3-gz01.didistatic.com/n9e-pub/prome/prometheus-2.28.0.linux-amd64.tar.gz -O prometheus-2.28.0.linux-amd64.tar.gz
[root@localhost ~]# tar xf prometheus-2.28.0.linux-amd64.tar.gz
[root@localhost ~]# cp -far prometheus-2.28.0.linux-amd64/* /opt/prometheus/
[root@localhost ~]# cat <<EOF >/etc/systemd/system/prometheus.service
> [Unit]
> Description="prometheus"
> Documentation=https://prometheus.io/
> After=network.target
>
> [Service]
> Type=simple
>
> ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --storage.tsdb.path=/opt/prometheus/data --web.enable-lifecycle --enable-feature=remote-write-receiver --query.lookback-delta=2m
>
> Restart=on-failure
> SuccessExitStatus=0
> LimitNOFILE=65536
> StandardOutput=syslog
> StandardError=syslog
> SyslogIdentifier=prometheus
>
>
> [Install]
> WantedBy=multi-user.target
> EOF
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable prometheus
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /etc/systemd/system/prometheus.service.
[root@localhost ~]# systemctl restart prometheus
[root@localhost ~]# systemctl status prometheus
● prometheus.service - "prometheus"
Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
Active: active (running) since 四 2023-04-06 11:11:18 CST; 6s ago
2. install mysql
[root@localhost ~]# yum -y install mariadb*
[root@localhost ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# mysql -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('1234');"
# 建议使用默认1234的密码,这样无需修改配置文件,否则要手动修改/opt/n9e下的etc/server.conf和etc/webapi.conf
3. install redis
[root@localhost ~]# yum install -y epel-release
[root@localhost ~]# yum install -y redis
[root@flashcat ~]# systemctl enable redis
[root@flashcat ~]# systemctl restart redis
1.2 安装夜莺
[root@flashcat ~]# mkdir -p /opt/n9e && cd /opt/n9e
# 最新安装包获取地址 https://github.com/didi/nightingale/releases
[root@flashcat n9e]# tarball=n9e-v6.0.0-ga.2.0.2-linux-amd64.tar.gz
[root@flashcat n9e]# urlpath=https://github.com/didi/nightingale/releases/download/v6.0.0-ga.2/${tarball}
[root@flashcat n9e]# wget $urlpath
# 无法下载时,建议先Windows下载好,再传到Linux机器
[root@flashcat n9e]# tar zxvf ${tarball}
[root@flashcat n9e]# mysql -uroot -p1234 < docker/initsql/a-n9e.sql
[root@flashcat n9e]# vim etc/service/n9e-server.service
# 修改如下两行
ExecStart=/opt/n9e/n9e server
WorkingDirectory=/opt/n9e
[root@flashcat n9e]# cp etc/service/n9e-server.service /usr/lib/systemd/system/
[root@flashcat n9e]# systemctl start n9e-server
[root@flashcat n9e]# systemctl enable n9e-server
4月 06 17:03:38 flashcat systemd[1]: n9e-server.service failed.
[root@flashcat n9e]# vim etc/service/n9e-webapi.service
[root@flashcat n9e]# cp etc/service/n9e-webapi.service /usr/lib/systemd/system
[root@flashcat n9e]# systemctl start n9e-webapi
[root@flashcat n9e]# systemctl enable n9e-webapi
Created symlink from /etc/systemd/system/multi-user.target.wants/n9e-webapi.service to /usr/lib/systemd/system/n9e-webapi.service.
[root@flashcat n9e]# systemctl status n9e-webapi
如果启动成功,server 默认会监听在 19000 端口,webapi 会监听在 18000 端口,且日志没有报错。
浏览器访问 webapi 的端口(默认是18000)就可以体验相关功能了,默认用户是root,密码是root.2020