Aapanel ansible
This script is the installation and configuration engine for aaPanel (a popular web hosting control panel). It is a complex Bash script designed to handle environment preparation, dependency management, Python virtual environments, and security settings across multiple Linux distributions.
Here is a breakdown of what the script does, organized by its functional logic:
1. System Environment Detection (Get_Versions)¶
The script first identifies your operating system to determine which package manager to use (yum for CentOS/AlmaLinux/Rocky/Amazon Linux or apt-get for Ubuntu/Debian). It specifically checks for versions like Ubuntu 22.04 (Jammy) and 24.04 (Noble) to ensure compatibility with software repositories.
2. Dependency & Repository Management¶
-
Repository Optimization (
Check_Change_official_sources): If it detects that the system's package sources are broken or cannot be reached, it offers to reset them to official Ubuntu/Debian mirrors. -
System Package Installation (
Check_Install_Sys_Packs): It ensures essential command-line tools likeunzip,tar, andwgetare installed before proceeding. If they are missing, it attempts to install them or warns the user if the system's package manager is broken.
3. Python Environment Setup (The "Heart" of aaPanel)¶
aaPanel relies heavily on a specific Python environment to run its web interface and background tasks.
-
OpenSSL Management (
Install_Openssl111): Many modern Python libraries require OpenSSL 1.1.1+. If the system is running an older OS (like CentOS 7), the script compiles and installs OpenSSL 1.1.1 manually to ensure Python'ssslmodule works correctly. -
Python 3.12 Installation (
Install_Python_Lib): It downloads, compiles, and sets up a dedicated Python 3.12 environment in/www/server/panel/pyenv. This prevents conflicts with the system's default Python version. -
Library Management (
Check_PIP_Packages&Update_Py_Lib): It usespipto install a massive list of required libraries (likeFlask,Werkzeug,psutil, etc.) specifically for the panel's operation.
4. Panel Installation and Configuration¶
-
Binary Download (
Install_Bt&Panel_web_server): It downloads the compiled aaPanel web server binary and the main control panel files, verifies their integrity (via SHA256 hashes), and extracts them to/www/server/panel. -
Database Initialization: It sets up default databases and configuration files.
-
Security & User Setup (
Set_Bt_Panel): -
It creates a dedicated
wwwuser for security. -
It generates a random login username and password.
-
It configures the panel's access path (a unique URL suffix to prevent brute-force attacks).
5. Networking & Security¶
-
Firewall Configuration (
Set_Firewall): It automatically opens necessary ports for SSH (22), HTTP (80), HTTPS (443), FTP (21/20), and the specific aaPanel port to allow you to access the interface. -
SSL/TLS Setup (
Use_self_signed_certificate&Start_Ip_Cert_Async): It can automatically generate a self-signed certificate for immediate HTTPS use or attempt to fetch a free Let's Encrypt SSL certificate via an asynchronous background process.
6. Finalization¶
Once the installation is complete, it:
-
Restarts the
bt(aaPanel) service. -
Displays your Login URL, Username, and Password in a large, formatted block.
-
Provides a warning to open ports in your cloud provider's security group (like AWS/Aliyun/Google Cloud).
Summary of Key Paths Created:¶
-
/www/server/panel: The core application files. -
/www/server/panel/pyenv: The isolated Python environment. -
/etc/init.d/bt: The service script to start/stop the panel. -
/www/server/panel/data/default.db: The SQLite database containing panel settings.