domingo, 10 de julho de 2022

Gather metrics of your Proxmox server with Prometheus

0 comentários

 Fonte: Hetzner Online Community


Introduction

With the help of a specific exporter, which queries the Proxmox API in the background, an existing Prometheus (and Grafana) stack can scrape data about your Proxmox environment.

At the end of this tutorial, we will be able to gather metrics about CPU, RAM, disk and network resources, as well of guests (CTs or VMs) via Prometheus. With a Grafana dashboard you can view these metrics.

Prerequisites

This tutorial does not cover the installation of Proxmox and Prometheus itself. See this tutorial for installing the Prometheus stack and this tutorial for Proxmox installation.

This tutorial has been tested on Debian 10 and 11.

  • Hetzner bare-metal server
  • functional Proxmox installation
  • functional Prometheus stack
  • Running SSH session as root

The exporter itself can be started on the Proxmox node itself or on another machine. For this tutorial we assume the exporter will run on the Proxmox node.

Step 1 - Create Proxmox read-only API user

We will create a dedicated Proxmox user because anonymous data collection is not permitted. This user will have read-only permissions.

Log in to your proxmox host and ensure you´re working as root

$ pveum user add pve-exporter@pve -comment "PVE-Exporter" -password <secure passphrase or password>
$ pveum aclmod / -user pve-exporter@pve -role PVEAuditor

Step 2 - Create linux user

For running the exporter as daemon / systemd unit we create a dedicated user.

$ useradd -c "pve exporter" -m -s /bin/false pve-exporter

Step 3 - Install package and python dependencies

The pve exporter is written in Python and we will install it within a so called venv (virtual environment). The use of such a venv makes python dependency handling much easier compared to regular installation with pip.

There are a few debian packages needed to ensure a proper installation process of the venv itself and the pve exporter.

$ apt-get update && apt-get install python3-venv python3-setuptools python3-dev python3-pip libffi-dev libssl-dev build-essential -y

Step 4 - Create and activate venv, install prometheus-pve-exporter

We will create the mentioned venv and install the package prometheus-pve-exporter from PyPi

$ python3 -m venv /opt/prometheus-pve-exporter
$ source /opt/prometheus-pve-exporter/bin/activate

Check if (prometheus-pve-exporter) is present in front of your command line prompt before executing the next command.

(prometheus-pve-exporter) $ pip install prometheus-pve-exporter

On Debian 10 an error message (Failed to build proxmoxer) may be displayed. This is not an issue, simply verify everything has been installed by executing the command again. It should finish in very short time and all lines should begin with "Requirement already satisfied".

Finally leave the venv by executing deactivate

(prometheus-pve-exporter) $ deactivate
$ 

Step 5 - Configure prometheus-pve-exporter

Place the previously created credentials for Proxmox user pve-exporter in a .yml file.

$ mkdir -p /etc/prometheus
$ cat <<EOF > /etc/prometheus/pve.yml
default:
    user: pve-exporter@pve
    password: <secure passphrase or password>
    # only needed when you not configured Lets Encrypt 
    # verify_ssl: false
EOF
$ chown root.pve-exporter /etc/prometheus/pve.yml
$ chmod 640 /etc/prometheus/pve.yml

Step 6 - Configure systemd unit for prometheus-pve-exporter

Place service unit to /etc/systemd/system.

$ cat <<EOF> /etc/systemd/system/prometheus-pve-exporter.service
[Unit]
Description=Prometheus exporter for Proxmox VE
Documentation=https://github.com/znerol/prometheus-pve-exporter

[Service]
Restart=always
User=pve-exporter
ExecStart=/opt/prometheus-pve-exporter/bin/pve_exporter /etc/prometheus/pve.yml

[Install]
WantedBy=multi-user.target
EOF

Reload SystemD, start and enable the service.

$ systemctl daemon-reload 
$ systemctl start prometheus-pve-exporter.service
$ systemctl enable prometheus-pve-exporter.service

Verify the tcp port 9221 (which is the default) is open:

$ ss -lntp | grep 9221
LISTEN 0      128          0.0.0.0:9221      0.0.0.0:*    users:(("pve_exporter",pid=7539,fd=3))

In some configurations it is necessary to note the IP address in front of :9221. You will need it in the next step. Normally pve-exporter binds to 0.0.0.0 which means that you can reach the exporter over every interface.

Step 7 - Test functionality

Access the endpoint which provide the metrics via cURL.

$ curl -s localhost:9221/pve

Check output of cURL command, at the end there should be a line like this

...
# HELP pve_version_info Proxmox VE version info
# TYPE pve_version_info gauge
pve_version_info{release="6.4",repoid="9f411e79",version="6.4-13"} 1.0

Step 8 - Extend your Prometheus configuration

Extend the scrape_config area in your existing Prometheus configuration with the following lines:

your-prometheus-host $ vim /etc/prometheus/prometheus.yml

  - job_name: 'pve-exporter'
    static_configs:
      - targets:
        - your-proxmox-host:9221
    metrics_path: /pve
    params:
      module: [default]

your-prometheus-host $ systemctl restart prometheus

Step 9 - Import the corresponding Grafana dashboard

Log in to your Grafana instance, navigate to Dashboards, press the import button, insert the ID 10347 and click load.

You can find the dashboard here: https://grafana.com/grafana/dashboards/10347

Conclusion

Screenshot of Grafana dashboard

