| 
									
										
										
										
											2021-05-14 01:21:18 +00:00
										 |  |  | #!/bin/bash
 | 
					
						
							| 
									
										
										
										
											2021-05-15 22:17:08 +00:00
										 |  |  | # System-tune-up to remove system software restrictions on a huge load of connections. | 
					
						
							|  |  |  | # Be aware that hardware/infrastructure resources are the most common limiters. | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2025-02-20 09:26:11 +00:00
										 |  |  | # SwITNet Ltd © - 2025, https://switnet.net/ | 
					
						
							| 
									
										
										
										
											2021-05-14 01:21:18 +00:00
										 |  |  | # GPLv3 or later. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | while getopts m: option | 
					
						
							|  |  |  | do | 
					
						
							|  |  |  | 	case "${option}" | 
					
						
							|  |  |  | 	in | 
					
						
							|  |  |  | 		m) MODE=${OPTARG};; | 
					
						
							| 
									
										
										
										
											2022-05-21 01:07:02 +00:00
										 |  |  | 		\?) echo "Usage: sudo bash ./$0 [-m debug]" && exit;; | 
					
						
							| 
									
										
										
										
											2021-05-14 01:21:18 +00:00
										 |  |  | 	esac | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-21 01:07:02 +00:00
										 |  |  | #DEBUG | 
					
						
							|  |  |  | if [ "$MODE" = "debug" ]; then | 
					
						
							|  |  |  | set -x | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #Check if user is root | 
					
						
							|  |  |  | if ! [ "$(id -u)" = 0 ]; then | 
					
						
							|  |  |  |    echo "You need to be root or have privileges!" | 
					
						
							|  |  |  |    exit 0 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-14 01:21:18 +00:00
										 |  |  | echo ' | 
					
						
							|  |  |  | #-------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2022-05-21 01:07:02 +00:00
										 |  |  | # Starting system tune up configuration | 
					
						
							| 
									
										
										
										
											2021-05-14 01:21:18 +00:00
										 |  |  | # for high performance | 
					
						
							|  |  |  | #-------------------------------------------------- | 
					
						
							|  |  |  | ' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-21 01:07:02 +00:00
										 |  |  | set_once_hash_comment() { | 
					
						
							|  |  |  | if ! awk '!/^ *#/ && NF {print}' "$2"|grep -q "$(awk -F '=' '{print$1}' <<< "$1")" ; then | 
					
						
							|  |  |  |   echo "Setting $1 on $2..." | 
					
						
							| 
									
										
										
										
											2021-05-14 01:21:18 +00:00
										 |  |  |   echo "$1" | tee -a "$2" | 
					
						
							|  |  |  | else | 
					
						
							| 
									
										
										
										
											2022-05-21 01:07:02 +00:00
										 |  |  |   echo "\"$(awk -F '=' '{print$1}' <<< "$1")\" seems already present, skipping setting this variable" | 
					
						
							| 
									
										
										
										
											2021-05-14 01:21:18 +00:00
										 |  |  | fi | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-05-16 21:15:59 +00:00
										 |  |  | FSTAB=/etc/fstab | 
					
						
							| 
									
										
										
										
											2021-05-14 01:21:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ##Disable swap | 
					
						
							|  |  |  | swapoff -a | 
					
						
							| 
									
										
										
										
											2022-05-21 01:07:02 +00:00
										 |  |  | sed -r  '/\sswap\s/s/^#?/#/' -i "$FSTAB" | 
					
						
							| 
									
										
										
										
											2021-05-14 01:21:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ##Alternative swap tuning (need more documentation). | 
					
						
							| 
									
										
										
										
											2021-05-15 22:17:08 +00:00
										 |  |  | #vm.swappiness=5 | 
					
						
							| 
									
										
										
										
											2021-05-14 01:21:18 +00:00
										 |  |  | #vm.vfs_cache_pressure=50 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ##Kernel | 
					
						
							|  |  |  | #https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/tuning_and_optimizing_red_hat_enterprise_linux_for_oracle_9i_and_10g_databases/sect-oracle_9i_and_10g_tuning_guide-adjusting_network_settings-changing_network_kernel_settings | 
					
						
							|  |  |  | sysctl -w net.core.rmem_default=262144 | 
					
						
							|  |  |  | sysctl -w net.core.wmem_default=262144 | 
					
						
							|  |  |  | sysctl -w net.core.rmem_max=262144 | 
					
						
							|  |  |  | sysctl -w net.core.wmem_max=262144 | 
					
						
							| 
									
										
										
										
											2022-05-21 01:07:02 +00:00
										 |  |  | set_once_hash_comment "net.core.rmem_default=262144" "/etc/sysctl.conf" | 
					
						
							|  |  |  | set_once_hash_comment "net.core.wmem_default=262144" "/etc/sysctl.conf" | 
					
						
							|  |  |  | set_once_hash_comment "net.core.rmem_max=262144" "/etc/sysctl.conf" | 
					
						
							|  |  |  | set_once_hash_comment "net.core.wmem_max=262144" "/etc/sysctl.conf" | 
					
						
							| 
									
										
										
										
											2021-05-14 01:21:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #system | 
					
						
							|  |  |  | #https://jitsi.github.io/handbook/docs/devops-guide/devops-guide-quickstart | 
					
						
							| 
									
										
										
										
											2022-05-21 01:07:02 +00:00
										 |  |  | set_once_hash_comment "DefaultLimitNOFILE=65000" "/etc/sysctl.conf" | 
					
						
							|  |  |  | set_once_hash_comment "DefaultLimitNPROC=65000" "/etc/sysctl.conf" | 
					
						
							|  |  |  | set_once_hash_comment "DefaultTasksMax=65000" "/etc/sysctl.conf" | 
					
						
							| 
									
										
										
										
											2021-05-14 01:21:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux_for_real_time/7/html/tuning_guide/reduce_tcp_performance_spikes | 
					
						
							|  |  |  | sysctl -w net.ipv4.tcp_timestamps=0 | 
					
						
							| 
									
										
										
										
											2022-05-21 01:07:02 +00:00
										 |  |  | set_once_hash_comment "net.ipv4.tcp_timestamps=0" "/etc/sysctl.conf" | 
					
						
							| 
									
										
										
										
											2021-05-14 01:21:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #https://bugzilla.redhat.com/show_bug.cgi?id=1283676 | 
					
						
							|  |  |  | sysctl -w net.core.netdev_max_backlog=100000 | 
					
						
							| 
									
										
										
										
											2022-05-21 01:07:02 +00:00
										 |  |  | set_once_hash_comment "net.core.netdev_max_backlog=100000" "/etc/sysctl.conf" | 
					
						
							| 
									
										
										
										
											2021-05-14 01:21:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ##nginx | 
					
						
							|  |  |  | sed -i "s|worker_connections.*|worker_connections 2000;|" /etc/nginx/nginx.conf | 
					
						
							|  |  |  | nginx -t | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #Missing docs | 
					
						
							|  |  |  | #sysctl -w net.ipv4.tcp_low_latency=1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | echo "System tune up...
 | 
					
						
							|  |  |  |   Done!"
 |