Ubuntu 24.04 InfluxDB をインストールする方法
環境
Ubuntu 24.04
InfluxDBのインストール方法
1.InfluxDB をインストールします。
# apt -y install influxdb influxdb-client
# apt -y install influxdb influxdb-client
# apt -y install influxdb influxdb-client
2.InfluxDB の初期設定を行います
デフォルトでは認証は無効となっているため、認証を有効にしておきます。
# 管理者ユーザー作成
# [admin] ⇒ 任意のユーザー名を設定
# [adminpassword] ⇒ 任意のパスワードを設定
# influx -execute "create user admin with password 'adminpassword' with all privileges"
# influx -execute "show users"
# influx -execute "create user admin with password 'adminpassword' with all privileges"
# influx -execute "show users"
# influx -execute "create user admin with password 'adminpassword' with all privileges" # influx -execute "show users"
3.influxdb.confを編集します
# vi /etc/influxdb/influxdb.conf
[http]
# Determines whether HTTP endpoint is enabled.
# enabled = true
# The bind address used by the HTTP service.
# bind-address = ":8086"
# Determines whether user authentication is enabled over HTTP/HTTPS.
# 226行目 : コメント解除して変更
auth-enabled = true
[http]
# Determines whether HTTP endpoint is enabled.
# enabled = true
# The bind address used by the HTTP service.
# bind-address = ":8086"
# Determines whether user authentication is enabled over HTTP/HTTPS.
# 226行目 : コメント解除して変更
auth-enabled = true
[http] # Determines whether HTTP endpoint is enabled. # enabled = true # The bind address used by the HTTP service. # bind-address = ":8086" # Determines whether user authentication is enabled over HTTP/HTTPS. # 226行目 : コメント解除して変更 auth-enabled = true
influxdbを再起動します
# systemctl restart influxdb
4.認証を有効にした場合は、以下のように InfluxDB へアクセスします。
# InfluxDB の CLI を起動して認証する
# influx
Connected to http://localhost:8086 version 1.6.7~rc0
InfluxDB shell version: 1.6.7~rc0
> auth
username: admin
password:
> exit
# influx
Connected to http://localhost:8086 version 1.6.7~rc0
InfluxDB shell version: 1.6.7~rc0
> auth
username: admin
password:
> exit
# influx Connected to http://localhost:8086 version 1.6.7~rc0 InfluxDB shell version: 1.6.7~rc0 > auth username: admin password: > exit
CLI に認証情報を付加して認証する
# influx -username admin -password adminpassword
Connected to http://localhost:8086 version 1.6.7~rc0
InfluxDB shell version: 1.6.7~rc0
> exit
# influx -username admin -password adminpassword
Connected to http://localhost:8086 version 1.6.7~rc0
InfluxDB shell version: 1.6.7~rc0
> exit
# influx -username admin -password adminpassword Connected to http://localhost:8086 version 1.6.7~rc0 InfluxDB shell version: 1.6.7~rc0 > exit
# 環境変数に認証情報を設定して認証する
# export INFLUX_USERNAME=admin
# export INFLUX_PASSWORD=adminpassword
# influx
Connected to http://localhost:8086 version 1.6.7~rc0
InfluxDB shell version: 1.6.7~rc0
> exit
# export INFLUX_USERNAME=admin
# export INFLUX_PASSWORD=adminpassword
# influx
Connected to http://localhost:8086 version 1.6.7~rc0
InfluxDB shell version: 1.6.7~rc0
> exit
# export INFLUX_USERNAME=admin # export INFLUX_PASSWORD=adminpassword # influx Connected to http://localhost:8086 version 1.6.7~rc0 InfluxDB shell version: 1.6.7~rc0 > exit
5.HTTP API で認証する
# curl -G http://localhost:8086/query?pretty=true -u admin:adminpassword –data-urlencode “q=show users"
結果
{
"results": [
{
"statement_id": 0,
"series": [
{
"columns": [
"user",
"admin"
],
"values": [
[
"admin",
true
]
]
}
]
}
]
}
{
"results": [
{
"statement_id": 0,
"series": [
{
"columns": [
"user",
"admin"
],
"values": [
[
"admin",
true
]
]
}
]
}
]
}
{ "results": [ { "statement_id": 0, "series": [ { "columns": [ "user", "admin" ], "values": [ [ "admin", true ] ] } ] } ] }