With the great prometheus-pve-exporter we have a simple and powerful tool which allows us to see which guests on the proxmox node take how much resources. Besides it provides general overview of proxmox host system health (Storage usage, Space allocation, ...).

Continue reading →
sábado, 9 de abril de 2022

https://sempreupdate.com.br/como-instalar-configurar-o-samba-no-ubuntu-linux-mint-debian-e-derivados/

0 comentários

Como instalar configurar o Samba no Ubuntu, Linux Mint, Debian e derivados! - SempreUpdate


 Antes de mais nada, vamos fazer um back-up do arquivo:

Terminal
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bkp

Particularmente gosto do VI para editar os arquivos .conf, mas use um editor de sua preferência. Caso queira aprender a usar o editor, temos um guia onde orientamo a como usar o vi/vim no Linux.

Para quem quiser usar o VI, execute o comando para editá-lo:

Terminal
sudo vi /etc/samba/smb.conf

Comentarei somente os parâmetros do arquivo smb.conf que precisaram ser alterados.

[global]
#nome do grupo de trabalho
workgroup = casa
#Como a máquina Linux irá aparecer na rede Windows
netbios name = servidor (está linha pode ser adicionada a baixo do workgroup)
####### Authentication #######
#Modo de acesso aos arquivos do Linux
security = “share” ou “user” (caso exista, remova o ; que está no início desta linha)
#share = para NÃO exigir autenticação
#user = para exigir autenticação
ex: security = user

Agora adicione estas linhas no final do arquivo:

#nome do compartilhamento
[arquivos]
# descrição do compartilhamento
comment = meus arquivos
# caminho da pasta, no Linux, que será compartilhada
path = /media/hdb5 #(Informe o caminho da pasta que você que quer compartilhar, pode ser /home/voce)
#se todos os compartilhamentos poderão ser acessados por todos os usuários
public = yes
# se o compartilhamento será visivel ou oculto na rede (yes para visível)
browseable = yes
# se permitirá escrita
writable = yes
# somente leitura
read only = no
# define a mascara em que os arquivos serão criados
create mask = 0700 #(terão a permissão rwx somente para o root)
# define a mascara em que os diretórios serão criados
directory mask = 0700

Salvando a configuração do Samba e reiniciando o serviço

Salve o arquivo de configuração, e execute este comando para reiniciar o samba:

Terminal
sudo systemctl restart smbd

Para sistemas mais antigos:

Terminal
sudo /etc/init.d/samba restart

Samba com Security User

Caso tenha colocado security = user, no momento que for acessar por uma máquina Windows será exibido uma tela de login e senha. Para cadastrar esta senha no linux execute os seguintes comandos.

Primeiramente adiciona na lista de usuários do Linux. Este comando adiciona usuário teste na lista de usuários do Linux:

Terminal
sudo adduser teste

Este comando adiciona o usuário na lista de usuários do Samba:

Terminal
sudo smbpasswd -a teste

Com esta configuração do Samba no Ubuntu, não tem erro!

Continue reading →

How to Install Latest qBittorrent on Ubuntu 20.04 Desktop and Server

0 comentários

 How to Install Latest qBittorrent on Ubuntu 20.04 Desktop and Server - LinuxCapable


qBittorrent can be installed on a headless Ubuntu server and easily managed on a WebUI interface accessed from your favorite Internet Browser.

First, add the PPA and update as your repositories:

sudo add-apt-repository ppa:qbittorrent-team/qbittorrent-stable -y && sudo apt update

Next, you will now install the qBittorrent client (qbittorent-nox) instead of (qbittorent ) with the following command:

sudo apt install qbittorrent-nox

qBittorrent-nox is the default go-to for headless clients designed to run through a Web interface accessible on the default localhost location at http://localhost:8080. The Web UI access is secured by default, and the default account username is (admin), and the password is (adminadmin).

Unlike the desktop version, using the terminal command (qbittorrent-nox) would not be advised as a headless server; you won’t be able to do anything while qBittorrent is running, which isn’t practical. Instead, you will create a systemd service unit to run in the background and start at system boot.

First, create (qbittorrent-nox) user and group so the service can run as an unprivileged user.

sudo adduser --system --group qbittorrent-nox

Note, if you were wondering what (–system) means, you created a system user instead of a normal user.

Next, add your username to the qbittorrent-nox user group:

sudo adduser your-username qbittorrent-nox

Second, create a systemd service file for qbittorrent-nox:

sudo nano /etc/systemd/system/qbittorrent-nox.service

Thirdly, you need to copy and paste the following lines into the file.

[Unit]
Description=qBittorrent Command Line Client
After=network.target

[Service]
#Do not change to "simple"
Type=forking
User=qbittorrent-nox
Group=qbittorrent-nox
UMask=007
ExecStart=/usr/bin/qbittorrent-nox -d --webui-port=8080
Restart=on-failure

[Install]
WantedBy=multi-user.target

Save the file (CTRL+O), then exit (CTRL+X). Now, reload your systemd daemon for changes to be active:

sudo systemctl daemon-reload

Now you can start qBittorrent-nox with the following command.

sudo systemctl start qbittorrent-nox

If you want qBittorrent-nox to be started on boot, use the following:

sudo systemctl enable qbittorrent-nox

Before you continue, it would be ideal for checking the status to make sure everything is working correctly:

systemctl status qbittorrent-nox

If no errors and status in the green, proceed to the next part of the tutorial.

Continue reading →