LNMP 一键安装脚本阅读
生活随笔
收集整理的這篇文章主要介紹了
LNMP 一键安装脚本阅读
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 基礎
- 筆記
- 軟件介紹
- 版本號
- .user.ini
- nginx
- php.ini
- 文件描述符
- 系統級別
- 用戶級別
- 安裝
- 編譯安裝Mysql
- 后續處理
- 編譯安裝 php
- 工具
- 編譯安裝 nginx
- lua 配置
- 流程
- 安裝流程
- 其他工具
- tool/*
- addons.sh
- 卸載流程
- 常用命令
- php
- nginx
- mysql
- yum
- python
- iptables
- 規則
- 服務
- lnmp 腳本
- 其他
- 源碼地址
- SHELL學習
- 系統信息
- 內存大小
- 版本信息
- 內存大小
- Swap 大小
- 磁盤大小
- openssl 版本
- centos 版本
- 系統類型, 區分安裝工具
- RHEL 版本
- 系統位數
- 判斷系統架構是否為 arm
- 地理位置
- 系統管理
- 設置時區
- 創建Swap分區
- 禁止 selinux
- 設置虛擬內存使用大小
- 配置庫路徑
- 配置文件描述符數量和進程數量
- 自啟管理
- 進程和命令
- 判斷進程是否存在
- 關閉程序
- 語法
- 變量為 6789 或者等于 10
- 隨機值
- 判斷目錄是否存在, 存在刪除
- 動態變量名
- 局部數組變量聲明
- 最佳實踐
- 選擇 yes 或者 no
- 刪除前置0, 默認值為 0
- 字符串分割
- 值排序比較
- 工具類
- 字體
- 按鍵繼續
- 判斷文件是否存在, 不存在則下載
- 編譯
- 解壓
- 隨機 Secret
- 倒計時
- 死循環讀取字符串
- 提示
- 網絡
- 判斷 host 是否包含 127.0.0.1
- 判斷 dns 是否正確
- 自定義臨時 dns 服務器
- 其他
- 阻止使用別名
- 批量創建目錄
- 管道增加額外參數
- 工具類
- 版本號對比
- 配置
- lnmp.conf
- 選項
- db
- php
基礎
筆記
- 選擇安裝JeMalloc或者TCMalloc, 則在編譯安裝 mysql 和 nginx時存在添加對應的擴展選項
- swap 策略: x<1024, y=1024; 1024<x<2048, y=2048; 2048<x<4096, y=4096; 4096<x<16384, y=8192; x>16384,y=8192
- swap 需要考慮剩余磁盤空間
- 安裝系統相關庫時, 需要動態鏈接
- 腳本運行前執行clear, 清空控制臺
軟件介紹
- FreeType庫是一個完全免費(開源)的, 高質量的且可移植的字體引擎, 它提供統一的接口來訪問多種字體格式文件
- PCRE(Perl Compatible Regular Expressions)是一個Perl庫, 包括 perl 兼容的正則表達式庫
- Boost庫是一個可移植、提供源代碼的C++庫
- cmake讀入所有源文件之后, 自動生成makefile, make依據makefile來批處理編譯
版本號
格式: major.minor.maintenance.build
- major: 是主版本號, 一般在軟件有重大升級時增長
- minor: 是次版本號, 一般在軟件有新功能時增長
- maintenance: 是維護版本, 一般在軟件有問題修復后增長
- build: 是構建版本, 一般只要軟件被重新編譯過就會增長
.user.ini
配置參考地址: http://php.net/manual/zh/ini.list.php
- 只有 PHP_INI_USER 和 PHP_INI_ALL可以被 .user.ini 和 ini_set 還有 nginx 設置
- PHP_INI_PERDIR可在 php.ini, .htaccess 或 httpd.conf 中設定
- PHP_INI_SYSTEM 可在 php.ini 或 httpd.conf 中設定
- .user.ini 文件路徑 DOCUMENT_ROOT 下
nginx
- 通過增加配置PHP_ADMIN_VALUE設置 php.ini 的值, 優先級高于 .user.ini
php.ini
- 默認用戶配置文件為 .user.ini
文件描述符
- 系統級別: 使用cat /proc/sys/fs/file-max查看, 默認值是根據內存大小自動設置, 一般為內存為 x KB, 則描述符數量為 x/10
- 用戶級別: 默認為 1024
- 限制原因: 1. 內存資源有限 2. 防止程序惡意創建, 影響系統穩定性
- 用戶級別優先級高于系統級別
系統級別
# 查看 cat /proc/sys/fs/file-max# 臨時設置 echo 1000000 > /proc/sys/fs/file-max# 永久設置 vi /etc/sysctl.conf fs.file-max = 1000000用戶級別
/etc/security/limits.conf
* soft nproc 65535 * hard nproc 65535 * soft nofile 65535 * hard nofile 65535- 第一列表示用戶和組(@開頭), * 表示所有用戶, 第二列表示軟限制還是硬限制, 第三列表示限制的資源類型, 第四列表示限制的最大值
- /etc/security/limits.d/ 里面配置會覆蓋 /etc/security/limits.conf 的配置
- core 是內核文件, nofile 是文件描述符, noproc 是進程
- hard和soft的區別: soft是一個警告值, 而hard則是一個真正意義的閥值, 超過就會報錯, 一般情況下都是設為同一個值
安裝
編譯安裝Mysql
wget https://soft.vpser.net/datebase/mysql/mysql-5.7.26.tar.gz tar xzf mysql-5.7.26.tar.gz wget https://soft.vpser.net/lib/boost/boost_1_59_0.tar.bz2 tar jxf boost_1_59_0.tar.bz2# 編譯安裝 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_BOOST=${cur_dir}/src/boost_${Get_Boost_Ver} make -j `grep 'processor' /proc/cpuinfo | wc -l` if [ $? -ne 0 ]; thenmake fi make install# 用戶組 groupadd mysql useradd -s /sbin/nologin -M -g mysql mysqlchown -R mysql:mysql ${MySQL_Data_Dir} # 初始化數據庫 /usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=${MySQL_Data_Dir} --user=mysql chgrp -R mysql /usr/local/mysql/. \cp support-files/mysql.server /etc/init.d/mysql # 可執行權限 chmod 755 /etc/init.d/mysql# 添加動態庫 cat > /etc/ld.so.conf.d/mysql.conf<<EOF /usr/local/mysql/lib /usr/local/lib EOFldconfig ln -sf /usr/local/mysql/lib/mysql /usr/lib/mysql ln -sf /usr/local/mysql/include/mysql /usr/include/mysql后續處理
# 設置密碼 UPDATE mysql.user SET authentication_string=PASSWORD('${DB_Root_Password}') WHERE User='root';# 刪除匿名用戶 DELETE FROM mysql.user WHERE User='';# 刪除遠程登錄用戶 DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');# 刪除測試數據庫 DROP DATABASE test;# 刷新權限 FLUSH PRIVILEGES;編譯安裝 php
# 編譯安裝 --disable-fileinfo ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/conf.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-pcntl --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-opcache --with-xsl make ZEND_EXTRA_LIBS='-liconv' -j `grep 'processor' /proc/cpuinfo | wc -l` if [ $? -ne 0 ]; thenmake ZEND_EXTRA_LIBS='-liconv' fi make install# 創建執行命令軟連接 ln -sf /usr/local/php/bin/php /usr/bin/php ln -sf /usr/local/php/bin/phpize /usr/bin/phpize ln -sf /usr/local/php/bin/pear /usr/bin/pear ln -sf /usr/local/php/bin/pecl /usr/bin/pecl if [ "${Stack}" = "lnmp" ]; thenln -sf /usr/local/php/sbin/php-fpm /usr/bin/php-fpm fi rm -f /usr/local/php/conf.d/*# 設置包管理使用的 php.ini pear config-set php_ini /usr/local/php/etc/php.ini pecl config-set php_ini /usr/local/php/etc/php.ini# 安裝 composer curl -sS --connect-timeout 30 -m 60 https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer# 添加啟動任務 \cp ${cur_dir}/src/${Php_Ver}/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod +x /etc/init.d/php-fpm工具
cat >phpinfo.php<<eof <?php phpinfo(); ?> eof編譯安裝 nginx
groupadd www useradd -s /sbin/nologin -g www wwwNginx_With_Openssl=--with-openssl=${cur_dir}/src/${Openssl_New_Ver} --with-openssl-opt='enable-weak-ssl-ciphers' ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module ${Nginx_With_Openssl} ${Nginx_Module_Lua} ${NginxMAOpt} ${Nginx_Modules_Options}lua 配置
location /lua {default_type text/html;content_by_lua 'ngx.say("hello world")'; }流程
安裝流程
其他工具
tool/*
- backup.sh 數據備份
- check502.sh 校驗地址否是 502 網關錯誤
- cut_nginx_logs.sh nginx 日志切割
- denyhosts_removeip.sh 解除 denyhost 屏蔽
- denyhosts.sh 預防 SSH 暴力破解的
- fail2ban.sh 防止暴力破解
- remove_disable_function.sh 刪除預定義禁用函數
- remove_open_basedir_restriction.sh 刪除 open_basedir 的限制
- reset_mysql_root_password.sh 重置密碼
addons.sh
卸載流程
常用命令
php
# 編譯參數 php -i|grep configure# 擴展地址 /usr/local/php/bin/php-config --extension-dir# 卸載 rpm -e php-mysql php-cli php-gd php-common php --nodepsnginx
# 查看編譯參數 nginx -Vmysql
# 版本 /usr/local/mysql/bin/mysql_config --version# 校驗密碼是否正常 Make_TempMycnf() { cat >~/.my.cnf<<EOF [client] user=root password='$1' socket=/home/mysql/tmp/mysql.sock EOFchmod 600 ~/.my.cnf }Verify_DB_Password() {status=1while [ $status -eq 1 ]; doread -s -p "Enter current root password of Database (Password will not shown): " DB_Root_PasswordMake_TempMycnf "${DB_Root_Password}"Do_Query ""status=$?doneecho "OK, MySQL root password correct." }TempMycnf_Clean() {if [ -s ~/.my.cnf ]; thenrm -f ~/.my.cnffiif [ -s /tmp/.mysql.tmp ]; thenrm -f /tmp/.mysql.tmpfi }# 卸載 yum -y remove mysql-server mysql mysql-libs mariadb-server mariadb mariadb-libs rpm -e mysql mysql-libs --nodeps rpm -e mariadb mariadb-libs --nodepsyum
## 檢查 yum 的配置, 是否有不包含的 repo sed -i 's:exclude=.*:exclude=:g' /etc/yum.confpython
計算當前目錄剩余空間, 單位 G
#!/usr/bin/env python import osdir = os.path.dirname(__file__) disk = os.statvfs(dir) Avail = disk.f_bavail * disk.f_bsize / (1024*1024*1024) print(int(Avail))iptables
規則
iptables -I INPUT 1 -i lo -j ACCEPT # 已經創建的連接和封包和本機有關的連接匹配規則 iptables -I INPUT 2 -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -I INPUT 3 -p tcp --dport 22 -j ACCEPT iptables -I INPUT 4 -p tcp --dport 80 -j ACCEPT iptables -I INPUT 5 -p tcp --dport 443 -j ACCEPT iptables -I INPUT 6 -p tcp --dport 3306 -j DROP iptables -I INPUT 7 -p icmp -m icmp --icmp-type 8 -j ACCEPT服務
yum -y install iptables-services service iptables save service iptables reload if command -v firewalld >/dev/null 2>&1; thensystemctl stop firewalldsystemctl disable firewalld fi chkconfig --add iptables chkconfig iptables onlnmp 腳本
# 排除 mysql sed -i 's#/etc/init.d/mysql.*##' /bin/lnmp其他
源碼地址
https://soft.vpser.net/web/libiconv/libiconv-1.15.tar.gz https://soft.vpser.net/web/libmcrypt/libmcrypt-2.5.8.tar.gz https://soft.vpser.net/web/mcrypt/mcrypt-2.6.8.tar.gz https://soft.vpser.net/web/mhash/mhash-0.9.9.9.tar.bz2 https://soft.vpser.net/web/nginx/nginx-1.16.1.tar.gz https://soft.vpser.net/web/php/php-7.1.33.tar.bz2 https://soft.vpser.net/datebase/mysql/mysql-5.7.26.tar.gz https://soft.vpser.net/datebase/phpmyadmin/phpMyAdmin-4.9.1-all-languages.tar.xz https://soft.vpser.net/prober/p.tar.gz https://soft.vpser.net/lib/openssl/openssl-1.0.2t.tar.gz https://soft.vpser.net/lib/boost/boost_1_59_0.tar.bz2 https://soft.vpser.net/web/php/composer/composer.pharSHELL學習
系統信息
內存大小
[ `free -m | grep Mem | awk '{print $2}'` -le 1024 ]版本信息
cat /etc/*-release內存大小
free -m | grep Mem | awk '{print $2}'Swap 大小
free -m | grep Swap | awk '{print $2}'磁盤大小
df -hopenssl 版本
openssl versioncentos 版本
echo "$(python2 -c 'import platform; print platform.linux_distribution()[1]')"lsb_release -rs系統類型, 區分安裝工具
if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; thenDISTRO='CentOS'PM='yum' elif grep -Eqi "Red Hat Enterprise Linux" /etc/issue || grep -Eq "Red Hat Enterprise Linux" /etc/*-release; thenDISTRO='RHEL'PM='yum' elif grep -Eqi "Aliyun" /etc/issue || grep -Eq "Aliyun" /etc/*-release; thenDISTRO='Aliyun'PM='yum' elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; thenDISTRO='Fedora'PM='yum' elif grep -Eqi "Amazon Linux" /etc/issue || grep -Eq "Amazon Linux" /etc/*-release; thenDISTRO='Amazon'PM='yum' elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; thenDISTRO='Debian'PM='apt' elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; thenDISTRO='Ubuntu'PM='apt' elif grep -Eqi "Raspbian" /etc/issue || grep -Eq "Raspbian" /etc/*-release; thenDISTRO='Raspbian'PM='apt' elif grep -Eqi "Deepin" /etc/issue || grep -Eq "Deepin" /etc/*-release; thenDISTRO='Deepin'PM='apt' elif grep -Eqi "Mint" /etc/issue || grep -Eq "Mint" /etc/*-release; thenDISTRO='Mint'PM='apt' elif grep -Eqi "Kali" /etc/issue || grep -Eq "Kali" /etc/*-release; thenDISTRO='Kali'PM='apt' elseDISTRO='unknow' fiRHEL 版本
判斷是否是版本 7.*
[ grep -Eqi "release 7." /etc/redhat-release ]系統位數
# 64位的系統中int類型還是4字節的,但是long已變成了8字節 if [[ `getconf WORD_BIT` = '32' && `getconf LONG_BIT` = '64' ]] ; thenIs_64bit='y' elseIs_64bit='n' fi判斷系統架構是否為 arm
if uname -m | grep -Eqi "arm|aarch64"; thenIs_ARM='y' fi地理位置
curl -sSk --connect-timeout 30 -m 60 https://ip.vpser.net/country系統管理
設置時區
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime創建Swap分區
DD_Count=1024 echo "Add Swap file..." 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 elserm -f /var/swapfileecho "Add Swap Failed!" fi禁止 selinux
if [ -s /etc/selinux/config ]; thensed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config fi設置虛擬內存使用大小
ulimit -v unlimited配置庫路徑
if [ `grep -L "/lib" '/etc/ld.so.conf'` ]; thenecho "/lib" >> /etc/ld.so.conf fiif [ `grep -L '/usr/lib' '/etc/ld.so.conf'` ]; thenecho "/usr/lib" >> /etc/ld.so.conf##echo "/usr/lib/openssl/engines" >> /etc/ld.so.conf fiif [ -d "/usr/lib64" ] && [ `grep -L '/usr/lib64' '/etc/ld.so.conf'` ]; thenecho "/usr/lib64" >> /etc/ld.so.conf##echo "/usr/lib64/openssl/engines" >> /etc/ld.so.conf fiif [ `grep -L '/usr/local/lib' '/etc/ld.so.conf'` ]; thenecho "/usr/local/lib" >> /etc/ld.so.conf fi配置文件描述符數量和進程數量
cat >>/etc/security/limits.conf<<eof * soft nproc 65535 * hard nproc 65535 * soft nofile 65535 * hard nofile 65535 eof echo "fs.file-max=65535" >> /etc/sysctl.conf自啟管理
# 開啟 chkconfig --add lnmp chkconfig lnmp on# 關閉 chkconfig lnmp off chkconfig --del lnmp進程和命令
判斷進程是否存在
if ps aux | grep "yum" | grep -qv "grep"; then# 判斷命令是否存在if command -v killall >/dev/null 2>&1; then# 關閉程序killall yumelse# 關閉程序kill `pidof yum`fi fi關閉程序
kill `pidof yum` killall yum語法
變量為 6789 或者等于 10
[[ "${DBSelect}" =~ ^[6789]|10$ ]]隨機值
echo "lnmp.org##$RANDOM"判斷目錄是否存在, 存在刪除
[[ -d "${DirName}" ]] && rm -rf ${DirName}動態變量名
eval echo "${DISTRO} \${${DISTRO}_Version}"局部數組變量聲明
local -a最佳實踐
選擇 yes 或者 no
case "${InstallInnodb}" in [yY][eE][sS]|[yY])echo "${InstallInnodb}";; [nN][oO]|[nN])echo "${InstallInnodb}";; *)echo "${InstallInnodb}" esac刪除前置0, 默認值為 0
echo ${version[0]:=0} | sed 's/^0*//'字符串分割
version=1.2.3.4 OLDIFS=${IFS} && IFS=. && version=(${version}) && IFS=${OLDIFS}值排序比較
local -a sorted=($(printf "%s\n%s" "${v1}" "${v2}" | sort )) if [ "${v1}" == "${sorted[0]}" ]; then echo -1; else echo 1; fi工具類
字體
Color_Text() {echo -e " \e[0;$2m$1\e[0m" }Echo_Red() {echo $(Color_Text "$1" "31") }Echo_Green() {echo $(Color_Text "$1" "32") }Echo_Yellow() {echo $(Color_Text "$1" "33") }Echo_Blue() {echo $(Color_Text "$1" "34") }按鍵繼續
if [ -z ${LNMP_Auto} ]; thenecho ""Echo_Green "Press any key to install...or Press Ctrl+c to cancel"OLDCONFIG=`stty -g`stty -icanon -echo min 1 time 0dd count=1 2>/dev/nullstty ${OLDCONFIG} fi判斷文件是否存在, 不存在則下載
Download_Files() {local URL=$1local FileName=$2if [ -s "${FileName}" ]; thenecho "${FileName} [found]"elseecho "Notice: ${FileName} not found!!!download now..."wget -c --progress=bar:force --prefer-family=IPv4 --no-check-certificate ${URL}fi }編譯
Make_Install() {# 嘗試多進程編譯make -j `grep 'processor' /proc/cpuinfo | wc -l`if [ $? -ne 0 ]; thenmakefimake install }解壓
Tar_Cd() {local FileName=$1local DirName=$2cd ${cur_dir}/src[[ -d "${DirName}" ]] && rm -rf ${DirName}echo "Uncompress ${FileName}..."tar zxf ${FileName}if [ -n "${DirName}" ]; thenecho "cd ${DirName}..."cd ${DirName}fi }隨機 Secret
sed -i 's/LNMPORG/LNMP.org_0'$RANDOM`date '+%s'`$RANDOM'9_VPSer.net/g' config.inc.php倒計時
Sleep_Sec() {seconds=$1while [ "${seconds}" -ge "0" ];doecho -ne "\r \r"echo -n ${seconds}seconds=$(($seconds - 1))sleep 1doneecho -ne "\r" }死循環讀取字符串
while :;doread -p "Enter website root directory: " website_rootif [ -d "${website_root}" ]; then# TODO: somethingbreakelseecho "${website_root} is not directory or not exist!"fi done提示
clear echo "+-------------------------------------------------------------------+" echo "| Remove PHP disable functions for LNMP, Written by Licess |" echo "+-------------------------------------------------------------------+" echo "| A tool to remove PHP disable_functions for LNMP |" echo "+-------------------------------------------------------------------+" echo "| For more information please visit https://lnmp.org |" echo "+-------------------------------------------------------------------+" echo "| Usage: ./remove_disable_function.sh |" echo "+-------------------------------------------------------------------+"網絡
判斷 host 是否包含 127.0.0.1
if grep -Eqi '^127.0.0.1[[:space:]]*localhost' /etc/hosts; thenecho "Hosts: ok." else## 添加 localhost 環路到配置文件echo "127.0.0.1 localhost.localdomain localhost" >> /etc/hosts fi判斷 dns 是否正確
pingresult=`ping -c1 lnmp.org 2>&1` echo "${pingresult}" if echo "${pingresult}" | grep -q "unknown host"; thenecho "DNS...fail"echo "Writing nameserver to /etc/resolv.conf ..."echo -e "nameserver 208.67.220.220\nnameserver 114.114.114.114" > /etc/resolv.conf elseecho "DNS...ok" fi自定義臨時 dns 服務器
echo -e "nameserver 208.67.220.220\nnameserver 114.114.114.114" > /etc/resolv.conf其他
阻止使用別名
\cp a b批量創建目錄
mkdir -p /usr/local/php/{etc,conf.d}管道增加額外參數
curl -sS --connect-timeout 30 -m 60 https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer工具類
版本號對比
#!/bin/bash # -*- tab-width: 2; encoding: utf-8 -*-## @file version_compare ## Compare [semantic] versions in Bash, comparable to PHP's version_compare function. # ------------------------------------------------------------------ ## @author Mark Carver <mark.carver@me.com> ## @copyright MIT ## @version 1.0.0 ## @see http://php.net/manual/en/function.version-compare.phpAPP_NAME=$(basename ${0}) APP_VERSION="1.0.0"# Version compare function version_compare () {# Default to a failed comparison result.local -i result=1;# Ensure there are two versions to compare.[ $# -lt 2 ] || [ -z "${1}" ] || [ -z "${2}" ] && echo "${FUNCNAME[0]} requires a minimum of two arguments to compare versions." &>/dev/stderr && return ${result}# Determine the operation to perform, if any.local op="${3}"# Convert passed versions into values for comparison.local v1=$(version_compare_convert ${1})local v2=$(version_compare_convert ${2})# Immediately return when comparing version equality (which doesn't require sorting).if [ -z "${op}" ]; then[ "${v1}" == "${v2}" ] && echo 0 && return;elseif [ "${op}" == "!=" ] || [ "${op}" == "<>" ] || [ "${op}" == "ne" ]; thenif [ "${v1}" != "${v2}" ]; then let result=0; fi;return ${result};elif [ "${op}" == "=" ] || [ "${op}" == "==" ] || [ "${op}" == "eq" ]; thenif [ "${v1}" == "${v2}" ]; then let result=0; fi;return ${result};elif [ "${op}" == "le" ] || [ "${op}" == "<=" ] || [ "${op}" == "ge" ] || [ "${op}" == ">=" ] && [ "${v1}" == "${v2}" ]; thenif [ "${v1}" == "${v2}" ]; then let result=0; fi;return ${result};fifi# If we get to this point, the versions should be different.# Immediately return if they're the same.[ "${v1}" == "${v2}" ] && return ${result}local sort='sort'# If only one version has a pre-release label, reverse sorting so# the version without one can take precedence.[[ "${v1}" == *"-"* ]] && [[ "${v2}" != *"-"* ]] || [[ "${v2}" == *"-"* ]] && [[ "${v1}" != *"-"* ]] && sort="${sort} -r"# Sort the versions.local -a sorted=($(printf "%s\n%s" "${v1}" "${v2}" | ${sort}))# No operator passed, indicate which direction the comparison leans.if [ -z "${op}" ]; thenif [ "${v1}" == "${sorted[0]}" ]; then echo -1; else echo 1; fireturnficase "${op}" in"<" | "lt" | "<=" | "le") if [ "${v1}" == "${sorted[0]}" ]; then let result=0; fi;;">" | "gt" | ">=" | "ge") if [ "${v1}" == "${sorted[1]}" ]; then let result=0; fi;;esacreturn ${result} }# Converts a version string to an integer that is used for comparison purposes. function version_compare_convert () {local version="${@}"# Remove any build meta information as it should not be used per semver spec.version="${version%+*}"# Extract any pre-release label.local prerelease[[ "${version}" = *"-"* ]] && prerelease=${version##*-}[ -n "${prerelease}" ] && prerelease="-${prerelease}"version="${version%%-*}"# Separate version (minus pre-release label) into an array using periods as the separator.local OLDIFS=${IFS} && local IFS=. && version=(${version%-*}) && IFS=${OLDIFS}# Unfortunately, we must use sed to strip of leading zeros here.local major=$(echo ${version[0]:=0} | sed 's/^0*//')local minor=$(echo ${version[1]:=0} | sed 's/^0*//')local patch=$(echo ${version[2]:=0} | sed 's/^0*//')local build=$(echo ${version[3]:=0} | sed 's/^0*//')# Combine the version parts and pad everything with zeros, except major.printf "%s%04d%04d%04d%s\n" "${major}" "${minor}" "${patch}" "${build}" "${prerelease}" }# Color Support # See: http://unix.stackexchange.com/a/10065 if test -t 1; thenncolors=$(tput colors)if test -n "$ncolors" && test $ncolors -ge 8; thenbold="$(tput bold)" && underline="$(tput smul)" && standout="$(tput smso)" && normal="$(tput sgr0)"black="$(tput setaf 0)" && red="$(tput setaf 1)" && green="$(tput setaf 2)" && yellow="$(tput setaf 3)"blue="$(tput setaf 4)" && magenta="$(tput setaf 5)" && cyan="$(tput setaf 6)" && white="$(tput setaf 7)"fi fifunction version_compare_usage {echo "${bold}${APP_NAME} (${APP_VERSION})${normal}"echo "Compare [semantic] versions in Bash, comparable to PHP's version_compare function."echoecho " - When ${cyan}<operator>${normal} is NOT provided, ${APP_NAME} will output (print to /dev/stdout):"echo " -1: ${cyan}<version1>${normal} is lower than ${cyan}<version2>${normal}"echo " 0: ${cyan}<version1>${normal} and ${cyan}<version2>${normal} are equal"echo " 1: ${cyan}<version2>${normal} is lower than ${cyan}<version1>${normal}"echo }# Do not continue if sourced. [[ ${0} != "$BASH_SOURCE" ]] && return# Process options. while getopts ":hV" opt; docase $opt inh) version_compare_usage && exit;;V) echo "${APP_VERSION}" && exit;;\?|*) echo "${red}${APP_NAME}: illegal option: -- ${OPTARG}${normal}" >&2 && echo && version_compare_usage && exit 64;;esac done shift $((OPTIND-1)) # Remove parsed options.# Allow script to be invoked as a CLI "command" by proxying arguments to the internal function. [ $# -gt 0 ] && version_compare ${@}配置
lnmp.conf
# 下載地址 Download_Mirror='https://soft.vpser.net'# 檢查鏡像 Check_Mirror# 數據庫 DBSelect DB_Root_Password InstallInnodb# php PHPSelect # 不安裝-1 SelectMalloc # 自動安裝 LNMP_Auto選項
db
php
總結
以上是生活随笔為你收集整理的LNMP 一键安装脚本阅读的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: fatal error C1001: I
- 下一篇: java的算术表达式程序,java计算数