184 lines
5.7 KiB
Bash
Executable File
184 lines
5.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
serverName="nginx"
|
|
serverPackages="nginx"
|
|
serverSourceUrl="https://nginx.org/packages/debian/"
|
|
phpVersion="7.3"
|
|
phpName="php${phpVersion}"
|
|
phpPackages="${phpName}-{fpm,gd,mysql,curl,xml,zip,intl,mbstring,bz2,ldap,apcu,bcmath,gmp,imagick,igbinary,redis,smbclient,cli,common,opcache,readline} imagemagick"
|
|
|
|
aptOpt=
|
|
step_config() {
|
|
if [ $QUIET -ne 0 ] ; then
|
|
aptOpt="-y"
|
|
fi
|
|
}
|
|
|
|
step_1_info() {
|
|
echoinfoArgs "[DEBIAN RELEASE]"
|
|
echo "Setup latest apt source list for $serverName"
|
|
echoinfo "$serverSourceUrl"
|
|
}
|
|
step_1_alias() { ALIAS="setup"; }
|
|
step_1() {
|
|
shift
|
|
local osRelease=$1
|
|
endCheckEmpty osRelease "Debian release not provided"
|
|
|
|
echoseq " [I] Setup apt source for $serverName $serverSourceUrl"
|
|
local srvSource="deb $serverSourceUrl $osRelease nginx"
|
|
addConf -s "$srvSource" "$serverSourceLoc"
|
|
if [ $? -eq 0 ] ; then
|
|
echoseq " [I] Get repository key for $serverSourceUrl"Y
|
|
exe apt install gnupg $aptOpt
|
|
exe apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABF5BD827BD9BF62
|
|
fi
|
|
}
|
|
serverSourceLoc="/etc/apt/sources.list.d/nginx.list"
|
|
|
|
step_2_info() {
|
|
echo "Installation of $serverName packages:"
|
|
echoinfo "$serverPackages"
|
|
}
|
|
step_2_alias() { ALIAS=install; }
|
|
step_2() {
|
|
exe apt update
|
|
exe apt install $serverPackages $aptOpt
|
|
endReturn -o $? "Failed to install $serverName"
|
|
}
|
|
|
|
step_3_info() { echo "Basic nginx configuration for initial letsencrypt certificate creation"; }
|
|
step_3() {
|
|
# Writing acme-challenge code snipped for certbot web root authentication
|
|
addConf -c "$snippetLetsencrypt" "$snippetLetsencryptLoc"
|
|
|
|
# Writing minimal default (see below)
|
|
addConf -c "$siteDefaultIp4" "$siteDefaultLoc"
|
|
|
|
# try fix errors on first install attempt
|
|
# (possible missing ipv6 support on system)
|
|
if [ $ERNO -ne 0 ] ; then
|
|
exe apt install nginx $aptOpt
|
|
fi
|
|
|
|
# create webroot
|
|
exe mkdir -p "$siteLetsencryptWww"
|
|
|
|
echoseq -n "Restarting Nginx..."
|
|
exe service nginx restart && echoseq "ok"
|
|
endReturn -o $? "Failed to install $serverName"
|
|
}
|
|
snippetLetsencryptLoc="/etc/nginx/snippets/letsencrypt.conf"
|
|
siteLetsencryptWww="/var/www/letsencrypt"
|
|
snippetLetsencrypt="\
|
|
location ^~ /.well-known/acme-challenge/ {
|
|
default_type \"text/plain\";
|
|
root ${siteLetsencryptWww};
|
|
}"
|
|
siteDefaultLoc="/etc/nginx/sites-available/default"
|
|
siteDefaultIp4="server {
|
|
listen 80 default_server;
|
|
|
|
include ${snippetLetsencryptLoc};
|
|
}"
|
|
|
|
step_4_info() {
|
|
echo "Installation of $phpName packages:"
|
|
echoinfo "$phpPackages"
|
|
}
|
|
step_4_alias() { ALIAS="php"; }
|
|
step_4() {
|
|
exe apt install $(eval echo $phpPackages) $aptOpt
|
|
}
|
|
|
|
phpFpmConfigLocation="/etc/php/${phpVersion}/fpm/conf.d/90-custom_pi.ini"
|
|
phpFpmConfig="memory_limit = 1024M
|
|
apc.enable_cli=1
|
|
output_buffering = Off
|
|
max_execution_time = 3600
|
|
max_input_time = 3600
|
|
post_max_size = 10240M
|
|
upload_max_filesize = 10240M
|
|
date.timezone = Europe/Berlin
|
|
session.cookie_secure = True
|
|
|
|
opcache.enable=1
|
|
opcache.enable_cli=1
|
|
opcache.memory_consumption=128
|
|
opcache.interned_strings_buffer=8
|
|
opcache.max_accelerated_files=10000
|
|
opcache.revalidate_freq=1
|
|
opcache.save_comments=1
|
|
|
|
allow_url_fopen = 1"
|
|
phpFpmConfigBu="register_argc_argv=on"
|
|
|
|
phpCliConfigLocation="/etc/php/${phpVersion}/cli/conf.d/90-custom_pi.ini"
|
|
phpCliConfig="\
|
|
apc.enable_cli=1
|
|
output_buffering = Off
|
|
max_execution_time = 3600
|
|
max_input_time = 3600
|
|
post_max_size = 10240M
|
|
upload_max_filesize = 10240M
|
|
date.timezone = Europe/Berlin"
|
|
phpPoolConfigLocation="/etc/php/${phpVersion}/fpm/pool.d/www.conf"
|
|
phpFpmIniLocation="/etc/php/${phpVersion}/fpm/php-fpm.conf"
|
|
|
|
step_5_info() { echo "Configuration of ${phpName} fpm and cli"; }
|
|
step_5() {
|
|
local AvailableRAM=$(awk '/MemAvailable/ {printf "%d", $2/1024}' /proc/meminfo)
|
|
local AverageFPM=$(ps --no-headers -o 'rss,cmd' -C php-fpm$phpVersion | awk '{ sum+=$1 } END { printf ("%d\n", sum/NR/1024,"M") }')
|
|
echo $AvailableRAM
|
|
echo $AverageFPM
|
|
local FPMS=$((AvailableRAM/AverageFPM))
|
|
local PMaxSS=$((FPMS*2/3))
|
|
local PMinSS=$((PMaxSS/2))
|
|
local PStartS=$(((PMaxSS+PMinSS)/2))
|
|
|
|
|
|
addConf -c "$phpFpmConfig" "$phpFpmConfigLocation"
|
|
addConf -c "$phpCliConfig" "$phpCliConfigLocation"
|
|
|
|
addConf -a "" "$phpFpmIniLocation"
|
|
exe sed -i "s|;emergency_restart_threshold.*|emergency_restart_threshold = 10|g" "$phpFpmIniLocation"
|
|
exe sed -i "s|;emergency_restart_interval.*|emergency_restart_interval = 1m|g" "$phpFpmIniLocation"
|
|
exe sed -i "s|;process_control_timeout.*|process_control_timeout = 10|g" "$phpFpmIniLocation"
|
|
|
|
addConf -a "" "$phpPoolConfigLocation"
|
|
exe sed -i "s/;env\[HOSTNAME\] = /env[HOSTNAME] = /" "$phpPoolConfigLocation"
|
|
exe sed -i "s/;env\[TMP\] = /env[TMP] = /" "$phpPoolConfigLocation"
|
|
exe sed -i "s/;env\[TMPDIR\] = /env[TMPDIR] = /" "$phpPoolConfigLocation"
|
|
exe sed -i "s/;env\[TEMP\] = /env[TEMP] = /" "$phpPoolConfigLocation"
|
|
exe sed -i "s/;env\[PATH\] = /env[PATH] = /" "$phpPoolConfigLocation"
|
|
exe sed -i 's/pm.max_children =.*/pm.max_children = '$FPMS'/' "$phpPoolConfigLocation"
|
|
exe sed -i 's/pm.start_servers =.*/pm.start_servers = '$PStartS'/' "$phpPoolConfigLocation"
|
|
exe sed -i 's/pm.min_spare_servers =.*/pm.min_spare_servers = '$PMinSS'/' "$phpPoolConfigLocation"
|
|
exe sed -i 's/pm.max_spare_servers =.*/pm.max_spare_servers = '$PMaxSS'/' "$phpPoolConfigLocation"
|
|
exe sed -i "s/;pm.max_requests =.*/pm.max_requests = 1000/" "$phpPoolConfigLocation"
|
|
|
|
echoseq -n "Restarting ${phpName} ... "
|
|
exe service ${phpName}-fpm restart && echoseq "ok"
|
|
}
|
|
|
|
step_6_info() { echo "Installation notes"; }
|
|
step_6_alias() { ALIAS="notes"; }
|
|
step_6() {
|
|
cat <<NOTES_EOF
|
|
# Set user to www-data on debian an tune performance a bit
|
|
[/etc/nginx/nginx.conf]
|
|
user www-data;
|
|
worker_processes 1;
|
|
|
|
events {
|
|
worker_connections 1024;
|
|
multi_accept on;
|
|
use epoll;
|
|
}
|
|
|
|
NOTES_EOF
|
|
}
|
|
|
|
VERSION_SEQREV=14
|
|
. /usr/local/bin/sequencer.sh
|