环境部署
- Prometheus 数据源环境部署
#下载prom,下载链接:https://prometheus.io/download/
#如果下载慢,可以使用国内源地址:https://mirrors.tuna.tsinghua.edu.cn/github-release/prometheus/prometheus/LatestRelease/
mkdir /opt/prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.43.0/prometheus-2.43.0.linux-amd64.tar.gz
tar xf prometheus-2.43.0.linux-amd64.tar.gz
mv prometheus-2.43.0.linux-amd64/* /opt/prometheus/
#将 prom 注册为service服务
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
systemctl daemon-reload
systemctl enable prometheus
systemctl start prometheus
- 数据库环境部署
# MySQL 下载链接:https://downloads.mysql.com/archives/community/
#下载 MySQL 并初始化数据库
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.40-linux-glibc2.12-x86_64.tar.gz
tar xf mysql-5.7.40-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.40-linux-glibc2.12-x86_64 /opt/mysql
mkdir -p /opt/mysql/{data,log}
cd /opt/mysql/bin/
useradd mysql -s /sbin/nologin -M -r
chown -R mysql.mysql /opt/mysql
./mysqld --initialize-insecure --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data
#添加 MySQL 配置文件
cat << EOF >> /etc/my.cnf
[mysqld]
user=mysql
basedir=/opt/mysql
datadir=/opt/mysql/data
socket=/opt/mysql/mysql.sock
symbolic-links=0
character-set-server = utf8mb4
open_files_limit= 65535
max_connections = 256
max_user_connections = 64
max_connect_errors = 10000
log_timestamps = SYSTEM
slow_query_log = 1
slow_query_log_file = /opt/mysql/log/slow.log
server-id=1
long_query_time = 0.1
log-bin = /opt/mysql/log/mysql-bin
max_binlog_cache_size = 512M
max_binlog_size = 1G
expire_logs_days = 7
skip_name_resolve = 1
[mysqld_safe]
log-error=/opt/mysql/log/err.log
pid-file=/opt/mysql/mysqld.pid
EOF
#注册 MySQL 为服务
cat << EOF >> /etc/systemd/system/mysqld.service
[Unit]
Description=MYSQL server
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=forking
TimeoutSec=0
PermissionsStartOnly=true
ExecStart=/opt/mysql/bin/mysqld --defaults-file=/etc/my.cnf --daemonize $OPTIONS
ExecReload=/bin/kill -HUP -$MAINPID #这里-HUP可以是改成-s HUP,就变成强制杀进程,有需要可以改,下面也一样
ExecStop=/bin/kill -QUIT $MAINPID #-s QUIT是强制杀进程
KillMode=process
LimitNOFILE=65535
Restart=on-failure
RestartSec=10
RestartPreventExitStatus=1
PrivateTmp=false
EOF
systemctl daemon-reload
systemctl enable mysqld
systemctl start mysqld
#设置 MySQL 密码为:n9etest
./mysqladmin -u root password "n9etest" -S ../mysql.sock
./mysql -uroot -p -S ../mysql.sock -e "grant all on *.* to root@'%' identified by 'n9etest'"
#redis下载地址:https://redis.io/download/
mkdir -p /opt/redis
wget https://github.com/redis/redis/archive/7.0.10.tar.gz
tar xf 7.0.10.tar.gz
cd redis-7.0.10/
make PREFIX=/opt/redis install
cd /opt/redis/
cp -a /opt/redis-7.0.10/redis.conf /opt/redis/bin/
cd bin
#修改redis配置文件
sed -i /protected-mode/s/yes/no/g redis.conf
sed -i /bind/s/127.0.0.1/0.0.0.0/g redis.conf
sed -i /daemonize/s/no/yes/g redis.conf
sed -i "/requirepass foobared/arequirpass n9etest" redis.conf
#将 redis 注册为服务
cat << EOF >> /etc/systemd/system/redis.service
[Unit]
Description=Redis data structure server
Documentation=https://redis.io/documentation
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/opt/redis/bin/redis-server /opt/redis/bin/redis.conf
LimitNOFILE=10032
NoNewPrivileges=yes
Type=forking
PrivateTmp=true
UMask=0077
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start redis
systemctl enable redis
- 安装n9e
#下载链接:https://github.com/didi/nightingale/releases
mkdir /opt/n9e
wget https://github.com/ccfos/nightingale/releases/download/v6.0.0-ga.4.1/n9e-v6.0.0-ga.4.1-linux-amd64.tar.gz
tar xf n9e-v6.0.0-ga.4.1-linux-amd64.tar.gz -C .opt.n9e
cd /opt/n9e
/opt/mysql/bin/mysql -uroot -p -S /opt/mysql/mysql.sock < n9e.sql
#修改配置文件
sed -i /DSN/s/1234/n9etest/g config.toml
sed -i "/Address/aPassword = “n9etest”" config.toml
#注册为服务
cat << EOF >> /etc/systemd/system/n9e.service
[Unit]
Description="n9e"
Documentation=https://github.com/ccfos/nightingale
After=network.target
After=redis.target
After=mysqld.target
[Service]
Type=simple
ExecStart=/opt/n9e/n9e --configs /opt/n9e/etc
Restart=on-failure
SuccessExitStatus=0
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=n9e
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start n9e
systemctl enable n9e
- 安装 categraf 采集器
#n9e默认推荐使用 categraf 作为采集器收集数据
#下载地址:https://flashcat.cloud/download/categraf/
#配置文件详解:https://flashcat.cloud/docs/content/flashcat-monitor/categraf/3-configuration/
wget https://download.flashcat.cloud/categraf-v0.2.39-linux-amd64-with-cgo-plugin.tar.gz
tar xf categraf-v0.2.39-linux-amd64-with-cgo-plugin.tar.gz
mv categraf-v0.2.39-linux-amd64-with-cgo-plugin /opt/categraf/
cd /opt/categraf/conf
cp -a categraf.service /etc/systemd/system/
systemctl daemon-reload
systemctl start categraf
systemctl enable categraf
注:这里启动可能会出现报错
实际系统内的libpcap版本会比要求的高一些,重新指一下软链接即可
代码语言:javascript复制cd /lib64/
ln -s libpcap.so.1.5.3 libpcap.so.0.8
再次启动就可以了
至此,所有基础服务部署完成