侧边栏壁纸
博主头像
SRE实战博主等级

行动起来,活在当下

  • 累计撰写 12 篇文章
  • 累计创建 1 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

夜莺监控安装

Miracle
2024-03-01 / 0 评论 / 0 点赞 / 32 阅读 / 11596 字

二进制方式安装

安装 prometheus

1.下载解压 prometheus
version=2.37.1
insdir=/usr/local/prometheus
datadir=/home/nightingale/prometheus
wget https://github.com/prometheus/prometheus/releases/download/v${version}/prometheus-${version}.linux-amd64.tar.gz

# 创建数据目录,解压
mkdir -p ${insdir} ${datadir}
tar xf prometheus-${version}.linux-amd64.tar.gz --strip-components=1 -C ${insdir}

2. 配置 prometheus 服务
# service 
cat <<EOF >/etc/systemd/system/prometheus.service
[Unit]
Description="prometheus"
Documentation=https://prometheus.io
After=network.target

[Service]
Type=simple
ExecStart=${insdir}/prometheus  --config.file=${insdir}/prometheus.yml --storage.tsdb.path=${datadir} --web.enable-lifecycle --enable-feature=remote-write-receiver --query.lookback-delta=2m 

Restart=always
RestartSec=10s
SuccessExitStatus=0
LimitNOFILE=65536
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=prometheus

[Install]
WantedBy=multi-user.target
EOF

# 配置服务开机自启,启动服务
systemctl daemon-reload
systemctl enable --now prometheus
systemctl restart prometheus
systemctl status prometheus

3. 配置防火墙
firewall-cmd --zone=public --add-port=9090/tcp 
firewall-cmd --zone=public --add-port=9090/tcp --permanent

安装 MySQL

1. 安装依赖包
yum install -y libaio numactl-libs ncurses-compat-libs
2. 创建服务运行用户
# 数据目录
datadir=/home/nightingale/mysql

# 创建运行用户,组
groupadd -g 27 -o -r mysql
useradd -M -N -g mysql -o -r -d ${datadir} -s /bin/false -c "MySQL Server" -u 27 mysql
3. 下载解压Mysql 二进制安装包
mysql_ver=5.7.38
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-${mysql_ver}-linux-glibc2.12-x86_64.tar.gz
tar xfz mysql-${mysql_ver}-linux-glibc2.12-x86_64.tar.gz -C /usr/local

# 配置/读取环境变量
ln -sf /usr/local/mysql-${mysql_ver}-linux-glibc2.12-x86_64 /usr/local/mysql
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
source /etc/profile

4. 创建配置文件

cat <<EOF   > /etc/my.cnf
[mysqld]
datadir=${datadir}
socket=${datadir}/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=${datadir}/mysqld.pid

[client]
socket=${datadir}/mysql.sock
EOF

5. 创建数据,日志目录

# 创建数据存储目录
mkdir -p ${datadir}
chown -Rf mysql:mysql ${datadir}

# 配置日志权限
touch /var/log/mysqld.log
chown mysql:mysql /var/log/mysqld.log
6. 初始化数据库
mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql --ssl
7. 配置 mysql 用户打开文件限制
grep -q mysql /etc/security/limits.conf || cat <<EOF  >> /etc/security/limits.conf

# mysql
mysql hard nofile 65535
mysql soft nofile 65535
EOF
8. 配置 mysql 服务
cat <<EOF   > /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(7)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql

Type=forking
PIDFile=${datadir}/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Start main service
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --daemonize \$MYSQLD_OPTS 

# Sets open_files_limit
LimitNOFILE = 65535

Restart=always
RestartSec=10

RestartPreventExitStatus=1 

PrivateTmp=false
EOF
7. 启动服务,跟随系统启动
systemctl daemon-reload
systemctl enable --now mysqld
systemctl restart mysqld
8. 初始化密码
# 配置密码(仅本机访问)
mysql_pass=Ck3VX7Q69itVRB0DpNX4KH
mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$mysql_pass'"

Redis 安装

1. 安装 redis
yum install -y redis
2. 启动服务
systemctl enable --now redis
systemctl restart redis

n9e 安装

1. 安装 n9e
# 下载安装包
version=5.11.3
insdir=/usr/local/n9e-server
datadir=/home/nightingale/n9e-server
wget https://ghproxy.com/https://github.com/ccfos/nightingale/releases/download/v${version}/n9e-v${version}-linux-amd64.tar.gz

# 创建数据目录,解压
mkdir -p ${insdir} #${datadir}
tar xf n9e-v${version}-linux-amd64.tar.gz -C ${insdir}
2. 导入 n9e sql
# 导入sql
mysql -uroot < ${insdir}/docker/initsql/a-n9e.sql -p${mysql_pass}

# 替换数据库配置
sed -i "s#root:1234#root:${mysql_pass}#" ${insdir}/etc/webapi.conf ${insdir}/etc/server.conf

3. 配置服务
# n9e-server.service
cat <<EOF >/etc/systemd/system/n9e-server.service
[Unit]
Description="n9e-server"
After=network.target

[Service]
Type=simple

ExecStart=${insdir}/n9e server
WorkingDirectory=${insdir}

Restart=on-failure
SuccessExitStatus=0
LimitNOFILE=65536
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=n9e-server

[Install]
WantedBy=multi-user.target
EOF

# systemn9e-webapi.service
cat <<EOF >/etc/systemd/system/n9e-webapi.service
[Unit]
Description="n9e-webapi"
After=network.target

[Service]
Type=simple

ExecStart=${insdir}/n9e webapi
WorkingDirectory=${insdir}

Restart=on-failure
SuccessExitStatus=0
LimitNOFILE=65536
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=n9e-webapi

[Install]
WantedBy=multi-user.target
EOF
4. 启动服务
systemctl enable --now n9e-server.service
systemctl enable --now n9e-webapi.service
systemctl restart n9e-server n9e-webapi.service
5. 服务地址
# WebUi:    http://192.168.6.82:18000      root/root.2020

docker 方式部署

1. docker 环境安装

bash <(curl -sSL https://dwz.cn/XOJj0Njx) -i docker
bash <(curl -sSL https://dwz.cn/XOJj0Njx) -i compose
source ~/.bashrc

2. 部署 docker-nightingale

git clone https://ghproxy.com/https://github.com/didi/nightingale.git
/usr/bin/cp -r nightingale/docker docker-nightingale
cd docker-nightingale
docker-compose up -d

Categraf 安装配置(被监控端)

1. 安装 categraf

curl -s http://oss.hc-yun.com/script/monitor_ne.sh | bash -s -- \
  --ins client \
  --insdir /usr/local \
  --server http://172.168.100.33:19000 \
  --eth eth0 \
  --labels platform=服务器类型,region=服务器区域,project=项目名称


# --ins       执行类型
# --insdir    安装路径
# --server    监控服务器地址
# --eth       多网卡情况下指定与服务器的通信网卡
# --liabels   指定服务器标签

2. 配置微服务监控

curl -s http://oss.hc-yun.com/script/monitor_ne.sh | bash -s -- \
  --config wfw \
  --labels platform=服务器类型,region=服务器区域,project=项目名称


# --config    配置服务类型 微服务
# --liabels   指定监控项标签

3. 配置基础环境监控

curl -s http://oss.hc-yun.com/script/monitor_ne.sh | bash -s -- \
  --config systemctl \
  --labels platform=服务器类型,region=服务器区域,project=项目名称


# --config    配置服务类型 /etc/rc,local 文件内 systemctl服务监控进程及端口
# --liabels   指定监控项标签
0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区