Table of contents
The purpose of writing this article is that I have a bad habit of hoarding servers. The number of servers is increasing, and there are always some repetitive steps when configuring each server. Here, I record them for future use.
(Recently, I am fond of the tool Ansible, but I haven’t learned it yet, so this tutorial is still useful)
Create a New User in Centos and Grant SUDO Privileges
|
|
Centos Firewall Configuration
Reference Link: https://go.opensl.life/gV4IY
Firewall Configuration
|
|
Open Ports The above instructions all open ports through the configuration file of the service. However, sometimes not all services come with configuration files. In this case, you have two options. You can open the specified port or define a new FirewallD service.
For example, the Plex server listens on port 32400 of the TCP protocol. You can use the –add-port= option to open port 32400 in the public area of the current session.
The protocol can be tcp or udp. To verify if port 32400 has been successfully added, use the –list-ports option to list the opened ports.
To keep port 32400 open after reboot, run the same command with the –permanent option to add the rule to the configuration file.
The syntax for deleting a port rule is the same as adding a port. Just use the –remove-port option.
|
|
Add Local User to Docker User Group
Reposted from: Add Users to Docker User Group - Use Docker without Root Privileges
The Docker daemon binds to a Unix socket, which causes Docker to require root privileges to be used. However, this is very troublesome as other users must frequently use sudo. For this reason, when the Docker daemon creates the Unix socket, it allows all members of the docker group to access. Therefore, we only need to add the user to the docker group to avoid using sudo.
- Create the docker group: sudo groupadd docker
- Add the user to the docker group: sudo usermod -aG docker $USER
- Log in again
Some Useful Self-Host Services
Configuration of Dockge and Uptime-Kuma
Reference Document: https://go.opensl.life/u8GXM
Previously, whenever I needed to start services, I would always tinker with container images. However, recently, I increasingly prefer using simple visual operations, and thus the application “dockge” has appeared on each of my servers.
This application can be deployed using containerization. The specific methods will not be detailed here. The main focus is on the problems that occurred when reverse proxying this application on my “qnap”. The main issue was that after configuring the reverse proxy on “npm”, there was always a 504 error. Later, when checking the background, “dockge” did not receive the request at all.
Key points are as follows:
- When configuring the reverse proxy for this application, remember to enable the websocket option.
- The second point is that npm needs to be bridged with dockge.
Docker Images
Due to certain reasons, we all know that recently, domestic mirrors of Docker Hub have been down. Currently, the solution of self-building mirrors is adopted.
The following repository provides some self-built complete sets of software, which can be referred to.
Reference Repository: https://go.opensl.life/bTHmv
When using servers from domestic service providers, it is also necessary to configure the docker-ce image. For CentOS, the following command can be used:
|
|
Reference Document: https://go.opensl.life/k2M6g
Skip Online Activation for WIN10 and WIN11
A few days ago, when installing the Windows virtual machine on the M-series MacBook, the system could not connect to the network during initialization no matter what. After checking, I found out that it was necessary to install vmware-tools after entering the system to be able to connect to the network. Conversely, the latest Windows system requires an online connection to be activated to enter the system. Thus, there is such a step.
When initializing the configuration or reinstalling the system for WIN10 and WIN11, during the normal installation progress, it will prompt to log in to the Microsoft account. It has to be said that this step is very unfriendly. So how can we skip the forced login to the Microsoft account to install the system? Follow these steps:
When starting the machine and seeing the installation screen, press Fn+Shift+F10 simultaneously to bring up the command prompt window, and enter OOBE\BYPASSNRO and press Enter (case insensitive);
Wait for the restart and then you can select “I don’t have an Internet connection” and “Continue with limited settings” to skip the online activation;
Set it as you like and you can see the Windows interface.
Garbage Cleanup for Small Servers
linux-trash-clean
> Reposted from: [Common Operations for Cleaning Disk Space in Linux](https://go.opensl.life/aDDEG)
The following methods can be used to clean up most of the garbage in Linux.
Clean Journal Logs
Generally, 2-3 GB can be cleaned.
- Check the hard disk space occupied by journal logs:
|
|
- Clean journal logs at once:
|
|
Note
These two operations only clear the logs once and cannot limit the size of future log files. Many blogs claim that these two operations can limit the size of log files, which is actually misleading.
If you need to permanently limit the size of log files, you need to modify the /etc/systemd/journald.conf
file.
- Permanently limit the size of journal logs:
journald.conf
[Journal] SystemMaxUse=10M # Only keep the most recent 10M of logs on the hard disk RuntimeMaxUse=10M # Only keep the most recent 10M of logs in memory
- Do not keep logs
journald.conf
[Journal] Storage=none # Discard all logs and do not save them to memory or disk
Danger
Do not use the rm
command to delete journal logs. Refer to
It is best not to use rm to delete logs to free up space
Clean apt-get Cache
Generally, several hundred MB can be cleaned.
apt-get clean
Clean pip Cache
Generally, two to three hundred MB can be cleaned.
rm -r ~/.cache/pip
Clean Old Version Snap Packages
Generally, each old snap package can clean 100 MB.
- List all snap packages:
snap list --all
You can see many snap packages marked asdisabled
, and these packages can be directly uninstalled.Name Version Rev Tracking Publisher Notes certbot 1.26.0 1952 latest/stable certbot-eff✓ classic cmake 3.23.0 1070 latest/stable crascit✓ disabled,classic cmake 3.23.1 1082 latest/stable crascit✓ classic core 16-2.55.2 12941 latest/stable canonical✓ core,disabled core 16-2.54.4 12834 latest/stable canonical✓ core core18 20220309 2344 latest/stable canonical✓ base core20 20220318 1405 latest/stable canonical✓ base
- Delete these duplicate snap packages:
snap remove XXXX --revision YYYY # XXXX is the name of the software, YYYY is the Rev of the software
- You can also use this script to clean:
From
How to Clean Up Snap Package Versions in Linux
#!/bin/bash # Removes old revisions of snaps # CLOSE ALL SNAPS BEFORE RUNNING THIS set -eu snap list --all | awk '/disabled/{print $1, $3}' | while read snapname revision; do snap remove "$snapname" --revision="$revision" done
Clean Login Logs
This file records the logs of incorrect logins. If someone tries your password every day to brute-force your SSH, then this file of yours will be very large.
echo "" > /var/log/btmp
The same applies to this file
echo "" > /var/log/auth.log
Similarly, instead of using rm
, use echo
to clear these two logs.
Clean Docker
- Check space usage
docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 5 1 645.4MB 611.9MB (94%) Containers 1 1 0B 0B Local Volumes 1 1 69.54kB 0B (0%) Build Cache 0 0 0B 0B
- Clean Build Cache
docker system prune --volumes
This will clear all:- Stopped Containers
- Networks not used by any Container
- Volumes not used by any Container
- Images without instances
- Build Cache without instances
- Clean Images
The previous step may not clean Images, so you can still see the space occupation of Images in
docker system df
. This step can clean these Images. View all Imagesdocker images -a
Clean the specified Imagedocker rmi <IMAGE ID>