1.登陆机器
机器有密码,每次登陆都要输入,好麻烦,于是这样:
ssh-copy-id root@x.x.x.x
它会将你本机的公钥添加到目标机器的 ~/.ssh/authorized_keys 中,并对文件夹与文件设置合适的权限
2.安装 nodejs(忽略)
安装nodejs
yum install nodejs
使用cnpm替换npm来加速下载
npm install -g cnpm --registry=https://registry.npm.taobao.org
下载 n
cnpm install -g n
使用n更新nodejs到最新稳定版本
n stable
3.安装pm2(忽略)
cnpm install pm2@latest -g
4.下载安装 influxdb
wget https://dl.influxdata.com/influxdb/releases/influxdb-1.3.2.x86_64.rpm
sudo yum localinstall influxdb-1.3.2.x86_64.rpm
5.配置、启动、设置开机启动
# 默认配置
/etc/influxdb/influxdb.conf
# 启动
service influxdb start
# 设置开机启动
systemctl enable influxdb
6.为 influxdb 添加权限认证
[http]
enabled = true
bind-address = ":8086"
auth-enabled = true # ✨
log-enabled = true
然后重启实例验证:
curl -G http://localhost:8086/query --data-urlencode "q=SHOW DATABASES"
返回:
{"results":[{"statement_id":0,"series":[{"name":"databases","columns":["name"],"values":[["_internal"]]}]}]}
即说明未开启认证
返回:
{"error":"error authorizing query: create admin user first or disable authentication"}
即说明已开启认证
当我们开启了认证,influxdb需要我们至少创建一个admin用户,不然不能交互
创建一个 admin 用户(至少一个)
# influx
Connected to http://localhost:8086 version 1.3.2
InfluxDB shell version: 1.3.2
> CREATE USER admin with PASSWORD 'password' WITH ALL PRIVILEGES
>
我们创建了用户:
验证:
curl -G http://localhost:8086/query -u admin:password --data-urlencode "q=SHOW DATABASES"
7.访问日志
因为我们刚才开启了日志(log-enabled = true):
可以在:
/var/log/message
查看访问记录
Aug 9 20:16:57 localhost influxd: [httpd] 127.0.0.1 - admin [09/Aug/2017:20:16:57 +0800] "GET /query?q=SHOW%20DATABASES HTTP/1.1" 401 33 "-" "curl/7.29.0" a395f891-7cfc-11e7-800a-000000000000 119520 Aug 9 20:17:06 localhost influxd: [I] 2017-08-09T12:17:06Z SHOW DATABASES service=query Aug 9 20:17:06 localhost influxd: [httpd] 127.0.0.1 - admin [09/Aug/2017:20:17:06 +0800] "GET /query?q=SHOW+DATABASES HTTP/1.1" 200 109 "-" "curl/7.29.0" a92acfad-7cfc-11e7-800b-000000000000 531 Aug 9 20:17:09 localhost influxd: [I] 2017-08-09T12:17:09Z SHOW DATABASES service=query Aug 9 20:17:09 localhost influxd: [httpd] 127.0.0.1 - admin [09/Aug/2017:20:17:09 +0800] "GET /query?q=SHOW+DATABASES HTTP/1.1" 200 109 "-" "curl/7.29.0" aaf24597-7cfc-11e7-800c-000000000000 549 Aug 9 20:17:10 localhost influxd: [I] 2017-08-09T12:17:10Z SHOW DATABASES service=query Aug 9 20:17:10 localhost influxd: [httpd] 127.0.0.1 - admin [09/Aug/2017:20:17:10 +0800] "GET /query?q=SHOW+DATABASES HTTP/1.1" 200 109 "-" "curl/7.29.0" ab5ead93-7cfc-11e7-800d-000000000000 582 Aug 9 20:17:11 localhost influxd: [I] 2017-08-09T12:17:11Z SHOW DATABASES service=query Aug 9 20:17:11 localhost influxd: [httpd] 127.0.0.1 - admin [09/Aug/2017:20:17:11 +0800] "GET /query?q=SHOW+DATABASES HTTP/1.1" 200 109 "-" "curl/7.29.0" abc7cbd1-7cfc-11e7-800e-000000000000 496
后面会补充些权限与用户的东西
你们不要以为这就完啦,当然不是搭建这么容易,后面还有 aggregation 等偏应用的东西