From cba3bf64822378c45d737b9af22cf4b653a67d58 Mon Sep 17 00:00:00 2001 From: hhftechnologies Date: Wed, 27 Nov 2024 14:21:31 +0530 Subject: [PATCH] update --- optimize/optimize-server.sh | 167 ++++++++++++++++++------------------ 1 file changed, 84 insertions(+), 83 deletions(-) diff --git a/optimize/optimize-server.sh b/optimize/optimize-server.sh index dd77a7b..ba9f0bc 100644 --- a/optimize/optimize-server.sh +++ b/optimize/optimize-server.sh @@ -4,20 +4,21 @@ # VARIABLES # #-----------------------------------# -this_script_url="https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/maintenance/optimize-server.sh" -this_script_name="Server Optimization Script Nginx MariaDB" +this_script_url="https://example.com/optimize-server.sh" +this_script_name="Server Optimization Script" formatter_url="https://git.hhf.technology/hhf/TaskFormatter/raw/branch/main/bash_task_formatter/task_formatter.sh" scriptname=$0 -# Initialize success flag -success=0 +# Configuration URLs +NGINX_CONF_URL="https://git.hhf.technology/hhf/script-management-cloudpanel/src/branch/main/optimize/nginx.conf" +MARIADB_CONF_URL="https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/optimize/100-cloudpanel.cnf" -# Paths +# Configuration paths NGINX_CONF="/etc/nginx/nginx.conf" MARIADB_CONF="/etc/mysql/mariadb.conf.d/100-cloudpanel.cnf" -# System memory in GB -TOTAL_MEM_GB=$(free -g | awk '/^Mem:/{print $2}') +# Initialize success flag +success=0 #-----------------------------------# # FORMATTER # @@ -95,92 +96,87 @@ check_mariadb() { #-----------------------------------# optimize_nginx() { - # Backup original config - cp "$NGINX_CONF" "${NGINX_CONF}.backup" - - # Calculate worker_processes based on CPU cores - local cpu_cores=$(nproc) + # Create backup + cp "$NGINX_CONF" "${NGINX_CONF}.backup.$(date +%Y%m%d_%H%M%S)" - # Update nginx.conf - sed -i "s/worker_processes.*/worker_processes $cpu_cores;/" "$NGINX_CONF" - sed -i "s/worker_connections.*/worker_connections 65535;/" "$NGINX_CONF" - - # Update buffer sizes - sed -i "s/client_body_buffer_size.*/client_body_buffer_size 16k;/" "$NGINX_CONF" - sed -i "s/client_max_body_size.*/client_max_body_size 100M;/" "$NGINX_CONF" - - # Update timeouts - sed -i "s/keepalive_timeout.*/keepalive_timeout 65;/" "$NGINX_CONF" - sed -i "s/client_body_timeout.*/client_body_timeout 15;/" "$NGINX_CONF" - - # Enable GZIP and Brotli - sed -i "s/gzip.*/gzip on;/" "$NGINX_CONF" - sed -i "s/brotli.*/brotli on;/" "$NGINX_CONF" - - # Test configuration - if ! nginx -t; then - echo "Error: Invalid Nginx configuration" - mv "${NGINX_CONF}.backup" "$NGINX_CONF" + # Download new configuration + if ! wget --no-check-certificate "$NGINX_CONF_URL" -O "$NGINX_CONF.new"; then + echo "Error: Failed to download Nginx configuration" return 1 fi + # Verify the downloaded configuration + if ! nginx -t -c "$NGINX_CONF.new"; then + echo "Error: Invalid Nginx configuration" + rm "$NGINX_CONF.new" + return 1 + fi + + # Replace the configuration + mv "$NGINX_CONF.new" "$NGINX_CONF" + return 0 } optimize_mariadb() { - # Backup original config - cp "$MARIADB_CONF" "${MARIADB_CONF}.backup" + # Create backup + cp "$MARIADB_CONF" "${MARIADB_CONF}.backup.$(date +%Y%m%d_%H%M%S)" - # Calculate buffer pool size (70% of total memory) - local innodb_buffer_pool_size=$((TOTAL_MEM_GB * 70 / 100)) + # Download new configuration + if ! wget --no-check-certificate "$MARIADB_CONF_URL" -O "$MARIADB_CONF.new"; then + echo "Error: Failed to download MariaDB configuration" + return 1 + } - # Update MariaDB configuration - cat > "$MARIADB_CONF" <