commit 75d305a03aaea8cca1b26ba7b62ef9f968ccf109 Author: Márcio Fernandes Date: Tue May 7 16:54:47 2024 +0100 refactoring diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d0dfe3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +docker/has +docker/lms +docker/mosquitto diff --git a/README.md b/README.md new file mode 100644 index 0000000..067c3ac --- /dev/null +++ b/README.md @@ -0,0 +1,110 @@ +# homesrv01.dev.lan + +Welcome to homesrv01.dev.lan git page. + +## OS + +Currently hosted on a proxmox ubuntu container. + +Distributor ID: Ubuntu +Description: Ubuntu 23.04 +Release: 23.04 +Codename: lunar +Kernel: 5.15.111-1-pve + +```bash +# check ubuntu release +lsb_release -a + +# check kernel version +uname -r +``` +## Development / Maintenance Environment + +Currently docker code server as an editor. + +But doing this way, **it is important to remember that editing files, git commands and control is done in VS CODE on the Development machine, but the execution of commands must be done over ssh.** + + +## setup + +```bash +apt update -y && apt upgrade -y +apt install curl -y +apt install git -y +curl -fsSL https://get.docker.com -o get-docker.sh && sh ./get-docker.sh +docker run hello-world && docker info +docker volume create --driver local --opt type=none --opt device=/ --opt o=bind host_fs +apt install sshfs +``` + +## fstab + +``` +#etc/fstab +#sshfs#media@nas.lan:/home/media /mnt/media@sshfs:nas.lan fuse defaults,_netdev,allow_other,follow_symlinks 0 0 +``` + + +## ssh + +```bash +#/etc/ssh/sshd_config +PermitRootLogin no +``` + +```bash +systemctl restart ssh +``` + + +## Update System + +```bash +apt update -y && apt upgrade -y && apt autoremove -y +``` + +if error on update because of EOL [check oficial documentation](https://help.ubuntu.com/community/EOLUpgrades#SpecificOlder) + +## logs & Promtail + +Check folder docker/promtail for more information + + + + +## Services (Stacks) + +### Portainer +for more information [check](https://git.limbosolutions.com/kb/portainer) + +``` bash +docker pull portainer/portainer-ce +docker stop portainer +docker rm portainer +docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer:/data portainer/portainer-ce +``` + +### code-server +[docker-compose](docker/code-server/docker-compose.yaml) + +### home assistant +[docker-compose](docker/has/docker-compose.yaml) + +### LMS +[docker-compose](docker/lms/docker-compose.yaml) + +### mosquitto +[docker-compose](docker/mosquitto/docker-compose.yaml) + +### duplicati +- Duplicati +[docker-compose](docker/duplicati/docker-compose.yaml) + + +### External volumes + +``` +docker volume create --driver local --opt type=none --opt device=/home/admin/repos --opt o=bind hostfs_home_admin_repos +docker volume create --driver local --opt type=none --opt device=/mnt/media@sshfs:nas.lan --opt o=bind music +``` diff --git a/docker/code-server/docker-compose.yaml b/docker/code-server/docker-compose.yaml new file mode 100644 index 0000000..04da1ac --- /dev/null +++ b/docker/code-server/docker-compose.yaml @@ -0,0 +1,41 @@ +version: '3' +services: + code-server: + container_name: code + image: lscr.io/linuxserver/code-server:latest + environment: + - PUID=0 + - PGID=0 + - TZ=Europe/London + - PASSWORD=${CODESERVER_PASSWORD} + - DEFAULT_WORKSPACE=/config/workspace + volumes: + - code-server_config:/config + - has_config:/mnt/has_config + - nginx_conf:/mnt/nginx_config + - mosquitto_config:/mnt/mosquitto_config + - hostfs_home_admin_repos:/mnt/hostfs_home_admin_repos + networks: + - code + - reverseproxy_public + ports: + - 8444:8443 + restart: unless-stopped +volumes: + code-server_config: + has_config: + name: has_app_config + external: true + nginx_conf: + name: reverseproxy_nginx-conf.d + external: true + mosquitto_config: + external: true + hostfs_home_admin_repos: + external: true +networks: + code: + reverseproxy_public: + external: true + + \ No newline at end of file diff --git a/docker/duplicati/docker-compose.yaml b/docker/duplicati/docker-compose.yaml new file mode 100644 index 0000000..4223e08 --- /dev/null +++ b/docker/duplicati/docker-compose.yaml @@ -0,0 +1,49 @@ +version: '3' +services: + duplicati: + image: duplicati/duplicati:latest + volumes: + - duplicati-data:/data + - codeserver-config:/bck/codeserver-config + - duplicati-data:/bck/duplicati-data + - has-config:/bck/has-config + - lms-config:/bck/lms-config + - lms-playlist:/bck/lms-config + - host-fs:/bck/host-fs + - mosquitto-config:/bck/mosquitto-config + - mosquitto-data:/bck/mosquitto-data + - portainer-data:/bck/portainer-data + - host-fs:/hostfs:ro + ports: + - 8200:8200 + restart: unless-stopped +volumes: + duplicati-data: + external: true + name: duplicati-data + codeserver-config: + name: code-server_code-server_config + external: true + has-config: + name: has_app_config + external: true + lms-config: + name: lms_config + external: true + lms-playlist: + name: lms_playlist + host-fs: + name: host_fs + external: true + mosquitto-config: + name: mosquitto_config + external: true + mosquitto-data: + name: mosquitto_data + external: true + portainer-data: + name: portainer_data + external: true + + + \ No newline at end of file diff --git a/docker/promtail/config/promtail-config.yaml b/docker/promtail/config/promtail-config.yaml new file mode 100644 index 0000000..dc2fb61 --- /dev/null +++ b/docker/promtail/config/promtail-config.yaml @@ -0,0 +1,49 @@ +server: + http_listen_port: 9080 + grpc_listen_port: 0 + +positions: + filename: /tmp/positions.yaml + +clients: + - url: http://lansrv01.dev.lan:3100/loki/api/v1/push + +scrape_configs: + - job_name: varlogs + static_configs: + - targets: + - localhost + labels: + job: varlogs + host: homesrv01 + __path__: /var/log/*log + - job_name: systemd-journal + journal: + json: true + max_age: 12h + path: /var/log/journal + # matches: _TRANSPORT=kernel + labels: + job: systemd-journal + host: homesrv01 + relabel_configs: + - source_labels: ['__journal__systemd_unit'] + target_label: 'journal_systemd_unit' + - source_labels: ['__journal_syslog_identifier'] + target_label: 'journal_syslog_identifier' + - source_labels: ['__journal__hostname'] + target_label: 'journal_hostname' + - job_name: docker + docker_sd_configs: + - host: unix:///var/run/docker.sock + refresh_interval: 1s + pipeline_stages: + - static_labels: + host: "homesrv01" + job: "docker" + relabel_configs: + - source_labels: ['__meta_docker_container_name'] + regex: '/(.*)' + target_label: "container_name" + - source_labels: ['__meta_docker_container_id'] + target_label: "container_id" \ No newline at end of file diff --git a/docker/promtail/docker-run.sh b/docker/promtail/docker-run.sh new file mode 100755 index 0000000..9ddcfb9 --- /dev/null +++ b/docker/promtail/docker-run.sh @@ -0,0 +1,15 @@ +#! /bin/bash +# must be executed from repo promtail root folder +docker container stop promtail +docker container remove promtail + +docker run -d \ +--name promtail \ +-v $(pwd)/config:/mnt/config \ +-v /var/log:/var/log \ +-v /var/log/journal/:/var/log/journal/ \ +-v /run/log/journal/:/run/log/journal/ \ +-v /etc/machine-id:/etc/machine-id \ +-v /var/run/docker.sock:/var/run/docker.sock \ +grafana/promtail:latest \ + -config.file=/mnt/config/promtail-config.yaml \ No newline at end of file diff --git a/docker/telegraf/config/telegraf.conf b/docker/telegraf/config/telegraf.conf new file mode 100644 index 0000000..20a3634 --- /dev/null +++ b/docker/telegraf/config/telegraf.conf @@ -0,0 +1,102 @@ + [global_tags] + # dc = "us-east-1" # will tag all metrics with dc=us-east-1 + # rack = "1a" + ## Environment variables can be used as tags, and throughout the config file + # user = "$USER" + + + + [agent] + hostname = "homesrv01" + omit_hostname = false + interval = "10s" + round_interval = true + metric_batch_size = 1000 + metric_buffer_limit = 10000 + collection_jitter = "0s" + flush_interval = "10s" + flush_jitter = "0s" + precision = "0s" + + + +# Output Configuration for telegraf agent +[[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://influxdb01.lan:8086"] + ## Token for authentication. + token = "V9iMrHJvI42_KcV0tcH5X3DcUEhvFQdnX5JqlBiKRsHEZMDDZQYdtxIuXlGzQTofUiLXc_QJN1pjpqnM6Fr1ow==" + ## Organization is the name of the organization you wish to write to; must exist. + organization = "limbo" + ## Destination bucket to write into. + bucket = "telegraf" + insecure_skip_verify = true + + + [[inputs.docker]] + endpoint = "unix:///var/run/docker.sock" + gather_services = false + container_names = [] + source_tag = false + container_name_include = [] + container_name_exclude = [] + timeout = "5s" + perdevice = true + total = false + docker_label_include = [] + docker_label_exclude = [] + tag_env = ["JAVA_HOME", "HEAP_SIZE"] + +# Read metrics about cpu usage +[[inputs.cpu]] + ## Whether to report per-cpu stats or not + percpu = true + ## Whether to report total system cpu stats or not + totalcpu = true + ## If true, collect raw CPU time metrics + collect_cpu_time = false + ## If true, compute and report the sum of all non-idle CPU states + report_active = false + + +# Read metrics about disk usage by mount point +[[inputs.disk]] + ## By default stats will be gathered for all mount points. + ## Set mount_points will restrict the stats to only the specified mount points. + # mount_points = ["/"] + + ## Ignore mount points by filesystem type. + ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"] + +[[inputs.diskio]] + +[[inputs.kernel]] + +[[inputs.mem]] + + # Get the number of processes and group them by status +[[inputs.processes]] + # no configuration + + +# Read metrics about swap memory usage +[[inputs.swap]] + # no configuration + + +# Read metrics about system load & uptime +[[inputs.system]] + # no configuration + + +# Read metrics about network interface usage +[[inputs.net]] + ## By default, telegraf gathers stats from any up interface (excluding loopback) + ## Setting interfaces will tell it to gather these explicit interfaces, + ## regardless of status. + ## + interfaces = ["eth0"] diff --git a/docker/telegraf/docker-run.sh b/docker/telegraf/docker-run.sh new file mode 100755 index 0000000..4c266c5 --- /dev/null +++ b/docker/telegraf/docker-run.sh @@ -0,0 +1,18 @@ +#! /bin/bash +# must be executed from repo/docker/telegraf +docker pull telegraf +docker container stop telegraf +docker container remove telegraf + + +docker run -d --name=telegraf \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v ./config/telegraf.conf:/etc/telegraf/telegraf.conf \ + -v /:/hostfs:ro \ + -e HOST_ETC=/hostfs/etc \ + -e HOST_PROC=/hostfs/proc \ + -e HOST_SYS=/hostfs/sys \ + -e HOST_VAR=/hostfs/var \ + -e HOST_RUN=/hostfs/run \ + -e HOST_MOUNT_PREFIX=/hostfs \ + telegraf \ No newline at end of file diff --git a/documentation/proxmox.md b/documentation/proxmox.md new file mode 100644 index 0000000..6353275 --- /dev/null +++ b/documentation/proxmox.md @@ -0,0 +1,20 @@ +# homesrv01.dev.lan + +- CT Container - Ubuntu ubuntu-22.10-standard_22.10-1_amd64.tar.zst + +## Params + +``` bash +# cat /etc/pve/lxc/105.conf +arch: amd64 +cores: 2 +features: fuse=1,keyctl=1,nesting=1 +hostname: homesrv01 +memory: 2000 +onboot: 1 +ostype: ubuntu +swap: 4000 +rootfs: local-lvm:vm-105-disk-0,size=32G +unprivileged: 1 + +`` diff --git a/lib/homeAssistant b/lib/homeAssistant new file mode 160000 index 0000000..10b5e7d --- /dev/null +++ b/lib/homeAssistant @@ -0,0 +1 @@ +Subproject commit 10b5e7d4a1e9bd9d5391789c8b250758289881e1 diff --git a/lib/lms b/lib/lms new file mode 160000 index 0000000..3341f92 --- /dev/null +++ b/lib/lms @@ -0,0 +1 @@ +Subproject commit 3341f92fcac1b974a949e0c6b54143e228d1be74 diff --git a/lib/mosquitto b/lib/mosquitto new file mode 160000 index 0000000..87ebdc5 --- /dev/null +++ b/lib/mosquitto @@ -0,0 +1 @@ +Subproject commit 87ebdc5dfb019c47463c3ca4212528965b55761d diff --git a/scripts/auto-update.sh b/scripts/auto-update.sh new file mode 100755 index 0000000..560af4c --- /dev/null +++ b/scripts/auto-update.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +doWork(){ + apt update -y + apt dist-upgrade -y + docker pull portainer/portainer-ce + docker stop portainer + docker rm portainer + docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer:/data portainer/portainer-ce + docker image prune -f +} + +doWork 2>&1 | systemd-cat -t "auto-update" +#example to check logs for autou-pdate +#journalctl --since yesterday -u cron.service | grep auto-update +exit 0 + + diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..812c163 --- /dev/null +++ b/setup.sh @@ -0,0 +1,15 @@ + + +docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer:/data portainer/portainer-ce +docker container list + + + + + +apt install sshfs + +#etc/fstab +#sshfs#media@nas.lan:/home/media /mnt/media@sshfs:nas.lan fuse defaults,_netdev,allow_other,follow_symlinks 0 0 + +docker volume create --driver local --opt type=none --opt device=/mnt/media@sshfs:nas.lan --opt o=bind musiccd music \ No newline at end of file