用户名和密码都是user
ubuntu22.04
(这一步跳过,新服务器只有一块盘,直接创建一个/data目录,权限777)
安装 sudo apt install zfsutils-linux
创建 sudo zpool create your-pool raidz1 /dev/sdc /dev/sdd /dev/sde
raidz1就是拿一块盘做冗余,raidz3则是拿三块
服务器需要包含两个域名,mds-server.local和global-control.local 新服务器的临时ip是192.168.3.111,且未与采集工控机192.168.0.21连通 所以需要脚本动态获取本机的ip地址
#!/bin/bash
# 获取第一个非127.0.0.1的IPv4地址
IP=$(ip -4 addr show scope global | grep inet | awk '{print $2}' | cut -d/ -f1 | head -n1)
# 检查是否获取成功
if [ -z "$IP" ]; then
echo "No valid IPv4 address found."
exit 1
fi
# 启动avahi-publish(后台运行)
avahi-publish -a -R mds-server.local "$IP" &
avahi-publish -a -R global-control.local "$IP"
[Unit]
Description=Publish custom .local hostnames via avahi
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=/usr/local/bin/avahi_publish.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
Ubuntu 22 Samba 配置指南 暂时没设置密码,可以匿名访问
sudo apt-get update && sudo apt-get install -y dotnet-sdk-6.0
sudo apt update
sudo apt upgrade -y
sudo apt install -y ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) \
signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker run hello-world
docker compose version
遇到报错
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded
Run 'docker run --help' for more information
更换国内加速器
sudo mkdir -p /etc/docker
sudo nano /etc/docker/daemon.json
daemon.json
{
"registry-mirrors": ["https://docker.1ms.run"]
}
sudo systemctl daemon-reexec
sudo systemctl restart docker
sudo apt install docker-compose
docker run运行成功
/home/user/cfet/influxdb
services:
influxdb:
image: influxdb:latest
container_name: influxdb2
volumes:
- /home/user/cfet/influxdb/data:/var/lib/influxdb2:rw
# env_file:
# - .env
# entrypoint: ["./entrypoint.sh"]
ports:
- 8086:8086
restart: unless-stopped
# Use the influx cli to set up an influxdb instance.
influxdb_cli:
links:
- influxdb
image: influxdb:latest
volumes:
# Mount for influxdb data directory and configuration
- /home/user/cfet/influxdb/data:/var/lib/influxdb2:rw
- ./ssl/influxdb-selfsigned.crt:/etc/ssl/influxdb-selfsigned.crt:rw
- ./ssl/influxdb-selfsigned.key:/etc/ssl/influxdb-selfsigned.key:rw
environment:
# Use these same configurations parameters in your telegraf configuration, mytelegraf.conf.
- DOCKER_INFLUXDB_INIT_MODE=setup
- DOCKER_INFLUXDB_INIT_USERNAME=user
- DOCKER_INFLUXDB_INIT_PASSWORD=useruser
- DOCKER_INFLUXDB_INIT_ORG=onesky
- DOCKER_INFLUXDB_INIT_BUCKET=onesky
- DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=xpponKADURu9Jn-gikU809LsuDPL3GVdpClmnrjrnfL5PZEEXi_IDVsiTffAKBbSBXEwshtJgQ9EWldP8HGPnQ==
- INFLUXD_TLS_CERT=/etc/ssl/influxdb-selfsigned.crt
- INFLUXD_TLS_KEY=/etc/ssl/influxdb-selfsigned.key
entrypoint: ["./entrypoint.sh"]
restart: unless-stopped
depends_on:
- influxdb
telegraf:
image: telegraf:latest
container_name: telegraf
# links:
# - influxdb
volumes:
# Sync timezone with host
- /etc/localtime:/etc/localtime:ro
# Map Telegraf configuration file
- /home/user/cfet/influxdb/telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
# Map /tmp to permanent storage (this includes /tmp/metrics.out)
restart: unless-stopped
depends_on:
- influxdb
/home/user/cfet/influxdb/telegraf/telegraf.conf
[agent]
interval = "5s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "5s"
flush_jitter = "0s"
precision = "s"
debug = true
quiet = false
logfile = ""
hostname = "CFET2APP"
omit_hostname = false
[[outputs.influxdb_v2]]
## The URLs of the InfluxDB cluster nodes.
##
## Multiple URLs can be specified for a single cluster, only ONE of the
## urls will be written to each interval.
## urls exp: http://127.0.0.1:8086
urls = ["http://192.168.0.20:8086"]
## Token for authentication.
token = "BnMPy7OCB72QEVLxhIYeQXNOIf8-_d4gp5pZlqNK4RgEEK086T_WN9Y_qp0cJpOWKYWenrWGByq2A9JBwGDyUw=="
## Organization is the name of the organization you wish to write to; must exist.
organization = "onesky"
## Destination bucket to write into.
bucket = "onesky"
[[inputs.http]]
name_override = "onesky"
## One or more URLs from which to read formatted metrics
urls = [
"http://192.168.0.21:8003/opcuaClient/NodeValue/TM_Generator_Stator_Core_Temperature_1"
]
## HTTP method
method = "GET"
#Data from HTTP in JSON format
data_format = "json"
fieldpass = ["CFET2CORE_SAMPLE_VAL"]
[inputs.http.tags]
url = "$url"
[[processors.starlark]]
namepass = ["onesky"]
source = '''
def extract_ipport(url):
start = url.find("//") + 2
end = url.find("/", start)
if end == -1:
end = len(url)
return url[start:end]
def extract_local(url):
start = url.find("/", url.find("//") + 2)
if start == -1:
return ""
return url[start:].strip("/").replace("/", "_")
def apply(metric):
url = metric.tags.get("url")
if url != None and "CFET2CORE_SAMPLE_VAL" in metric.fields:
ipport = extract_ipport(url)
local_address = extract_local(url)
metric.fields[local_address] = metric.fields.pop("CFET2CORE_SAMPLE_VAL")
metric.tags["ipport"] = ipport
metric.tags.pop("url", None)
return metric
'''
[[aggregators.merge]]
period = "5s"
drop_original = true
namepass = ["onesky"]
[[outputs.file]]
files = ["stdout"]
启动: 在.yml文件路径下输入sudo docker-compose up -d
关闭: sudo docker-compose down
启动之后,打开http://localhost:8086,设置用户名user,密码useruser,注册完毕得到token,将其改到docker-compose.yml中。
遇到telegraf的docker频繁重启,sudo docker logs telegraf查看日志
日志显示报错:telegraf.conf failed: error parsing data: line 2: invalid TOML syntax
TOML 格式要求严格,必须使用 标准 ASCII 空格和换行符,否则解析失败。
# 用 sed 自动替换非标准空格为标准空格
sed -i 's/ / /g' telegraf.conf
# 进一步验证配置正确性
telegraf --config telegraf.conf --test
待续。。。