1.离线安装脚本
为了能够快速部署,编写了离线安装配置的 shell 脚本,安装文件为influxdb-1.7.6.x86_64.rpm
脚本内容如下:
#!/bin/bash # yum -y remove influxdb.x86_64 echo "(1/6): 安装InfluxDB..." yum localinstall -y influxdb-1.7.6.x86_64.rpm echo "(1/6): InfluxDB安装完毕" echo "(2/6): 配置InfluxDB运行参数..." mkdir -p /home/influxdb/meta mkdir -p /home/influxdb/data mkdir -p /home/influxdb/wal chown -R influxdb:influxdb /home/influxdb sed -i "26c dir = \"/home/influxdb/meta\"" /etc/influxdb/influxdb.conf sed -i "45c dir = \"/home/influxdb/data\"" /etc/influxdb/influxdb.conf sed -i "48c wal-dir = \"/home/influxdb/wal\"" /etc/influxdb/influxdb.conf sed -i "247c enabled = true" /etc/influxdb/influxdb.conf echo "(2/6): InfluxDB运行参数配置完毕" echo "(3/6): 首次启动InfluxDB..." systemctl start influxd sleep 3 systemctl status influxd echo "(3/6): InfluxDB首次启动完毕" echo "(4/6): 创建用户及数据库..." influx -execute 'create user "dsj" with password '\''dsj'\'' with all privileges;' -format 'json' -pretty sleep 1 influx -execute 'create database "sjzt";' -format 'json' -pretty sleep 1 echo "(4/6): 用户及数据库创建完毕" echo "(5/6): 开启权限认证并重启InfluxDB..." sed -i "259c auth-enabled = true" /etc/influxdb/influxdb.conf systemctl restart influxd sleep 3 systemctl status influxd echo "(5/6): 开启权限认证并重启InfluxDB完毕" echo "(6/6): 配置InfluxDB开机启动..." cat <<EOF >> /etc/rc.loal systemctl start influxd EOF echo "(6/6): InfluxDB开机启动配置完毕"
2.问题处理
使用systemctl start influxd
启动过一会儿就停止了,但是使用/usr/bin/influxd -config /etc/influxdb/influxdb.conf
命令可以正常启动,
# 查看系统的日志信息 tail -f /var/log/messages # 报错 run: open server: open tsdb store: mkdir /home/influxdb/data/_internal/_series: permission denied # 处理 chown -R influxdb:influxdb /home/influxdb/data # 再次启动后报错 error="mkdir /home/influxdb/wal/_internal: permission denied" # 最终处理 chown -R influxdb:influxdb /home/influxdb
3.脚本调整
调整 1️⃣ 启动后睡眠3s
保证数据库启动完成,否则创建用户或数据库会报错。
echo "3.启动InfluxDB..." systemctl start influxd sleep 3 systemctl status influxd echo "3.启动InfluxDB完毕"