|
| 1 | +# Proxmox |
| 2 | + |
| 3 | +<https://www.proxmox.com/en/> |
| 4 | + |
| 5 | +**If it's the very first install, remember to enable the intel virtualization technology and disable secure boot in the BIOS.** |
| 6 | +<https://rog.asus.com/us/support/FAQ/1043786> |
| 7 | +<https://techzillo.com/how-to-disable-or-enable-secure-boot-for-asus-motherboard/> |
| 8 | + |
| 9 | +## Graphical installation |
| 10 | + |
| 11 | +Follow the classic graphical installation process. |
| 12 | +For the first filesystem related step, select the disk dedicated to the OS and use `ext4` as the filesystem *(for `pmx02`, set hdsize to 75 GiB)*. |
| 13 | + |
| 14 | +## Setup Proxmox community repositories and update the system |
| 15 | + |
| 16 | +```bash |
| 17 | +sed -i '1s/^/# /' /etc/apt/sources.list.d/ceph.list /etc/apt/sources.list.d/pve-enterprise.list |
| 18 | +echo "deb http://download.proxmox.com/debian $(grep CODENAME /etc/os-release | cut -f2 -d'=') pve-no-subscription" > /etc/apt/sources.list.d/pve-no-subscription.list |
| 19 | +apt update |
| 20 | +``` |
| 21 | + |
| 22 | +## Create and configure my user |
| 23 | + |
| 24 | +```bash |
| 25 | +useradd -s /bin/bash -m -u 1001 antiz |
| 26 | +passwd antiz |
| 27 | +apt install sudo |
| 28 | +usermod -aG sudo antiz |
| 29 | +su - antiz |
| 30 | +``` |
| 31 | + |
| 32 | +### Download my dotfiles |
| 33 | + |
| 34 | +```bash |
| 35 | +curl https://raw.githubusercontent.com/Antiz96/Linux-Server/main/Dotfiles/Bashrc/Debian-Ubuntu-Server -o ~/.bashrc |
| 36 | +curl https://raw.githubusercontent.com/Antiz96/Linux-Server/main/Dotfiles/General/vimrc -o ~/.vimrc |
| 37 | +mkdir -p ~/.vim/colors && curl https://raw.githubusercontent.com/vv9k/vim-github-dark/master/colors/ghdark.vim -o ~/.vim/colors/ghdark.vim |
| 38 | +source ~/.bashrc |
| 39 | +``` |
| 40 | + |
| 41 | +## Update the server and install useful packages |
| 42 | + |
| 43 | +```bash |
| 44 | +sudo apt update && sudo apt full-upgrade && sudo apt autoremove |
| 45 | +sudo apt install vim man bash-completion openssh-server dnsutils traceroute rsync zip unzip diffutils firewalld plocate htop curl openssl telnet chrony wget logrotate fail2ban python3-passlib fastfetch |
| 46 | +sudo systemctl enable --now ssh chrony firewalld logrotate.timer fstrim.timer |
| 47 | +sudo reboot |
| 48 | +``` |
| 49 | + |
| 50 | +## Setup additional DNS servers (if needed) |
| 51 | + |
| 52 | +```bash |
| 53 | +sudo vim /etc/network/interfaces |
| 54 | +``` |
| 55 | + |
| 56 | +> [...] |
| 57 | +> auto enp3s0 |
| 58 | +> iface enp3s0 inet manual |
| 59 | +> > **dns-nameservers 192.168.1.1 192.168.1.2** |
| 60 | +> [...] |
| 61 | +
|
| 62 | +```bash |
| 63 | +echo "nameserver 192.168.1.2" | sudo tee -a /etc/resolv.conf |
| 64 | +sudo systemctl restart networking |
| 65 | +``` |
| 66 | + |
| 67 | +## Setup secure SSH connection |
| 68 | + |
| 69 | +### Change the default SSH port |
| 70 | + |
| 71 | +```bash |
| 72 | +sudo vim /etc/ssh/sshd_config |
| 73 | +``` |
| 74 | + |
| 75 | +> [...] |
| 76 | +> Port **"X"** *# Where "X" is the port you want to set* |
| 77 | +> [...] |
| 78 | +
|
| 79 | +### Disable ssh connection for the root account |
| 80 | + |
| 81 | +```bash |
| 82 | +sudo vim /etc/ssh/sshd_config |
| 83 | +``` |
| 84 | + |
| 85 | +> [...] |
| 86 | +> PermitRootLogin no |
| 87 | +> [...] |
| 88 | +
|
| 89 | +### Restrict SSH connection method to public key authentication |
| 90 | + |
| 91 | +```bash |
| 92 | +sudo vim /etc/ssh/sshd_config |
| 93 | +``` |
| 94 | + |
| 95 | +> [...] |
| 96 | +> PasswordAuthentication no |
| 97 | +> AuthenticationMethods publickey |
| 98 | +
|
| 99 | +### Open the SSH port on the firewall |
| 100 | + |
| 101 | +```bash |
| 102 | +sudo firewall-cmd --add-port=X/tcp --permanent # Open the port we've set for SSH (replace "X" by the port) |
| 103 | +sudo firewall-cmd --remove-service="ssh" --permanent # Close the default SSH port |
| 104 | +sudo firewall-cmd --remove-service="dhcpv6-client" --permanent # Close the dhcpv6-client port as I don't use it |
| 105 | +sudo firewall-cmd --reload |
| 106 | +``` |
| 107 | + |
| 108 | +### Restart the SSH service to apply changes |
| 109 | + |
| 110 | +```bash |
| 111 | +sudo systemctl restart sshd |
| 112 | +``` |
| 113 | + |
| 114 | +## Configure and start fail2ban |
| 115 | + |
| 116 | +Procedure: <https://github.com/Antiz96/Linux-Server/blob/main/Services/Fail2Ban.md> |
| 117 | + |
| 118 | +## Enable Wake On Lan |
| 119 | + |
| 120 | +<https://www.asus.com/support/FAQ/1045950/> |
| 121 | +<https://wiki.debian.org/WakeOnLan> |
| 122 | + |
| 123 | +### Enable Wake On Lan in the BIOS |
| 124 | + |
| 125 | +- pmx01: |
| 126 | + |
| 127 | +DEL Key at startup to go to the BIOS |
| 128 | +Advanced --> APM Configuration --> Power On By PCI-E --> Enabled |
| 129 | + |
| 130 | +- pmx02: |
| 131 | + |
| 132 | +No related option in BIOS, it seems activated by default. |
| 133 | + |
| 134 | +### Enable Wake On Lan support in the OS |
| 135 | + |
| 136 | +```bash |
| 137 | +sudo apt install ethtool |
| 138 | +sudo ethtool -s enp3s0 wol g # Adapt network card name if needed |
| 139 | +sudo vim /etc/network/interfaces |
| 140 | +``` |
| 141 | + |
| 142 | +> [...] |
| 143 | +> auto enp3s0 |
| 144 | +> iface enp3s0 inet manual |
| 145 | +> > **post-up ethtool -s enp3s0 wol g** # Adapt network card name if needed |
| 146 | +> > **post-down ethtool -s enp3s0 wol g** # Adapt network card name if needed |
| 147 | +> |
| 148 | +> [...] |
| 149 | +
|
| 150 | +Verify with: |
| 151 | + |
| 152 | +```bash |
| 153 | +sudo ethtool enp3s0 # Adapt network card name if needed |
| 154 | + |
| 155 | +``` |
| 156 | + |
| 157 | +> [...] |
| 158 | +> Wake-on: **g** # "g" means it is enabled |
| 159 | +> [...] |
| 160 | +
|
| 161 | +## Configure the inactivity timeout |
| 162 | + |
| 163 | +```bash |
| 164 | +sudo vim /etc/bash.bashrc # Set the inactivity timeout to 15 min |
| 165 | +``` |
| 166 | + |
| 167 | +> [...] |
| 168 | +> #Set inactivity timeout |
| 169 | +> TMOUT=900 |
| 170 | +> readonly TMOUT |
| 171 | +> export TMOUT |
| 172 | +
|
| 173 | +## Create and configure the ansible user |
| 174 | + |
| 175 | +```bash |
| 176 | +sudo useradd -s /bin/bash -m -u 1000 ansible # Create the ansible user |
| 177 | +sudo vim /etc/sudoers.d/ansible # Make the ansible user a sudoer |
| 178 | +``` |
| 179 | + |
| 180 | +> ansible ALL=(ALL) NOPASSWD: ALL |
| 181 | +
|
| 182 | +```bash |
| 183 | +sudo mkdir -p /home/ansible/.ssh && sudo chmod 700 /home/ansible/.ssh && sudo chown ansible: /home/ansible/.ssh |
| 184 | +sudo touch /home/ansible/.ssh/authorized_keys && sudo chmod 600 /home/ansible/.ssh/authorized_keys && sudo chown ansible: /home/ansible/.ssh/authorized_keys |
| 185 | +sudo vim /home/ansible/.ssh/authorized_keys |
| 186 | +``` |
| 187 | + |
| 188 | +> Copy the ansible master server's SSH public key here (ansible@ansible-server) |
| 189 | +
|
| 190 | +## Install and configure Zabbix Agent |
| 191 | + |
| 192 | +```bash |
| 193 | +sudo firewall-cmd --add-port=10050/tcp --permanent |
| 194 | +sudo firewall-cmd --reload |
| 195 | +sudo apt install zabbix-agent |
| 196 | +sudo vim /etc/zabbix/zabbix_agentd.conf |
| 197 | +``` |
| 198 | + |
| 199 | +> [...] |
| 200 | +> Server=hostname_of_zabbix_server |
| 201 | +> [...] |
| 202 | +> ServerActive=hostname_of_zabbix_server |
| 203 | +> [...] |
| 204 | +> Hostname=pmx01.rc # Adapt the hostname if needed |
| 205 | +> [...] |
| 206 | +> TLSPSKIdentity=XXXX # Should be filled in according to the "Deploying a New Server" procedure |
| 207 | +> [...] |
| 208 | +> TLSPSKFile=/etc/zabbix/.psk |
| 209 | +> [...] |
| 210 | +> UserParameter=fail2ban_status,systemctl is-active fail2ban |
| 211 | +> UserParameter=fail2ban_num,sudo /etc/zabbix/scripts/fail2ban_num.sh |
| 212 | +> UserParameter=pve-cluster_status,systemctl is-active pve-cluster |
| 213 | +> UserParameter=pvedaemon_status,systemctl is-active pvedaemon |
| 214 | +> UserParameter=pveproxy_status,systemctl is-active pveproxy |
| 215 | +> [...] |
| 216 | +> TLSConnect=psk |
| 217 | +> [...] |
| 218 | +> TLSAccept=psk |
| 219 | +
|
| 220 | +```bash |
| 221 | +sudo mkdir /etc/zabbix/scripts |
| 222 | +sudo vim /etc/zabbix/scripts/fail2ban_num.sh |
| 223 | +``` |
| 224 | + |
| 225 | +```bash |
| 226 | +#!/bin/bash |
| 227 | + |
| 228 | +jails_list=$(fail2ban-client status | grep -w "Jail list:" | cut -f2 | sed s/,//g) |
| 229 | + |
| 230 | +for i in ${jails_list} ; do ban_number=$(( ban_number + $(fail2ban-client status "${i}" | grep -w "Currently banned:" | cut -f2) )) ; done |
| 231 | + |
| 232 | +echo "${ban_number}" |
| 233 | +``` |
| 234 | + |
| 235 | +```bash |
| 236 | +sudo chmod +x /etc/zabbix/scripts/fail2ban_num.sh |
| 237 | +sudo vim /etc/sudoers.d/zabbix |
| 238 | +``` |
| 239 | + |
| 240 | +> zabbix ALL=(ALL) NOPASSWD:/etc/zabbix/scripts/fail2ban_num.sh |
| 241 | +
|
| 242 | +```bash |
| 243 | +sudo systemctl enable --now zabbix-agent |
| 244 | +``` |
| 245 | + |
| 246 | +## Configure Proxmox |
| 247 | + |
| 248 | +### Open the port used by Proxmox (and its component) on the firewall |
| 249 | + |
| 250 | +I only open the port for proxmox service's that I use. |
| 251 | +For a full list of port use by the different proxmox services, refer to this link: <https://pve.proxmox.com/wiki/Firewall> |
| 252 | + |
| 253 | +```bash |
| 254 | +sudo firewall-cmd --zone=public --add-port=8006/tcp --permanent # Web Interface port |
| 255 | +sudo firewall-cmd --zone=public --add-port=3128/tcp --permanent # Spice proxy port |
| 256 | +sudo firewall-cmd --reload |
| 257 | +``` |
| 258 | + |
| 259 | +### Create the cluster |
| 260 | + |
| 261 | +- From the **main** node WebUI (login with the system's `root` credentials): |
| 262 | + |
| 263 | +"Datacenter" --> "Cluster" --> "Create Cluster" (give it a name, select the network interface, then click "Create"). |
| 264 | + |
| 265 | +- From the **secondary** node(s) WebUI: |
| 266 | + |
| 267 | +"Datacenter" --> "Cluster" --> "Join Cluster" (copy / paster the join information from the main node, enter the root password of the main node, select the network interface, then click "Join Cluster"). |
| 268 | + |
| 269 | +#### Setup the ssh connection between the nodes |
| 270 | + |
| 271 | +Allow ssh connection for the `root` user using key authentication (Proxmox uses ssh with the `root` user of each node for some specific components such as the vncproxy used to access the console of VMs from another node): |
| 272 | + |
| 273 | +```bash |
| 274 | +sudoedit /etc/ssh/sshd_config |
| 275 | +``` |
| 276 | + |
| 277 | +> [...] |
| 278 | +> PermitRootLogin prohibit-password |
| 279 | +> [...] |
| 280 | +
|
| 281 | +```bash |
| 282 | +sudo systemctl restart sshd |
| 283 | +``` |
| 284 | + |
| 285 | +In case you don't use the default `22` port for ssh: |
| 286 | + |
| 287 | +```bash |
| 288 | +sudoedit /root/.ssh/config |
| 289 | +``` |
| 290 | + |
| 291 | +> [...] |
| 292 | +> Host "IP_of_node_2" |
| 293 | +> > Port "Port_number" |
| 294 | +
|
| 295 | +Then copy the public key of each nodes to the `/root/.ssh/authorized_keys` files (a key pair is automatically created for the `root` during Proxmox's installation). |
| 296 | +Do this between every nodes so they can all connect to each other via `ssh` on the `root` account. |
| 297 | + |
| 298 | +### Setup ZFS pool (for VMs disks) |
| 299 | + |
| 300 | +We're going to create a ZFS pool for VMs disks (allowing to replicate them between the cluster nodes for *semi* HA). |
| 301 | + |
| 302 | +- From **all** nodes: |
| 303 | + |
| 304 | +```bash |
| 305 | +sudo fdisk /dev/nvme0n1 # Create a partition on the dedicated disk with all the free space as Linux filesystem |
| 306 | +``` |
| 307 | + |
| 308 | +- From the **main** node: |
| 309 | + |
| 310 | +From the WebUI (<https://[HOSTNAME]:8006/>): |
| 311 | + |
| 312 | +"*Node name*" --> "Disks" --> "ZFS" --> "Create: ZFS" (give it a name, check the "Add storage" checkbox, select the partition, leave the rest at default unless you wanna do some RAID, then click "Create"). |
| 313 | + |
| 314 | +Then (required for free space discard support): |
| 315 | + |
| 316 | +"Datacenter" --> "Storage" --> "*ZFS Pool name*" --> "Edit" (check the "Thin provision" checkbox, then click "OK"). |
| 317 | + |
| 318 | +- From the **secondary** node(s): |
| 319 | + |
| 320 | +From the WebUI (<https://[HOSTNAME]:8006/>): |
| 321 | + |
| 322 | +"*Node name*" --> "Disks" --> "ZFS" --> "Create: ZFS" (put the **same** name as the ZFS pool created on the main node, **uncheck** the "Add storage" checkbox, select the partition, leave the rest at default unless you wanna do some RAID, then click "Create"). |
| 323 | + |
| 324 | +### Setup ZFS replication and HA (for VMs disks) |
| 325 | + |
| 326 | +To setup ZFS replication for VMs, from the WebUI: |
| 327 | + |
| 328 | +"*VM_Name*" --> "Replication" --> "Add" (select the target node for the replication, the schedule, then click "Create"). |
| 329 | + |
| 330 | +This allows to copy VMs Disks to other nodes, allowing to start a VM from the different nodes of the cluster. |
| 331 | +This can be used to setup a *semi* HA (High Availability) where a VM will automatically start from a different node if a node goes down (it's a *semi* HA because the replication is asynchronous, so you will still loose the data written since the last replication). |
| 332 | + |
| 333 | +To setup HA, from the WebUI: |
| 334 | + |
| 335 | +"Datacenter" --> "HA" --> "Add" (select the VM to add to HA, then click "Add"). |
| 336 | + |
| 337 | +### Create Backup / ISO storage |
| 338 | + |
| 339 | +```bash |
| 340 | +sudo fdisk /dev/nvme0n2 # Create a partition on the dedicated disk will all the free space as Linux filesystem |
| 341 | +``` |
| 342 | + |
| 343 | +```bash |
| 344 | +sudo mkfs.ext4 /dev/nvme0n2p1 # Format it as ext4 (or whatever other FS you prefer) |
| 345 | +sudo mkdir -p /data/proxmox/{backup,iso} # Create mount point and data directories |
| 346 | +sudo vim /etc/fstab # Add it to the fstab |
| 347 | +``` |
| 348 | + |
| 349 | +> [...] |
| 350 | +> #Data |
| 351 | +> UUID=ff3414a7-c564-427c-868f-9a72edccd87d /data ext4 defaults 0 2 |
| 352 | +
|
| 353 | +```bash |
| 354 | +sudo mount -a # Mount it |
| 355 | +sudo systemctl daemon-reload # Reload systemd |
| 356 | +``` |
| 357 | + |
| 358 | +Then, from the WebUI (<https://[HOSTNAME]:8006/>): |
| 359 | + |
| 360 | +"Datacenter" --> "Storage" --> "Add" --> "Directory" (give it a name / ID, enter the directory path, select the content and the node, then click "Add"). |
| 361 | + |
| 362 | +This should be done for both the `/data/proxmox/backup` directory (content: "VZDump backup file") and the `/data/proxmox/iso` directory (content: "ISO image") on all the nodes of the future cluster. |
| 363 | + |
| 364 | +### Setup backup jobs |
| 365 | + |
| 366 | +To create automatic backup jobs for VMs, from the WebUI: |
| 367 | + |
| 368 | +"Datacenter" --> "Backup" --> "Add" (select the node, backup storage, schedule, VMs to backup, etc..., then click "Create"). |
| 369 | + |
| 370 | +### Create a dedicated admin user (and disable the default root pam user access) |
| 371 | + |
| 372 | +From the WebUI (<https://[HOSTNAME]:8006/>): |
| 373 | + |
| 374 | +"Datacenter" --> "Permissions" --> "Users" --> "Add" (fill in all information, Realm: "PVE authentication server", then click "Add"). |
| 375 | + |
| 376 | +Then: |
| 377 | + |
| 378 | +"Datacenter" --> "Permissions" --> "Add" --> "User Permission" (Path: "/", User: "username@pve", Role: "PVEAdmin", then click "Add"). |
| 379 | + |
| 380 | +Logout from `root` and login with your user, then: |
| 381 | + |
| 382 | +"Datacenter" --> "Permissions" --> "Users" --> "root" --> "Edit" (uncheck the "enabled" checkbox, then click "OK"). |
0 commit comments