Compare commits
3 Commits
cd21cc76f4
...
815396776b
Author | SHA1 | Date |
---|---|---|
|
815396776b | |
|
bc68405581 | |
|
9d57539f66 |
15
mbadmin.jps
15
mbadmin.jps
|
@ -31,6 +31,8 @@ onInstall:
|
||||||
- if [ ! -f check_litespeed.php ]; then echo "Failed to download check_litespeed.php"; exit 1; fi
|
- if [ ! -f check_litespeed.php ]; then echo "Failed to download check_litespeed.php"; exit 1; fi
|
||||||
- curl -OL https://deploy.mightybox.io/tony/mb-admin/raw/branch/main/scripts/manage_litespeed.php
|
- curl -OL https://deploy.mightybox.io/tony/mb-admin/raw/branch/main/scripts/manage_litespeed.php
|
||||||
- if [ ! -f manage_litespeed.php ]; then echo "Failed to download manage_litespeed.php"; exit 1; fi
|
- if [ ! -f manage_litespeed.php ]; then echo "Failed to download manage_litespeed.php"; exit 1; fi
|
||||||
|
- curl -OL https://deploy.mightybox.io/tony/mb-admin/raw/branch/main/scripts/check_redis.php
|
||||||
|
- if [ ! -f check_redis.php ]; then echo "Failed to download check_redis.php"; exit 1; fi
|
||||||
- chmod +x *.php *.sh
|
- chmod +x *.php *.sh
|
||||||
# Download WordPress Installer with path verification
|
# Download WordPress Installer with path verification
|
||||||
- cd /home/litespeed/mbmanager
|
- cd /home/litespeed/mbmanager
|
||||||
|
@ -151,6 +153,11 @@ menu:
|
||||||
caption: Flush Keys
|
caption: Flush Keys
|
||||||
action: redis_clear_keys
|
action: redis_clear_keys
|
||||||
successText: "${response.out}"
|
successText: "${response.out}"
|
||||||
|
- confirmText: Get Redis metrics?
|
||||||
|
loadingText: Getting Redis metrics...
|
||||||
|
caption: Get Redis Metrics
|
||||||
|
action: redis_metrics
|
||||||
|
successText: "${response.out}"
|
||||||
- confirmText: Check OPcache status?
|
- confirmText: Check OPcache status?
|
||||||
loadingText: Checking OPcache status...
|
loadingText: Checking OPcache status...
|
||||||
caption: Check OPcache Status
|
caption: Check OPcache Status
|
||||||
|
@ -729,6 +736,14 @@ actions:
|
||||||
- return:
|
- return:
|
||||||
type: info
|
type: info
|
||||||
message: "${response.out}"
|
message: "${response.out}"
|
||||||
|
redis_metrics:
|
||||||
|
- cmd[cp]:
|
||||||
|
user: root
|
||||||
|
commands:
|
||||||
|
- php /home/litespeed/mbmanager/scripts/check_redis.php
|
||||||
|
- return:
|
||||||
|
type: info
|
||||||
|
message: "${response.out}"
|
||||||
db_import_preparation:
|
db_import_preparation:
|
||||||
- cmd[cp]:
|
- cmd[cp]:
|
||||||
user: root
|
user: root
|
||||||
|
|
|
@ -0,0 +1,202 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Redis Monitoring Script
|
||||||
|
* Returns comprehensive Redis metrics for Laravel panel
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Redis socket path (from existing scripts)
|
||||||
|
$redis_socket = '/var/run/redis/redis.sock';
|
||||||
|
|
||||||
|
function executeRedisCommand($socket, $command) {
|
||||||
|
$output = shell_exec("redis-cli -s $socket $command 2>/dev/null");
|
||||||
|
return trim($output);
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseRedisInfo($info_output) {
|
||||||
|
$data = [];
|
||||||
|
$lines = explode("\n", $info_output);
|
||||||
|
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
$line = trim($line);
|
||||||
|
if (empty($line) || strpos($line, '#') === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strpos($line, ':') !== false) {
|
||||||
|
list($key, $value) = explode(':', $line, 2);
|
||||||
|
$data[trim($key)] = trim($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculateHitRate($hits, $misses) {
|
||||||
|
$total = $hits + $misses;
|
||||||
|
if ($total == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return round(($hits / $total) * 100, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertBytesToMB($bytes) {
|
||||||
|
return round($bytes / 1024 / 1024, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertBytesToHuman($bytes) {
|
||||||
|
$units = ['B', 'KB', 'MB', 'GB'];
|
||||||
|
$bytes = max($bytes, 0);
|
||||||
|
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
|
||||||
|
$pow = min($pow, count($units) - 1);
|
||||||
|
|
||||||
|
$bytes /= (1 << (10 * $pow));
|
||||||
|
|
||||||
|
return round($bytes, 2) . ' ' . $units[$pow];
|
||||||
|
}
|
||||||
|
|
||||||
|
function measureLatency($socket) {
|
||||||
|
$start_time = microtime(true);
|
||||||
|
$result = executeRedisCommand($socket, 'PING');
|
||||||
|
$end_time = microtime(true);
|
||||||
|
|
||||||
|
if ($result === 'PONG') {
|
||||||
|
return round(($end_time - $start_time) * 1000, 2); // Convert to milliseconds
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Check if Redis is running
|
||||||
|
$ping_result = executeRedisCommand($redis_socket, 'PING');
|
||||||
|
|
||||||
|
if ($ping_result !== 'PONG') {
|
||||||
|
echo json_encode([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Redis is not responding',
|
||||||
|
'data' => [
|
||||||
|
'redis_status' => 'disconnected',
|
||||||
|
'memory_utilization' => [
|
||||||
|
'used_mb' => 0,
|
||||||
|
'max_mb' => 0,
|
||||||
|
'used_human' => '0 B',
|
||||||
|
'max_human' => '0 B',
|
||||||
|
'percentage' => 0,
|
||||||
|
'fragmentation_ratio' => 0
|
||||||
|
],
|
||||||
|
'hit_rate' => [
|
||||||
|
'hits' => 0,
|
||||||
|
'misses' => 0,
|
||||||
|
'percentage' => 0
|
||||||
|
],
|
||||||
|
'latency' => [
|
||||||
|
'avg_ms' => 0,
|
||||||
|
'status' => 'unavailable'
|
||||||
|
],
|
||||||
|
'server_info' => [
|
||||||
|
'version' => 'unknown',
|
||||||
|
'uptime_seconds' => 0,
|
||||||
|
'uptime_human' => '0 seconds'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
], JSON_PRETTY_PRINT);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Redis memory information
|
||||||
|
$memory_info = parseRedisInfo(executeRedisCommand($redis_socket, 'INFO memory'));
|
||||||
|
|
||||||
|
// Get Redis statistics
|
||||||
|
$stats_info = parseRedisInfo(executeRedisCommand($redis_socket, 'INFO stats'));
|
||||||
|
|
||||||
|
// Get Redis server information
|
||||||
|
$server_info = parseRedisInfo(executeRedisCommand($redis_socket, 'INFO server'));
|
||||||
|
|
||||||
|
// Measure latency
|
||||||
|
$latency_ms = measureLatency($redis_socket);
|
||||||
|
|
||||||
|
// Calculate memory utilization
|
||||||
|
$used_memory = isset($memory_info['used_memory']) ? (int)$memory_info['used_memory'] : 0;
|
||||||
|
$max_memory = isset($memory_info['maxmemory']) ? (int)$memory_info['maxmemory'] : 0;
|
||||||
|
$used_memory_human = isset($memory_info['used_memory_human']) ? $memory_info['used_memory_human'] : convertBytesToHuman($used_memory);
|
||||||
|
$max_memory_human = isset($memory_info['maxmemory_human']) ? $memory_info['maxmemory_human'] : convertBytesToHuman($max_memory);
|
||||||
|
|
||||||
|
$memory_percentage = 0;
|
||||||
|
if ($max_memory > 0) {
|
||||||
|
$memory_percentage = round(($used_memory / $max_memory) * 100, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate hit rate
|
||||||
|
$hits = isset($stats_info['keyspace_hits']) ? (int)$stats_info['keyspace_hits'] : 0;
|
||||||
|
$misses = isset($stats_info['keyspace_misses']) ? (int)$stats_info['keyspace_misses'] : 0;
|
||||||
|
$hit_rate_percentage = calculateHitRate($hits, $misses);
|
||||||
|
|
||||||
|
// Format uptime
|
||||||
|
$uptime_seconds = isset($server_info['uptime_in_seconds']) ? (int)$server_info['uptime_in_seconds'] : 0;
|
||||||
|
$uptime_human = '';
|
||||||
|
if ($uptime_seconds > 0) {
|
||||||
|
$days = floor($uptime_seconds / 86400);
|
||||||
|
$hours = floor(($uptime_seconds % 86400) / 3600);
|
||||||
|
$minutes = floor(($uptime_seconds % 3600) / 60);
|
||||||
|
$seconds = $uptime_seconds % 60;
|
||||||
|
|
||||||
|
if ($days > 0) {
|
||||||
|
$uptime_human = "{$days}d {$hours}h {$minutes}m";
|
||||||
|
} elseif ($hours > 0) {
|
||||||
|
$uptime_human = "{$hours}h {$minutes}m";
|
||||||
|
} elseif ($minutes > 0) {
|
||||||
|
$uptime_human = "{$minutes}m {$seconds}s";
|
||||||
|
} else {
|
||||||
|
$uptime_human = "{$seconds}s";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare response
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'data' => [
|
||||||
|
'redis_status' => 'connected',
|
||||||
|
'memory_utilization' => [
|
||||||
|
'used_mb' => convertBytesToMB($used_memory),
|
||||||
|
'max_mb' => convertBytesToMB($max_memory),
|
||||||
|
'used_human' => $used_memory_human,
|
||||||
|
'max_human' => $max_memory_human,
|
||||||
|
'percentage' => $memory_percentage,
|
||||||
|
'fragmentation_ratio' => isset($memory_info['mem_fragmentation_ratio']) ? (float)$memory_info['mem_fragmentation_ratio'] : 0
|
||||||
|
],
|
||||||
|
'hit_rate' => [
|
||||||
|
'hits' => $hits,
|
||||||
|
'misses' => $misses,
|
||||||
|
'percentage' => $hit_rate_percentage
|
||||||
|
],
|
||||||
|
'latency' => [
|
||||||
|
'avg_ms' => $latency_ms,
|
||||||
|
'status' => $latency_ms !== null ? 'available' : 'unavailable'
|
||||||
|
],
|
||||||
|
'server_info' => [
|
||||||
|
'version' => isset($server_info['redis_version']) ? $server_info['redis_version'] : 'unknown',
|
||||||
|
'uptime_seconds' => $uptime_seconds,
|
||||||
|
'uptime_human' => $uptime_human,
|
||||||
|
'total_connections' => isset($stats_info['total_connections_received']) ? (int)$stats_info['total_connections_received'] : 0,
|
||||||
|
'total_commands' => isset($stats_info['total_commands_processed']) ? (int)$stats_info['total_commands_processed'] : 0,
|
||||||
|
'ops_per_sec' => isset($stats_info['instantaneous_ops_per_sec']) ? (int)$stats_info['instantaneous_ops_per_sec'] : 0
|
||||||
|
],
|
||||||
|
'additional_metrics' => [
|
||||||
|
'evicted_keys' => isset($stats_info['evicted_keys']) ? (int)$stats_info['evicted_keys'] : 0,
|
||||||
|
'expired_keys' => isset($stats_info['expired_keys']) ? (int)$stats_info['expired_keys'] : 0,
|
||||||
|
'keyspace_misses_ratio' => $hits + $misses > 0 ? round(($misses / ($hits + $misses)) * 100, 2) : 0
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
echo json_encode($response, JSON_PRETTY_PRINT);
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo json_encode([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Failed to get Redis information: ' . $e->getMessage(),
|
||||||
|
'data' => null
|
||||||
|
], JSON_PRETTY_PRINT);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
?>
|
|
@ -607,6 +607,38 @@ if ! $SUDO_CMD $WP_EXECUTABLE core is-installed "${WP_RUN_ARGS[@]}"; then
|
||||||
# Use determined $SUDO_CMD, $WP_EXECUTABLE, and $WP_RUN_ARGS
|
# Use determined $SUDO_CMD, $WP_EXECUTABLE, and $WP_RUN_ARGS
|
||||||
$SUDO_CMD $WP_EXECUTABLE plugin delete akismet hello "${WP_RUN_ARGS[@]}" --quiet || warning "Could not delete default plugins (might not exist)."
|
$SUDO_CMD $WP_EXECUTABLE plugin delete akismet hello "${WP_RUN_ARGS[@]}" --quiet || warning "Could not delete default plugins (might not exist)."
|
||||||
|
|
||||||
|
# Install and activate LiteSpeed Cache plugin
|
||||||
|
info "Installing LiteSpeed Cache plugin..."
|
||||||
|
if $SUDO_CMD $WP_EXECUTABLE plugin install litespeed-cache "${WP_RUN_ARGS[@]}" --activate; then
|
||||||
|
success "LiteSpeed Cache plugin installed and activated successfully."
|
||||||
|
|
||||||
|
# Configure basic LiteSpeed Cache settings
|
||||||
|
info "Configuring basic LiteSpeed Cache settings..."
|
||||||
|
|
||||||
|
# Enable cache
|
||||||
|
$SUDO_CMD $WP_EXECUTABLE option update litespeed.conf.cache 1 "${WP_RUN_ARGS[@]}" || warning "Could not enable LiteSpeed cache"
|
||||||
|
|
||||||
|
# Set cache TTL to 1 week (604800 seconds)
|
||||||
|
$SUDO_CMD $WP_EXECUTABLE option update litespeed.conf.cache-ttl_pub 604800 "${WP_RUN_ARGS[@]}" || warning "Could not set public cache TTL"
|
||||||
|
|
||||||
|
# Enable CSS/JS optimization
|
||||||
|
$SUDO_CMD $WP_EXECUTABLE option update litespeed.conf.optm-css_min 1 "${WP_RUN_ARGS[@]}" || warning "Could not enable CSS minification"
|
||||||
|
$SUDO_CMD $WP_EXECUTABLE option update litespeed.conf.optm-js_min 1 "${WP_RUN_ARGS[@]}" || warning "Could not enable JS minification"
|
||||||
|
|
||||||
|
# Enable image optimization (WebP)
|
||||||
|
$SUDO_CMD $WP_EXECUTABLE option update litespeed.conf.media-webp 1 "${WP_RUN_ARGS[@]}" || warning "Could not enable WebP conversion"
|
||||||
|
|
||||||
|
# Enable lazy loading for images
|
||||||
|
$SUDO_CMD $WP_EXECUTABLE option update litespeed.conf.media-lazy 1 "${WP_RUN_ARGS[@]}" || warning "Could not enable lazy loading"
|
||||||
|
|
||||||
|
# Enable browser cache
|
||||||
|
$SUDO_CMD $WP_EXECUTABLE option update litespeed.conf.cache-browser 1 "${WP_RUN_ARGS[@]}" || warning "Could not enable browser cache"
|
||||||
|
|
||||||
|
success "LiteSpeed Cache basic configuration completed."
|
||||||
|
else
|
||||||
|
warning "Failed to install LiteSpeed Cache plugin. You can install it manually from the WordPress admin."
|
||||||
|
fi
|
||||||
|
|
||||||
# Ensure a default theme is activated (uses Twenty Twenty-Four or fallback to any available theme)
|
# Ensure a default theme is activated (uses Twenty Twenty-Four or fallback to any available theme)
|
||||||
info "Ensuring a default theme is activated..."
|
info "Ensuring a default theme is activated..."
|
||||||
if $SUDO_CMD $WP_EXECUTABLE theme is-installed twentytwentyfour "${WP_RUN_ARGS[@]}"; then
|
if $SUDO_CMD $WP_EXECUTABLE theme is-installed twentytwentyfour "${WP_RUN_ARGS[@]}"; then
|
||||||
|
@ -810,6 +842,13 @@ printf " Database Name: ${GREEN}%s${NC}\n" "$DB_NAME"
|
||||||
printf " Username: ${GREEN}%s${NC}\n" "$DB_USER"
|
printf " Username: ${GREEN}%s${NC}\n" "$DB_USER"
|
||||||
printf " Password: ${YELLOW}%s${NC} (Keep this safe!)\n" "$DB_PASSWORD"
|
printf " Password: ${YELLOW}%s${NC} (Keep this safe!)\n" "$DB_PASSWORD"
|
||||||
printf " Host: ${GREEN}%s${NC}\n" "$DB_HOST"
|
printf " Host: ${GREEN}%s${NC}\n" "$DB_HOST"
|
||||||
|
printf "\n"
|
||||||
|
printf "${YELLOW}LiteSpeed Cache Plugin:${NC}\n"
|
||||||
|
printf " Status: ${GREEN}Installed and Activated${NC}\n"
|
||||||
|
printf " Cache Enabled: ${GREEN}Yes${NC}\n"
|
||||||
|
printf " Cache TTL: ${GREEN}1 week (604800 seconds)${NC}\n"
|
||||||
|
printf " Optimizations: ${GREEN}CSS/JS minification, WebP, Lazy loading${NC}\n"
|
||||||
|
printf " Admin Panel: ${GREEN}https://%s/wp-admin/admin.php?page=litespeed${NC}\n" "$DOMAIN"
|
||||||
if [[ "$PERFORM_DB_ROOT_RESET" == "true" ]]; then
|
if [[ "$PERFORM_DB_ROOT_RESET" == "true" ]]; then
|
||||||
printf "\n${RED}IMPORTANT: The MySQL/MariaDB root password was reset during this process.${NC}\n"
|
printf "\n${RED}IMPORTANT: The MySQL/MariaDB root password was reset during this process.${NC}\n"
|
||||||
printf " New Root Pass: ${YELLOW}%s${NC} (Keep this safe!)\n" "$DB_ROOT_PASS"
|
printf " New Root Pass: ${YELLOW}%s${NC} (Keep this safe!)\n" "$DB_ROOT_PASS"
|
||||||
|
|
Loading…
Reference in New Issue