#!/usr/bin/env bash Set_Timezone() { Echo_Blue "Setting timezone..." rm -rf /etc/localtime ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime } CentOS_InstallNTP() { if echo "${CentOS_Version}" | grep -Eqi "^8" || echo "${RHEL_Version}" | grep -Eqi "^8" || echo "${Oracle_Version}" | grep -Eqi "^8"; then Echo_Blue "[+] Installing chrony..." dnf install chrony -y chronyd -q "server pool.ntp.org iburst" else Echo_Blue "[+] Installing ntp..." yum install -y ntpdate ntpdate -u pool.ntp.org fi date start_time=$(date +%s) } Deb_InstallNTP() { apt-get update -y Echo_Blue "[+] Installing ntp..." apt-get install -y ntpdate ntpdate -u pool.ntp.org date start_time=$(date +%s) } CentOS_RemoveAMP() { Echo_Blue "[-] Yum remove packages..." rpm -qa|grep httpd rpm -e httpd httpd-tools --nodeps if [[ "${DBSelect}" != "0" ]]; then yum -y remove mysql-server mysql mysql-libs mariadb-server mariadb mariadb-libs rpm -qa|grep mysql if [ $? -ne 0 ]; then rpm -e mysql mysql-libs --nodeps rpm -e mariadb mariadb-libs --nodeps fi fi rpm -qa|grep php rpm -e php-mysql php-cli php-gd php-common php --nodeps Remove_Error_Libcurl yum -y remove httpd* yum -y remove php* yum clean all } Deb_RemoveAMP() { Echo_Blue "[-] apt-get remove packages..." apt-get update -y for removepackages in apache2 apache2-doc apache2-utils apache2.2-common apache2.2-bin apache2-mpm-prefork apache2-doc apache2-mpm-worker php5 php5-common php5-cgi php5-cli php5-mysql php5-curl php5-gd; do apt-get purge -y $removepackages; done if [[ "${DBSelect}" != "0" ]]; then if echo "${Ubuntu_Version}" | grep -Eqi "^20\.04"; then dpkg -l |grep mysql dpkg --force-all -P mysql-server dpkg --force-all -P mariadb-client mariadb-server mariadb-common libmariadbd-dev [[ -d "/etc/mysql" ]] && rm -rf /etc/mysql for removepackages in mysql-server mariadb-server; do apt-get purge -y $removepackages; done else dpkg -l |grep mysql dpkg --force-all -P mysql-server mysql-common libmysqlclient15off libmysqlclient15-dev libmysqlclient18 libmysqlclient18-dev libmysqlclient20 libmysqlclient-dev libmysqlclient21 dpkg --force-all -P mariadb-client mariadb-server mariadb-common libmariadbd-dev for removepackages in mysql-client mysql-server mysql-common mysql-server-core-5.5 mysql-client-5.5 mariadb-client mariadb-server mariadb-common; do apt-get purge -y $removepackages; done fi fi killall apache2 dpkg -l |grep apache dpkg -P apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2.2-common dpkg -l |grep php dpkg -P php5 php5-common php5-cli php5-cgi php5-mysql php5-curl php5-gd apt-get autoremove -y && apt-get clean } Disable_Selinux() { if [ -s /etc/selinux/config ]; then sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config fi } Xen_Hwcap_Setting() { if [ -s /etc/ld.so.conf.d/libc6-xen.conf ]; then sed -i 's/hwcap 1 nosegneg/hwcap 0 nosegneg/g' /etc/ld.so.conf.d/libc6-xen.conf fi } Check_Hosts() { if grep -Eqi '^127.0.0.1[[:space:]]*localhost' /etc/hosts; then echo "Hosts: ok." else echo "127.0.0.1 localhost.localdomain localhost" >> /etc/hosts fi pingresult=`ping -c1 lnmp.org 2>&1` echo "${pingresult}" if echo "${pingresult}" | grep -q "unknown host"; then echo "DNS...fail" echo "Writing nameserver to /etc/resolv.conf ..." echo -e "nameserver 208.67.220.220\nnameserver 114.114.114.114" > /etc/resolv.conf else echo "DNS...ok" fi } RHEL_Modify_Source() { Get_RHEL_Version if [ "${RHELRepo}" = "local" ]; then echo "DO NOT change RHEL repository, use the repository you set." else echo "RHEL ${RHEL_Ver} will use aliyun centos repository..." if [ ! -s "/etc/yum.repos.d/Centos-${RHEL_Ver}.repo" ]; then wget --prefer-family=IPv4 http://mirrors.aliyun.com/repo/Centos-${RHEL_Ver}.repo -O /etc/yum.repos.d/Centos-${RHEL_Ver}.repo fi if echo "${RHEL_Version}" | grep -Eqi "^6"; then sed -i "s#centos/\$releasever#centos-vault/\$releasever#g" /etc/yum.repos.d/Centos-${RHEL_Ver}.repo sed -i "s/\$releasever/${RHEL_Version}/g" /etc/yum.repos.d/Centos-${RHEL_Ver}.repo else sed -i "s/\$releasever/${RHEL_Ver}/g" /etc/yum.repos.d/Centos-${RHEL_Ver}.repo fi yum clean all yum makecache fi sed -i "s/^enabled[ ]*=[ ]*1/enabled=0/" /etc/yum/pluginconf.d/subscription-manager.conf } Ubuntu_Modify_Source() { if [ "${country}" = "CN" ]; then OldReleasesURL='http://mirrors.ustc.edu.cn/ubuntu-old-releases/ubuntu/' else OldReleasesURL='http://old-releases.ubuntu.com/ubuntu/' fi CodeName='' if grep -Eqi "10.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^10.10'; then CodeName='maverick' elif grep -Eqi "11.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^11.04'; then CodeName='natty' elif grep -Eqi "11.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^11.10'; then CodeName='oneiric' elif grep -Eqi "12.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^12.10'; then CodeName='quantal' elif grep -Eqi "13.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^13.04'; then CodeName='raring' elif grep -Eqi "13.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^13.10'; then CodeName='saucy' elif grep -Eqi "10.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^10.04'; then CodeName='lucid' elif grep -Eqi "14.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^14.10'; then CodeName='utopic' elif grep -Eqi "15.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^15.04'; then CodeName='vivid' elif grep -Eqi "12.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^12.04'; then CodeName='precise' elif grep -Eqi "15.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^15.10'; then CodeName='wily' elif grep -Eqi "16.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^16.10'; then CodeName='yakkety' elif grep -Eqi "14.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^14.04'; then Ubuntu_Deadline trusty elif grep -Eqi "17.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^17.04'; then CodeName='zesty' elif grep -Eqi "17.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^17.10'; then CodeName='artful' elif grep -Eqi "16.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^16.04'; then Ubuntu_Deadline xenial elif grep -Eqi "18.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^18.10'; then CodeName='cosmic' elif grep -Eqi "19.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^19.04'; then CodeName='disco' elif grep -Eqi "19.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^19.10'; then Ubuntu_Deadline eoan elif grep -Eqi "20.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^20.10'; then Ubuntu_Deadline groovy fi if [ "${CodeName}" != "" ]; then \cp /etc/apt/sources.list /etc/apt/sources.list.$(date +"%Y%m%d") cat > /etc/apt/sources.list<&1 | awk '/^ HTTP/{print $2}'` if [ "${OR_Status}" = "200" ]; then echo "Ubuntu old-releases status: ${OR_Status}"; CodeName="$1" fi } Ubuntu_Deadline() { trusty_deadline=`date -d "2022-4-30 00:00:00" +%s` xenial_deadline=`date -d "2024-4-30 00:00:00" +%s` eoan_deadline=`date -d "2020-7-30 00:00:00" +%s` groovy_deadline=`date -d "2021-7-30 00:00:00" +%s` cur_time=`date +%s` case "$1" in trusty) if [ ${cur_time} -gt ${trusty_deadline} ]; then echo "${cur_time} > ${trusty_deadline}" Check_Old_Releases_URL trusty fi ;; xenial) if [ ${cur_time} -gt ${xenial_deadline} ]; then echo "${cur_time} > ${xenial_deadline}" Check_Old_Releases_URL xenial fi ;; eoan) if [ ${cur_time} -gt ${eoan_deadline} ]; then echo "${cur_time} > ${eoan_deadline}" Check_Old_Releases_URL eoan fi ;; groovy) if [ ${cur_time} -gt ${groovy_deadline} ]; then echo "${cur_time} > ${groovy_deadline}" Check_Old_Releases_URL groovy fi ;; esac } CentOS6_Modify_Source() { if echo "${CentOS_Version}" | grep -Eqi "^6"; then Echo_Yellow "CentOS 6 is now end of life, use vault repository." \cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup \cp ${cur_dir}/conf/CentOS6-Base-Vault.repo /etc/yum.repos.d/CentOS-Base.repo fi } Check_PowerTools() { if ! yum -v repolist all|grep "PowerTools"; then echo "PowerTools repository not found, add PowerTools repository ..." cat >/etc/yum.repos.d/CentOS-PowerTools.repo< /etc/ld.so.conf.d/freetype.conf</dev/null 2>&1 || pcre-config --version | grep -vEqi '^8.'; then Echo_Blue "[+] Installing ${Pcre_Ver}" cd ${cur_dir}/src Download_Files ${Download_Mirror}/web/pcre/${Pcre_Ver}.tar.bz2 ${Pcre_Ver}.tar.bz2 Tarj_Cd ${Pcre_Ver}.tar.bz2 Nginx_With_Pcre="--with-pcre=${cur_dir}/src/${Pcre_Ver}" fi } Install_Jemalloc() { Echo_Blue "[+] Installing ${Jemalloc_Ver}" cd ${cur_dir}/src Tarj_Cd ${Jemalloc_Ver}.tar.bz2 ${Jemalloc_Ver} ./configure Make_Install ldconfig cd ${cur_dir}/src/ rm -rf ${cur_dir}/src/${Jemalloc_Ver} ln -sf /usr/local/lib/libjemalloc* /usr/lib/ } Install_TCMalloc() { Echo_Blue "[+] Installing ${TCMalloc_Ver}" if [ "${Is_64bit}" = "y" ]; then Tar_Cd ${Libunwind_Ver}.tar.gz ${Libunwind_Ver} CFLAGS=-fPIC ./configure make CFLAGS=-fPIC make CFLAGS=-fPIC install rm -rf ${cur_dir}/src/${Libunwind_Ver} fi Tar_Cd ${TCMalloc_Ver}.tar.gz ${TCMalloc_Ver} if [ "${Is_64bit}" = "y" ]; then ./configure else ./configure --enable-frame-pointers fi Make_Install ldconfig cd ${cur_dir}/src/ rm -rf ${cur_dir}/src/${TCMalloc_Ver} ln -sf /usr/local/lib/libtcmalloc* /usr/lib/ } Install_Icu4c() { if command -v icu-config >/dev/null 2>&1 && icu-config --version | grep -Eq "^3."; then Echo_Blue "[+] Installing ${Libicu4c_Ver}" cd ${cur_dir}/src Download_Files ${Download_Mirror}/lib/icu4c/${Libicu4c_Ver}-src.tgz ${Libicu4c_Ver}-src.tgz Tar_Cd ${Libicu4c_Ver}-src.tgz icu/source ./configure --prefix=/usr if [ ! -s /usr/include/xlocale.h ]; then ln -s /usr/include/locale.h /usr/include/xlocale.h fi Make_Install cd ${cur_dir}/src/ rm -rf ${cur_dir}/src/icu fi } Download_Boost() { Echo_Blue "[+] Download or use exist boost..." if [ "${DBSelect}" = "4" ] || echo "${mysql_version}" | grep -Eqi '^5.7.'; then if [ -s "${cur_dir}/src/${Boost_Ver}.tar.bz2" ]; then [[ -d "${cur_dir}/src/${Boost_Ver}" ]] && rm -rf "${cur_dir}/src/${Boost_Ver}" tar jxf ${cur_dir}/src/${Boost_Ver}.tar.bz2 -C ${cur_dir}/src MySQL_WITH_BOOST="-DWITH_BOOST=${cur_dir}/src/${Boost_Ver}" else cd ${cur_dir}/src/ Download_Files ${Download_Mirror}/lib/boost/${Boost_Ver}.tar.bz2 ${Boost_Ver}.tar.bz2 tar jxf ${cur_dir}/src/${Boost_Ver}.tar.bz2 cd - MySQL_WITH_BOOST="-DWITH_BOOST=${cur_dir}/src/${Boost_Ver}" fi elif [ "${DBSelect}" = "5" ] || echo "${mysql_version}" | grep -Eqi '^8.0.'; then Get_Boost_Ver=$(grep 'SET(BOOST_PACKAGE_NAME' cmake/boost.cmake |grep -oP '\d+(\_\d+){2}') if [ -s "${cur_dir}/src/boost_${Get_Boost_Ver}.tar.bz2" ]; then [[ -d "${cur_dir}/src/boost_${Get_Boost_Ver}" ]] && rm -rf "${cur_dir}/src/boost_${Get_Boost_Ver}" tar jxf ${cur_dir}/src/boost_${Get_Boost_Ver}.tar.bz2 -C ${cur_dir}/src MySQL_WITH_BOOST="-DWITH_BOOST=${cur_dir}/src/boost_${Get_Boost_Ver}" else MySQL_WITH_BOOST="-DDOWNLOAD_BOOST=1 -DWITH_BOOST=${cur_dir}/src" fi fi } Install_Boost() { Echo_Blue "[+] Download or use exist boost..." if [ "${DBSelect}" = "4" ] || [ "${DBSelect}" = "5" ]; then if [ -d "${cur_dir}/src/${Mysql_Ver}/boost" ]; then MySQL_WITH_BOOST="-DWITH_BOOST=${cur_dir}/src/${Mysql_Ver}/boost" else Download_Boost fi elif echo "${mysql_version}" | grep -Eqi '^5.7.' || echo "${mysql_version}" | grep -Eqi '^8.0.'; then if [ -d "${cur_dir}/src/mysql-${mysql_version}/boost" ]; then MySQL_WITH_BOOST="-DWITH_BOOST=${cur_dir}/src/mysql-${mysql_version}/boost" else Download_Boost fi fi } Install_Openssl() { if [ ! -s /usr/local/openssl/bin/openssl ] || /usr/local/openssl/bin/openssl version | grep -v 'OpenSSL 1.0.2'; then Echo_Blue "[+] Installing ${Openssl_Ver}" cd ${cur_dir}/src Download_Files ${Download_Mirror}/lib/openssl/${Openssl_Ver}.tar.gz ${Openssl_Ver}.tar.gz [[ -d "${Openssl_Ver}" ]] && rm -rf ${Openssl_Ver} Tar_Cd ${Openssl_Ver}.tar.gz ${Openssl_Ver} ./config -fPIC --prefix=/usr/local/openssl --openssldir=/usr/local/openssl make depend Make_Install cd ${cur_dir}/src/ rm -rf ${cur_dir}/src/${Openssl_Ver} fi } Install_Openssl_New() { if openssl version | grep -vEqi "OpenSSL 1.1.1*"; then if [ ! -s /usr/local/openssl1.1.1/bin/openssl ] || /usr/local/openssl1.1.1/bin/openssl version | grep -Eqi 'OpenSSL 1.1.1*'; then Echo_Blue "[+] Installing ${Openssl_New_Ver}" cd ${cur_dir}/src Download_Files ${Download_Mirror}/lib/openssl/${Openssl_New_Ver}.tar.gz ${Openssl_New_Ver}.tar.gz [[ -d "${Openssl_New_Ver}" ]] && rm -rf ${Openssl_New_Ver} Tar_Cd ${Openssl_New_Ver}.tar.gz ${Openssl_New_Ver} ./config enable-weak-ssl-ciphers -fPIC --prefix=/usr/local/openssl1.1.1 --openssldir=/usr/local/openssl1.1.1 make depend Make_Install ln -sf /usr/local/openssl1.1.1/lib/libcrypto.so.1.1 /usr/lib/ ln -sf /usr/local/openssl1.1.1/lib/libssl.so.1.1 /usr/lib/ cd ${cur_dir}/src/ rm -rf ${cur_dir}/src/${Openssl_New_Ver} fi ldconfig apache_with_ssl='--with-ssl=/usr/local/openssl1.1.1' else apache_with_ssl='--with-ssl' fi } Install_Nghttp2() { if [[ ! -s /usr/local/nghttp2/lib/libnghttp2.so || ! -s /usr/local/nghttp2/include/nghttp2/nghttp2.h ]]; then Echo_Blue "[+] Installing ${Nghttp2_Ver}" cd ${cur_dir}/src Download_Files ${Download_Mirror}/lib/nghttp2/${Nghttp2_Ver}.tar.xz ${Nghttp2_Ver}.tar.xz [[ -d "${Nghttp2_Ver}" ]] && rm -rf ${Nghttp2_Ver} TarJ_Cd ${Nghttp2_Ver}.tar.xz ${Nghttp2_Ver} ./configure --prefix=/usr/local/nghttp2 Make_Install cd ${cur_dir}/src/ rm -rf ${cur_dir}/src/${Nghttp2_Ver} fi } Install_Libzip() { if echo "${CentOS_Version}" | grep -Eqi "^7" || echo "${RHEL_Version}" | grep -Eqi "^7" || echo "${Aliyun_Version}" | grep -Eqi "^2"; then if [ ! -s /usr/local/lib/libzip.so ]; then Echo_Blue "[+] Installing ${Libzip_Ver}" cd ${cur_dir}/src Download_Files ${Download_Mirror}/lib/libzip/${Libzip_Ver}.tar.xz ${Libzip_Ver}.tar.xz TarJ_Cd ${Libzip_Ver}.tar.xz ${Libzip_Ver} ./configure Make_Install cd ${cur_dir}/src/ rm -rf ${cur_dir}/src/${Libzip_Ver} fi export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH ldconfig fi } CentOS_Lib_Opt() { if [ "${Is_64bit}" = "y" ] ; then ln -sf /usr/lib64/libpng.* /usr/lib/ ln -sf /usr/lib64/libjpeg.* /usr/lib/ fi ulimit -v unlimited if [ `grep -L "/lib" '/etc/ld.so.conf'` ]; then echo "/lib" >> /etc/ld.so.conf fi if [ `grep -L '/usr/lib' '/etc/ld.so.conf'` ]; then echo "/usr/lib" >> /etc/ld.so.conf #echo "/usr/lib/openssl/engines" >> /etc/ld.so.conf fi if [ -d "/usr/lib64" ] && [ `grep -L '/usr/lib64' '/etc/ld.so.conf'` ]; then echo "/usr/lib64" >> /etc/ld.so.conf #echo "/usr/lib64/openssl/engines" >> /etc/ld.so.conf fi if [ `grep -L '/usr/local/lib' '/etc/ld.so.conf'` ]; then echo "/usr/local/lib" >> /etc/ld.so.conf fi ldconfig if command -v systemd-detect-virt >/dev/null 2>&1 && [[ "$(systemd-detect-virt)" = "lxc" ]]; then cat >>/etc/security/limits.conf<>/etc/security/limits.conf<> /etc/sysctl.conf if echo "${Fedora_Version}" | grep -Eqi "3[0-9]" && [ ! -d "/etc/init.d" ]; then ln -sf /etc/rc.d/init.d /etc/init.d fi } Deb_Lib_Opt() { if [ "${Is_64bit}" = "y" ]; then ln -sf /usr/lib/x86_64-linux-gnu/libpng* /usr/lib/ ln -sf /usr/lib/x86_64-linux-gnu/libjpeg* /usr/lib/ else ln -sf /usr/lib/i386-linux-gnu/libpng* /usr/lib/ ln -sf /usr/lib/i386-linux-gnu/libjpeg* /usr/lib/ ln -sf /usr/include/i386-linux-gnu/asm /usr/include/asm fi if [ -d "/usr/lib/arm-linux-gnueabihf" ]; then ln -sf /usr/lib/arm-linux-gnueabihf/libpng* /usr/lib/ ln -sf /usr/lib/arm-linux-gnueabihf/libjpeg* /usr/lib/ ln -sf /usr/include/arm-linux-gnueabihf/curl /usr/include/ fi ulimit -v unlimited if [ `grep -L "/lib" '/etc/ld.so.conf'` ]; then echo "/lib" >> /etc/ld.so.conf fi if [ `grep -L '/usr/lib' '/etc/ld.so.conf'` ]; then echo "/usr/lib" >> /etc/ld.so.conf fi if [ -d "/usr/lib64" ] && [ `grep -L '/usr/lib64' '/etc/ld.so.conf'` ]; then echo "/usr/lib64" >> /etc/ld.so.conf fi if [ `grep -L '/usr/local/lib' '/etc/ld.so.conf'` ]; then echo "/usr/local/lib" >> /etc/ld.so.conf fi if [ -d /usr/include/x86_64-linux-gnu/curl ]; then ln -sf /usr/include/x86_64-linux-gnu/curl /usr/include/ elif [ -d /usr/include/i386-linux-gnu/curl ]; then ln -sf /usr/include/i386-linux-gnu/curl /usr/include/ fi if [ -d /usr/include/arm-linux-gnueabihf/curl ]; then ln -sf /usr/include/arm-linux-gnueabihf/curl /usr/include/ fi if [ -d /usr/include/aarch64-linux-gnu/curl ]; then ln -sf /usr/include/aarch64-linux-gnu/curl /usr/include/ fi ldconfig cat >>/etc/security/limits.conf<> /etc/sysctl.conf } Remove_Error_Libcurl() { if [ -s /usr/local/lib/libcurl.so ]; then rm -f /usr/local/lib/libcurl* fi } Add_Swap() { if ! command -v python >/dev/null 2>&1; then if [ "$PM" = "yum" ]; then yum -y install python2 elif [ "$PM" = "apt" ]; then apt-get --no-install-recommends install -y python fi fi if command -v python >/dev/null 2>&1; then Disk_Avail=$(python ${cur_dir}/include/disk.py) elif command -v python3 >/dev/null 2>&1; then Disk_Avail=$(python3 ${cur_dir}/include/disk.py) elif command -v python2 >/dev/null 2>&1; then Disk_Avail=$(python2 ${cur_dir}/include/disk.py) fi if [ "${MemTotal}" -lt 1024 ]; then DD_Count='1024' if [ "${Disk_Avail}" -lt 5 ]; then Enable_Swap='n' fi elif [[ "${MemTotal}" -ge 1024 && "${MemTotal}" -le 2048 ]]; then DD_Count='2028' if [ "${Disk_Avail}" -lt 13 ]; then Enable_Swap='n' fi elif [[ "${MemTotal}" -ge 2048 && "${MemTotal}" -le 4096 ]]; then DD_Count='4096' if [ "${Disk_Avail}" -lt 17 ]; then Enable_Swap='n' fi elif [[ "${MemTotal}" -ge 4096 && "${MemTotal}" -le 16384 ]]; then DD_Count='8192' if [ "${Disk_Avail}" -lt 19 ]; then Enable_Swap='n' fi elif [[ "${MemTotal}" -ge 16384 ]]; then DD_Count='8192' if [ "${Disk_Avail}" -lt 27 ]; then Enable_Swap='n' fi fi Swap_Total=$(free -m | grep Swap | awk '{print $2}') if [[ "${Enable_Swap}" = "y" && "${Swap_Total}" -le 512 && ! -s /var/swapfile ]]; then echo "Add Swap file..." [ $(cat /proc/sys/vm/swappiness) -eq 0 ] && sysctl vm.swappiness=10 dd if=/dev/zero of=/var/swapfile bs=1M count=${DD_Count} chmod 0600 /var/swapfile echo "Enable Swap..." /sbin/mkswap /var/swapfile /sbin/swapon /var/swapfile if [ $? -eq 0 ]; then [ `grep -L '/var/swapfile' '/etc/fstab'` ] && echo "/var/swapfile swap swap defaults 0 0" >>/etc/fstab /sbin/swapon -s else rm -f /var/swapfile echo "Add Swap Failed!" fi fi }