├── 16.04 ├── install.sh ├── install_elasticsearch.sh ├── mysql_add_user.sh ├── nginx_add_site.sh └── nginx_site_conf.tpl ├── 18.04 ├── install.sh ├── install_elasticsearch.sh ├── mysql_add_user.sh ├── nginx_add_site.sh └── nginx_site_conf.tpl ├── 20.04 ├── install.sh ├── install_elasticsearch.sh ├── mysql_add_user.sh ├── nginx_add_site.sh └── nginx_site_conf.tpl ├── 22.04 ├── install.sh ├── install_elasticsearch.sh ├── mysql_add_user.sh ├── nginx_add_site.sh └── nginx_site_conf.tpl ├── common ├── ansi.sh └── common.sh ├── download.16.04.sh ├── download.18.04.sh ├── download.20.04.sh ├── download.22.04.sh ├── download.sh └── readme.md /16.04/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 5 | source ${CURRENT_DIR}/../common/common.sh 6 | 7 | [ $(id -u) != "0" ] && { ansi -n --bold --bg-red "请用 root 账户执行本脚本"; exit 1; } 8 | 9 | MYSQL_ROOT_PASSWORD=`random_string` 10 | 11 | function init_system { 12 | export LC_ALL="en_US.UTF-8" 13 | echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale 14 | locale-gen en_US.UTF-8 15 | locale-gen zh_CN.UTF-8 16 | 17 | ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 18 | 19 | apt-get update 20 | apt-get install -y software-properties-common 21 | 22 | init_alias 23 | } 24 | 25 | function init_alias { 26 | alias sudowww > /dev/null 2>&1 || { 27 | echo "alias sudowww='sudo -H -u ${WWW_USER} sh -c'" >> ~/.bash_aliases 28 | } 29 | } 30 | 31 | function init_repositories { 32 | add-apt-repository -y ppa:ondrej/php 33 | add-apt-repository -y ppa:nginx/stable 34 | grep -rl ppa.launchpad.net /etc/apt/sources.list.d/ | xargs sed -i 's/http:\/\/ppa.launchpad.net/https:\/\/launchpad.proxy.ustclug.org/g' 35 | 36 | curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - 37 | echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list 38 | 39 | # https://mirrors.tuna.tsinghua.edu.cn/ 2021-02-05移除 nodesource 镜像 40 | 41 | curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - 42 | echo 'deb https://deb.nodesource.com/node_10.x xenial main' > /etc/apt/sources.list.d/nodesource.list 43 | echo 'deb-src https://deb.nodesource.com/node_10.x xenial main' >> /etc/apt/sources.list.d/nodesource.list 44 | 45 | apt-get update 46 | } 47 | 48 | function install_basic_softwares { 49 | apt-get install -y curl git build-essential unzip supervisor 50 | } 51 | 52 | function install_node_yarn { 53 | apt-get install -y nodejs yarn 54 | sudo -H -u ${WWW_USER} sh -c 'cd ~ && yarn config set registry https://registry.npm.taobao.org' 55 | } 56 | 57 | function install_php { 58 | apt-get install -y php7.4-bcmath php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-pgsql php7.4-readline php7.4-xml php7.4-zip php7.4-sqlite3 php7.4-redis 59 | } 60 | 61 | function install_others { 62 | apt-get remove -y apache2 63 | debconf-set-selections <<< "mysql-server mysql-server/root_password password ${MYSQL_ROOT_PASSWORD}" 64 | debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQL_ROOT_PASSWORD}" 65 | apt-get install -y nginx mysql-server redis-server memcached beanstalkd sqlite3 66 | chown -R ${WWW_USER}.${WWW_USER_GROUP} /var/www/ 67 | systemctl enable nginx.service 68 | } 69 | 70 | function install_composer { 71 | curl https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer 72 | chmod +x /usr/local/bin/composer 73 | sudo -H -u ${WWW_USER} sh -c 'cd ~ && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/' 74 | } 75 | 76 | call_function init_system "正在初始化系统" ${LOG_PATH} 77 | call_function init_repositories "正在初始化软件源" ${LOG_PATH} 78 | call_function install_basic_softwares "正在安装基础软件" ${LOG_PATH} 79 | call_function install_php "正在安装 PHP" ${LOG_PATH} 80 | call_function install_others "正在安装 Mysql / Nginx / Redis / Memcached / Beanstalkd / Sqlite3" ${LOG_PATH} 81 | call_function install_node_yarn "正在安装 Nodejs / Yarn" ${LOG_PATH} 82 | call_function install_composer "正在安装 Composer" ${LOG_PATH} 83 | 84 | ansi --green --bold -n "安装完毕" 85 | ansi --green --bold "Mysql root 密码:"; ansi -n --bold --bg-yellow --black ${MYSQL_ROOT_PASSWORD} 86 | ansi --green --bold -n "请手动执行 source ~/.bash_aliases 使 alias 指令生效。" 87 | -------------------------------------------------------------------------------- /16.04/install_elasticsearch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 4 | source ${CURRENT_DIR}/../common/common.sh 5 | 6 | VERSION=$1 7 | VERSION=${VERSION:-6} 8 | 9 | [ $(id -u) != "0" ] && { ansi -n --bold --bg-red "请用 root 账户执行本脚本"; exit 1; } 10 | 11 | # 设置 JAVA_HOME 12 | export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-openjdk-amd64/bin:/usr/lib/jvm/java-8-openjdk-amd64/db/bin:/usr/lib/jvm/java-8-openjdk-amd64/jre/bin" 13 | export J2SDKDIR="/usr/lib/jvm/java-8-openjdk-amd64" 14 | export J2REDIR="/usr/lib/jvm/java-8-openjdk-amd64/jre*" 15 | export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64" 16 | export DERBY_HOME="/usr/lib/jvm/java-8-openjdk-amd64/db" 17 | 18 | function install_java { 19 | apt-get install -y openjdk-8-jre 20 | } 21 | 22 | function install_es { 23 | curl -sS https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - 24 | echo "deb https://mirrors.tuna.tsinghua.edu.cn/elasticstack/${VERSION}.x/apt stable main" > /etc/apt/sources.list.d/elastic-${VERSION}.x.list 25 | apt-get update 26 | apt-get install -y elasticsearch 27 | service elasticsearch start 28 | } 29 | 30 | function install_es_plugins { 31 | ESVersion=$(/usr/share/elasticsearch/bin/elasticsearch -V|awk -F',' '{print $1}'| awk '{print $2}') 32 | 33 | [[ -e /usr/share/elasticsearch/plugins/analysis-ik ]] || { 34 | /usr/share/elasticsearch/bin/elasticsearch-plugin install --batch https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v${ESVersion}/elasticsearch-analysis-ik-${ESVersion}.zip 35 | } 36 | mkdir -p /etc/elasticsearch/analysis/ 37 | touch /etc/elasticsearch/analysis/synonyms.txt 38 | 39 | service elasticsearch restart 40 | } 41 | 42 | call_function install_java "正在安装 JAVA" ${LOG_PATH} 43 | call_function install_es "正在安装 Elasticsearch ${VERSION}" ${LOG_PATH} 44 | call_function install_es_plugins "正在安装 Elasticsearch 插件" ${LOG_PATH} 45 | 46 | ansi --green --bold -n "安装完毕" 47 | -------------------------------------------------------------------------------- /16.04/mysql_add_user.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 4 | source ${CURRENT_DIR}/../common/common.sh 5 | 6 | read -r -p "请输入 Mysql root 密码:" MYSQL_ROOT_PASSWORD 7 | 8 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "quit" >> ${LOG_PATH} 2>&1 || { 9 | ansi -n --bold --bg-red "密码不正确" 10 | exit 1 11 | } 12 | 13 | read -r -p "请输入要新建的用户名:" MYSQL_NORMAL_USER 14 | 15 | [[ $MYSQL_NORMAL_USER =~ ^[a-zA-Z\0-9_\-]+$ ]] || { 16 | ansi -n --bold --bg-red "用户名包含非法字符" 17 | exit 1 18 | } 19 | 20 | MYSQL_NORMAL_USER_PASSWORD=`random_string` 21 | 22 | read -r -p "是否创建同名数据库并赋予权限?[y/N] " response 23 | case "$response" in 24 | [yY][eE][sS]|[yY]) 25 | CREATE_DB=1 26 | ;; 27 | *) 28 | CREATE_DB=0 29 | ;; 30 | esac 31 | 32 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "CREATE USER '${MYSQL_NORMAL_USER}' IDENTIFIED BY '${MYSQL_NORMAL_USER_PASSWORD}';" >> ${LOG_PATH} 2>&1 33 | 34 | ansi -n --bold --green "用户创建成功"; 35 | 36 | ansi --green --bold "用户名:"; ansi -n --bg-yellow --black ${MYSQL_NORMAL_USER} 37 | ansi --green --bold "密码:"; ansi -n --bg-yellow --black ${MYSQL_NORMAL_USER_PASSWORD} 38 | 39 | if [[ CREATE_DB -eq 1 ]]; then 40 | DATABASE_NAME=${MYSQL_NORMAL_USER} 41 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "CREATE DATABASE \`${DATABASE_NAME}\`;" >> ${LOG_PATH} 2>&1 42 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "GRANT ALL ON \`${DATABASE_NAME}\`.* TO '${MYSQL_NORMAL_USER}';" >> ${LOG_PATH} 2>&1 43 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "FLUSH PRIVILEGES;" >> ${LOG_PATH} 2>&1 44 | fi 45 | 46 | ansi -n --bold --green "数据库 ${DATABASE_NAME} 创建成功"; 47 | -------------------------------------------------------------------------------- /16.04/nginx_add_site.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 4 | source ${CURRENT_DIR}/../common/common.sh 5 | 6 | [ $(id -u) != "0" ] && { ansi -n --bold --bg-red "请用 root 账户执行本脚本"; exit 1; } 7 | 8 | read -r -p "请输入项目名:" project 9 | 10 | [[ $project =~ ^[a-zA-Z\0-9_\-\.]+$ ]] || { 11 | ansi -n --bold --bg-red "项目名包含非法字符" 12 | exit 1 13 | } 14 | 15 | read -r -p "请输入站点域名(多个域名用空格隔开):" domains 16 | 17 | project_dir="/var/www/${project}" 18 | 19 | ansi -n --bold --green "域名列表:${domains}" 20 | ansi -n --bold --green "项目名:${project}" 21 | ansi -n --bold --green "项目目录:${project_dir}" 22 | 23 | read -r -p "是否确认? [y/N] " response 24 | case "$response" in 25 | [yY][eE][sS]|[yY]) 26 | ;; 27 | *) 28 | ansi -n --bold --bg-red "用户取消" 29 | exit 1 30 | ;; 31 | esac 32 | 33 | cat ${CURRENT_DIR}/nginx_site_conf.tpl | 34 | sed "s|{{domains}}|${domains}|g" | 35 | sed "s|{{project}}|${project}|g" | 36 | sed "s|{{project_dir}}|${project_dir}|g" > /etc/nginx/sites-available/${project}.conf 37 | 38 | ln -sf /etc/nginx/sites-available/${project}.conf /etc/nginx/sites-enabled/${project}.conf 39 | 40 | ansi -n --bold --green "配置文件创建成功"; 41 | 42 | mkdir -p ${project_dir} && chown -R ${WWW_USER}.${WWW_USER_GROUP} ${project_dir} 43 | 44 | systemctl restart nginx.service 45 | 46 | ansi -n --bold --green "Nginx 重启成功"; 47 | -------------------------------------------------------------------------------- /16.04/nginx_site_conf.tpl: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | server_name {{domains}}; 4 | root "{{project_dir}}/public"; 5 | 6 | index index.html index.htm index.php; 7 | 8 | charset utf-8; 9 | 10 | location / { 11 | try_files $uri $uri/ /index.php?$query_string; 12 | } 13 | 14 | location = /favicon.ico { access_log off; log_not_found off; } 15 | location = /robots.txt { access_log off; log_not_found off; } 16 | 17 | access_log /var/log/nginx/{{project}}.log; 18 | error_log /var/log/nginx/{{project}}-error.log error; 19 | 20 | sendfile off; 21 | 22 | client_max_body_size 100m; 23 | 24 | location ~ \.php$ { 25 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 26 | fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; 27 | fastcgi_index index.php; 28 | include fastcgi_params; 29 | fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 30 | fastcgi_param DOCUMENT_ROOT $realpath_root; 31 | 32 | fastcgi_intercept_errors off; 33 | fastcgi_buffer_size 16k; 34 | fastcgi_buffers 4 16k; 35 | fastcgi_connect_timeout 300; 36 | fastcgi_send_timeout 300; 37 | fastcgi_read_timeout 300; 38 | } 39 | 40 | location ~ /\.ht { 41 | deny all; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /18.04/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 5 | source ${CURRENT_DIR}/../common/common.sh 6 | 7 | [ $(id -u) != "0" ] && { ansi -n --bold --bg-red "请用 root 账户执行本脚本"; exit 1; } 8 | 9 | MYSQL_ROOT_PASSWORD=`random_string` 10 | 11 | function init_system { 12 | export LC_ALL="en_US.UTF-8" 13 | echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale 14 | locale-gen en_US.UTF-8 15 | locale-gen zh_CN.UTF-8 16 | 17 | ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 18 | 19 | apt-get update 20 | apt-get install -y software-properties-common 21 | 22 | init_alias 23 | } 24 | 25 | function init_alias { 26 | alias sudowww > /dev/null 2>&1 || { 27 | echo "alias sudowww='sudo -H -u ${WWW_USER} sh -c'" >> ~/.bash_aliases 28 | } 29 | } 30 | 31 | function init_repositories { 32 | add-apt-repository -y ppa:ondrej/php 33 | add-apt-repository -y ppa:nginx/stable 34 | grep -rl ppa.launchpad.net /etc/apt/sources.list.d/ | xargs sed -i 's/http:\/\/ppa.launchpad.net/https:\/\/launchpad.proxy.ustclug.org/g' 35 | 36 | curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - 37 | echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list 38 | 39 | # https://mirrors.tuna.tsinghua.edu.cn/ 2021-02-05移除 nodesource 镜像 40 | 41 | curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - 42 | echo 'deb https://deb.nodesource.com/node_10.x bionic main' > /etc/apt/sources.list.d/nodesource.list 43 | echo 'deb-src https://deb.nodesource.com/node_10.x bionic main' >> /etc/apt/sources.list.d/nodesource.list 44 | 45 | apt-get update 46 | } 47 | 48 | function install_basic_softwares { 49 | apt-get install -y curl git build-essential unzip supervisor 50 | } 51 | 52 | function install_node_yarn { 53 | apt-get install -y nodejs yarn 54 | sudo -H -u ${WWW_USER} sh -c 'cd ~ && yarn config set registry https://registry.npm.taobao.org' 55 | } 56 | 57 | function install_php { 58 | apt-get install -y php7.4-bcmath php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-pgsql php7.4-readline php7.4-xml php7.4-zip php7.4-sqlite3 php7.4-redis 59 | } 60 | 61 | function install_others { 62 | apt-get remove -y apache2 63 | debconf-set-selections <<< "mysql-server mysql-server/root_password password ${MYSQL_ROOT_PASSWORD}" 64 | debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQL_ROOT_PASSWORD}" 65 | apt-get install -y nginx mysql-server redis-server memcached beanstalkd sqlite3 66 | chown -R ${WWW_USER}.${WWW_USER_GROUP} /var/www/ 67 | systemctl enable nginx.service 68 | } 69 | 70 | function install_composer { 71 | curl https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer 72 | chmod +x /usr/local/bin/composer 73 | sudo -H -u ${WWW_USER} sh -c 'cd ~ && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/' 74 | } 75 | 76 | call_function init_system "正在初始化系统" ${LOG_PATH} 77 | call_function init_repositories "正在初始化软件源" ${LOG_PATH} 78 | call_function install_basic_softwares "正在安装基础软件" ${LOG_PATH} 79 | call_function install_php "正在安装 PHP" ${LOG_PATH} 80 | call_function install_others "正在安装 Mysql / Nginx / Redis / Memcached / Beanstalkd / Sqlite3" ${LOG_PATH} 81 | call_function install_node_yarn "正在安装 Nodejs / Yarn" ${LOG_PATH} 82 | call_function install_composer "正在安装 Composer" ${LOG_PATH} 83 | 84 | ansi --green --bold -n "安装完毕" 85 | ansi --green --bold "Mysql root 密码:"; ansi -n --bold --bg-yellow --black ${MYSQL_ROOT_PASSWORD} 86 | ansi --green --bold -n "请手动执行 source ~/.bash_aliases 使 alias 指令生效。" 87 | -------------------------------------------------------------------------------- /18.04/install_elasticsearch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 4 | source ${CURRENT_DIR}/../common/common.sh 5 | 6 | VERSION=$1 7 | VERSION=${VERSION:-6} 8 | 9 | [ $(id -u) != "0" ] && { ansi -n --bold --bg-red "请用 root 账户执行本脚本"; exit 1; } 10 | 11 | # 设置 JAVA_HOME 12 | export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-openjdk-amd64/bin:/usr/lib/jvm/java-8-openjdk-amd64/db/bin:/usr/lib/jvm/java-8-openjdk-amd64/jre/bin" 13 | export J2SDKDIR="/usr/lib/jvm/java-8-openjdk-amd64" 14 | export J2REDIR="/usr/lib/jvm/java-8-openjdk-amd64/jre*" 15 | export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64" 16 | export DERBY_HOME="/usr/lib/jvm/java-8-openjdk-amd64/db" 17 | 18 | function install_java { 19 | apt-get install -y openjdk-8-jre 20 | } 21 | 22 | function install_es { 23 | curl -sS https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - 24 | echo "deb https://mirrors.tuna.tsinghua.edu.cn/elasticstack/${VERSION}.x/apt stable main" > /etc/apt/sources.list.d/elastic-${VERSION}.x.list 25 | apt-get update 26 | apt-get install -y elasticsearch 27 | service elasticsearch start 28 | } 29 | 30 | function install_es_plugins { 31 | ESVersion=$(/usr/share/elasticsearch/bin/elasticsearch -V|awk -F',' '{print $1}'| awk '{print $2}') 32 | 33 | [[ -e /usr/share/elasticsearch/plugins/analysis-ik ]] || { 34 | /usr/share/elasticsearch/bin/elasticsearch-plugin install --batch https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v${ESVersion}/elasticsearch-analysis-ik-${ESVersion}.zip 35 | } 36 | mkdir -p /etc/elasticsearch/analysis/ 37 | touch /etc/elasticsearch/analysis/synonyms.txt 38 | 39 | service elasticsearch restart 40 | } 41 | 42 | call_function install_java "正在安装 JAVA" ${LOG_PATH} 43 | call_function install_es "正在安装 Elasticsearch ${VERSION}" ${LOG_PATH} 44 | call_function install_es_plugins "正在安装 Elasticsearch 插件" ${LOG_PATH} 45 | 46 | ansi --green --bold -n "安装完毕" 47 | -------------------------------------------------------------------------------- /18.04/mysql_add_user.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 4 | source ${CURRENT_DIR}/../common/common.sh 5 | 6 | read -r -p "请输入 Mysql root 密码:" MYSQL_ROOT_PASSWORD 7 | 8 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "quit" >> ${LOG_PATH} 2>&1 || { 9 | ansi -n --bold --bg-red "密码不正确" 10 | exit 1 11 | } 12 | 13 | read -r -p "请输入要新建的用户名:" MYSQL_NORMAL_USER 14 | 15 | [[ $MYSQL_NORMAL_USER =~ ^[a-zA-Z\0-9_\-]+$ ]] || { 16 | ansi -n --bold --bg-red "用户名包含非法字符" 17 | exit 1 18 | } 19 | 20 | MYSQL_NORMAL_USER_PASSWORD=`random_string` 21 | 22 | read -r -p "是否创建同名数据库并赋予权限?[y/N] " response 23 | case "$response" in 24 | [yY][eE][sS]|[yY]) 25 | CREATE_DB=1 26 | ;; 27 | *) 28 | CREATE_DB=0 29 | ;; 30 | esac 31 | 32 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "CREATE USER '${MYSQL_NORMAL_USER}' IDENTIFIED BY '${MYSQL_NORMAL_USER_PASSWORD}';" >> ${LOG_PATH} 2>&1 33 | 34 | ansi -n --bold --green "用户创建成功"; 35 | 36 | ansi --green --bold "用户名:"; ansi -n --bg-yellow --black ${MYSQL_NORMAL_USER} 37 | ansi --green --bold "密码:"; ansi -n --bg-yellow --black ${MYSQL_NORMAL_USER_PASSWORD} 38 | 39 | if [[ CREATE_DB -eq 1 ]]; then 40 | DATABASE_NAME=${MYSQL_NORMAL_USER} 41 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "CREATE DATABASE \`${DATABASE_NAME}\`;" >> ${LOG_PATH} 2>&1 42 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "GRANT ALL ON \`${DATABASE_NAME}\`.* TO '${MYSQL_NORMAL_USER}';" >> ${LOG_PATH} 2>&1 43 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "FLUSH PRIVILEGES;" >> ${LOG_PATH} 2>&1 44 | fi 45 | 46 | ansi -n --bold --green "数据库 ${DATABASE_NAME} 创建成功"; 47 | -------------------------------------------------------------------------------- /18.04/nginx_add_site.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 4 | source ${CURRENT_DIR}/../common/common.sh 5 | 6 | [ $(id -u) != "0" ] && { ansi -n --bold --bg-red "请用 root 账户执行本脚本"; exit 1; } 7 | 8 | read -r -p "请输入项目名:" project 9 | 10 | [[ $project =~ ^[a-zA-Z\0-9_\-\.]+$ ]] || { 11 | ansi -n --bold --bg-red "项目名包含非法字符" 12 | exit 1 13 | } 14 | 15 | read -r -p "请输入站点域名(多个域名用空格隔开):" domains 16 | 17 | project_dir="/var/www/${project}" 18 | 19 | ansi -n --bold --green "域名列表:${domains}" 20 | ansi -n --bold --green "项目名:${project}" 21 | ansi -n --bold --green "项目目录:${project_dir}" 22 | 23 | read -r -p "是否确认? [y/N] " response 24 | case "$response" in 25 | [yY][eE][sS]|[yY]) 26 | ;; 27 | *) 28 | ansi -n --bold --bg-red "用户取消" 29 | exit 1 30 | ;; 31 | esac 32 | 33 | cat ${CURRENT_DIR}/nginx_site_conf.tpl | 34 | sed "s|{{domains}}|${domains}|g" | 35 | sed "s|{{project}}|${project}|g" | 36 | sed "s|{{project_dir}}|${project_dir}|g" > /etc/nginx/sites-available/${project}.conf 37 | 38 | ln -sf /etc/nginx/sites-available/${project}.conf /etc/nginx/sites-enabled/${project}.conf 39 | 40 | ansi -n --bold --green "配置文件创建成功"; 41 | 42 | mkdir -p ${project_dir} && chown -R ${WWW_USER}.${WWW_USER_GROUP} ${project_dir} 43 | 44 | systemctl restart nginx.service 45 | 46 | ansi -n --bold --green "Nginx 重启成功"; 47 | -------------------------------------------------------------------------------- /18.04/nginx_site_conf.tpl: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | server_name {{domains}}; 4 | root "{{project_dir}}/public"; 5 | 6 | index index.html index.htm index.php; 7 | 8 | charset utf-8; 9 | 10 | location / { 11 | try_files $uri $uri/ /index.php?$query_string; 12 | } 13 | 14 | location = /favicon.ico { access_log off; log_not_found off; } 15 | location = /robots.txt { access_log off; log_not_found off; } 16 | 17 | access_log /var/log/nginx/{{project}}.log; 18 | error_log /var/log/nginx/{{project}}-error.log error; 19 | 20 | sendfile off; 21 | 22 | client_max_body_size 100m; 23 | 24 | location ~ \.php$ { 25 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 26 | fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; 27 | fastcgi_index index.php; 28 | include fastcgi_params; 29 | fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 30 | fastcgi_param DOCUMENT_ROOT $realpath_root; 31 | 32 | fastcgi_intercept_errors off; 33 | fastcgi_buffer_size 16k; 34 | fastcgi_buffers 4 16k; 35 | fastcgi_connect_timeout 300; 36 | fastcgi_send_timeout 300; 37 | fastcgi_read_timeout 300; 38 | } 39 | 40 | location ~ /\.ht { 41 | deny all; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /20.04/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 5 | source ${CURRENT_DIR}/../common/common.sh 6 | 7 | [ $(id -u) != "0" ] && { ansi -n --bold --bg-red "请用 root 账户执行本脚本"; exit 1; } 8 | 9 | MYSQL_ROOT_PASSWORD=`random_string` 10 | 11 | function init_system { 12 | export LC_ALL="en_US.UTF-8" 13 | echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale 14 | locale-gen en_US.UTF-8 15 | locale-gen zh_CN.UTF-8 16 | 17 | ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 18 | 19 | apt-get update 20 | apt-get install -y software-properties-common 21 | 22 | init_alias 23 | } 24 | 25 | function init_alias { 26 | alias sudowww > /dev/null 2>&1 || { 27 | echo "alias sudowww='sudo -H -u ${WWW_USER} sh -c'" >> ~/.bash_aliases 28 | } 29 | } 30 | 31 | function init_repositories { 32 | add-apt-repository -y ppa:ondrej/php 33 | add-apt-repository -y ppa:nginx/stable 34 | grep -rl ppa.launchpad.net /etc/apt/sources.list.d/ | xargs sed -i 's/http:\/\/ppa.launchpad.net/https:\/\/launchpad.proxy.ustclug.org/g' 35 | 36 | curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - 37 | echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list 38 | 39 | # https://mirrors.tuna.tsinghua.edu.cn/ 2021-02-05移除 nodesource 镜像 40 | 41 | curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - 42 | echo 'deb https://deb.nodesource.com/node_10.x focal main' > /etc/apt/sources.list.d/nodesource.list 43 | echo 'deb-src https://deb.nodesource.com/node_10.x focal main' >> /etc/apt/sources.list.d/nodesource.list 44 | 45 | apt-get update 46 | } 47 | 48 | function install_basic_softwares { 49 | apt-get install -y curl git build-essential unzip supervisor 50 | } 51 | 52 | function install_node_yarn { 53 | apt-get install -y nodejs yarn 54 | sudo -H -u ${WWW_USER} sh -c 'cd ~ && yarn config set registry https://registry.npm.taobao.org' 55 | } 56 | 57 | function install_php { 58 | apt-get install -y php7.4-bcmath php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-pgsql php7.4-readline php7.4-xml php7.4-zip php7.4-sqlite3 php7.4-redis 59 | } 60 | 61 | function install_others { 62 | apt-get remove -y apache2 63 | debconf-set-selections <<< "mysql-server mysql-server/root_password password ${MYSQL_ROOT_PASSWORD}" 64 | debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQL_ROOT_PASSWORD}" 65 | apt-get install -y nginx mysql-server redis-server memcached beanstalkd sqlite3 66 | chown -R ${WWW_USER}.${WWW_USER_GROUP} /var/www/ 67 | systemctl enable nginx.service 68 | } 69 | 70 | function install_composer { 71 | curl https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer 72 | chmod +x /usr/local/bin/composer 73 | sudo -H -u ${WWW_USER} sh -c 'cd ~ && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/' 74 | } 75 | 76 | call_function init_system "正在初始化系统" ${LOG_PATH} 77 | call_function init_repositories "正在初始化软件源" ${LOG_PATH} 78 | call_function install_basic_softwares "正在安装基础软件" ${LOG_PATH} 79 | call_function install_php "正在安装 PHP" ${LOG_PATH} 80 | call_function install_others "正在安装 Mysql / Nginx / Redis / Memcached / Beanstalkd / Sqlite3" ${LOG_PATH} 81 | call_function install_node_yarn "正在安装 Nodejs / Yarn" ${LOG_PATH} 82 | call_function install_composer "正在安装 Composer" ${LOG_PATH} 83 | 84 | ansi --green --bold -n "安装完毕" 85 | ansi --green --bold "Mysql root 密码:"; ansi -n --bold --bg-yellow --black ${MYSQL_ROOT_PASSWORD} 86 | ansi --green --bold -n "请手动执行 source ~/.bash_aliases 使 alias 指令生效。" 87 | -------------------------------------------------------------------------------- /20.04/install_elasticsearch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 4 | source ${CURRENT_DIR}/../common/common.sh 5 | 6 | VERSION=$1 7 | VERSION=${VERSION:-6} 8 | 9 | [ $(id -u) != "0" ] && { ansi -n --bold --bg-red "请用 root 账户执行本脚本"; exit 1; } 10 | 11 | # 设置 JAVA_HOME 12 | export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-openjdk-amd64/bin:/usr/lib/jvm/java-8-openjdk-amd64/db/bin:/usr/lib/jvm/java-8-openjdk-amd64/jre/bin" 13 | export J2SDKDIR="/usr/lib/jvm/java-8-openjdk-amd64" 14 | export J2REDIR="/usr/lib/jvm/java-8-openjdk-amd64/jre*" 15 | export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64" 16 | export DERBY_HOME="/usr/lib/jvm/java-8-openjdk-amd64/db" 17 | 18 | function install_java { 19 | apt-get install -y openjdk-8-jre 20 | } 21 | 22 | function install_es { 23 | curl -sS https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - 24 | echo "deb https://mirrors.tuna.tsinghua.edu.cn/elasticstack/${VERSION}.x/apt stable main" > /etc/apt/sources.list.d/elastic-${VERSION}.x.list 25 | apt-get update 26 | apt-get install -y elasticsearch 27 | service elasticsearch start 28 | } 29 | 30 | function install_es_plugins { 31 | ESVersion=$(/usr/share/elasticsearch/bin/elasticsearch -V|awk -F',' '{print $1}'| awk '{print $2}') 32 | 33 | [[ -e /usr/share/elasticsearch/plugins/analysis-ik ]] || { 34 | /usr/share/elasticsearch/bin/elasticsearch-plugin install --batch https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v${ESVersion}/elasticsearch-analysis-ik-${ESVersion}.zip 35 | } 36 | mkdir -p /etc/elasticsearch/analysis/ 37 | touch /etc/elasticsearch/analysis/synonyms.txt 38 | 39 | service elasticsearch restart 40 | } 41 | 42 | call_function install_java "正在安装 JAVA" ${LOG_PATH} 43 | call_function install_es "正在安装 Elasticsearch ${VERSION}" ${LOG_PATH} 44 | call_function install_es_plugins "正在安装 Elasticsearch 插件" ${LOG_PATH} 45 | 46 | ansi --green --bold -n "安装完毕" 47 | -------------------------------------------------------------------------------- /20.04/mysql_add_user.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 4 | source ${CURRENT_DIR}/../common/common.sh 5 | 6 | read -r -p "请输入 Mysql root 密码:" MYSQL_ROOT_PASSWORD 7 | 8 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "quit" >> ${LOG_PATH} 2>&1 || { 9 | ansi -n --bold --bg-red "密码不正确" 10 | exit 1 11 | } 12 | 13 | read -r -p "请输入要新建的用户名:" MYSQL_NORMAL_USER 14 | 15 | [[ $MYSQL_NORMAL_USER =~ ^[a-zA-Z\0-9_\-]+$ ]] || { 16 | ansi -n --bold --bg-red "用户名包含非法字符" 17 | exit 1 18 | } 19 | 20 | MYSQL_NORMAL_USER_PASSWORD=`random_string` 21 | 22 | read -r -p "是否创建同名数据库并赋予权限?[y/N] " response 23 | case "$response" in 24 | [yY][eE][sS]|[yY]) 25 | CREATE_DB=1 26 | ;; 27 | *) 28 | CREATE_DB=0 29 | ;; 30 | esac 31 | 32 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "CREATE USER '${MYSQL_NORMAL_USER}' IDENTIFIED BY '${MYSQL_NORMAL_USER_PASSWORD}';" >> ${LOG_PATH} 2>&1 33 | 34 | ansi -n --bold --green "用户创建成功"; 35 | 36 | ansi --green --bold "用户名:"; ansi -n --bg-yellow --black ${MYSQL_NORMAL_USER} 37 | ansi --green --bold "密码:"; ansi -n --bg-yellow --black ${MYSQL_NORMAL_USER_PASSWORD} 38 | 39 | if [[ CREATE_DB -eq 1 ]]; then 40 | DATABASE_NAME=${MYSQL_NORMAL_USER} 41 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "CREATE DATABASE \`${DATABASE_NAME}\`;" >> ${LOG_PATH} 2>&1 42 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "GRANT ALL ON \`${DATABASE_NAME}\`.* TO '${MYSQL_NORMAL_USER}';" >> ${LOG_PATH} 2>&1 43 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "FLUSH PRIVILEGES;" >> ${LOG_PATH} 2>&1 44 | fi 45 | 46 | ansi -n --bold --green "数据库 ${DATABASE_NAME} 创建成功"; 47 | -------------------------------------------------------------------------------- /20.04/nginx_add_site.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 4 | source ${CURRENT_DIR}/../common/common.sh 5 | 6 | [ $(id -u) != "0" ] && { ansi -n --bold --bg-red "请用 root 账户执行本脚本"; exit 1; } 7 | 8 | read -r -p "请输入项目名:" project 9 | 10 | [[ $project =~ ^[a-zA-Z\0-9_\-\.]+$ ]] || { 11 | ansi -n --bold --bg-red "项目名包含非法字符" 12 | exit 1 13 | } 14 | 15 | read -r -p "请输入站点域名(多个域名用空格隔开):" domains 16 | 17 | project_dir="/var/www/${project}" 18 | 19 | ansi -n --bold --green "域名列表:${domains}" 20 | ansi -n --bold --green "项目名:${project}" 21 | ansi -n --bold --green "项目目录:${project_dir}" 22 | 23 | read -r -p "是否确认? [y/N] " response 24 | case "$response" in 25 | [yY][eE][sS]|[yY]) 26 | ;; 27 | *) 28 | ansi -n --bold --bg-red "用户取消" 29 | exit 1 30 | ;; 31 | esac 32 | 33 | cat ${CURRENT_DIR}/nginx_site_conf.tpl | 34 | sed "s|{{domains}}|${domains}|g" | 35 | sed "s|{{project}}|${project}|g" | 36 | sed "s|{{project_dir}}|${project_dir}|g" > /etc/nginx/sites-available/${project}.conf 37 | 38 | ln -sf /etc/nginx/sites-available/${project}.conf /etc/nginx/sites-enabled/${project}.conf 39 | 40 | ansi -n --bold --green "配置文件创建成功"; 41 | 42 | mkdir -p ${project_dir} && chown -R ${WWW_USER}.${WWW_USER_GROUP} ${project_dir} 43 | 44 | systemctl restart nginx.service 45 | 46 | ansi -n --bold --green "Nginx 重启成功"; 47 | -------------------------------------------------------------------------------- /20.04/nginx_site_conf.tpl: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | server_name {{domains}}; 4 | root "{{project_dir}}/public"; 5 | 6 | index index.html index.htm index.php; 7 | 8 | charset utf-8; 9 | 10 | location / { 11 | try_files $uri $uri/ /index.php?$query_string; 12 | } 13 | 14 | location = /favicon.ico { access_log off; log_not_found off; } 15 | location = /robots.txt { access_log off; log_not_found off; } 16 | 17 | access_log /var/log/nginx/{{project}}.log; 18 | error_log /var/log/nginx/{{project}}-error.log error; 19 | 20 | sendfile off; 21 | 22 | client_max_body_size 100m; 23 | 24 | location ~ \.php$ { 25 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 26 | fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; 27 | fastcgi_index index.php; 28 | include fastcgi_params; 29 | fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 30 | fastcgi_param DOCUMENT_ROOT $realpath_root; 31 | 32 | fastcgi_intercept_errors off; 33 | fastcgi_buffer_size 16k; 34 | fastcgi_buffers 4 16k; 35 | fastcgi_connect_timeout 300; 36 | fastcgi_send_timeout 300; 37 | fastcgi_read_timeout 300; 38 | } 39 | 40 | location ~ /\.ht { 41 | deny all; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /22.04/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 5 | source ${CURRENT_DIR}/../common/common.sh 6 | 7 | [ $(id -u) != "0" ] && { ansi -n --bold --bg-red "请用 root 账户执行本脚本"; exit 1; } 8 | 9 | MYSQL_ROOT_PASSWORD=`random_string` 10 | 11 | function init_system { 12 | export LC_ALL="en_US.UTF-8" 13 | echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale 14 | locale-gen en_US.UTF-8 15 | locale-gen zh_CN.UTF-8 16 | 17 | ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 18 | 19 | apt-get update 20 | apt-get install -y software-properties-common 21 | 22 | init_alias 23 | } 24 | 25 | function init_alias { 26 | alias sudowww > /dev/null 2>&1 || { 27 | echo "alias sudowww='sudo -H -u ${WWW_USER} sh -c'" >> ~/.bash_aliases 28 | } 29 | } 30 | 31 | function init_repositories { 32 | add-apt-repository -y ppa:ondrej/php 33 | add-apt-repository -y ppa:ondrej/nginx-mainline 34 | grep -rl ppa.launchpad.net /etc/apt/sources.list.d/ | xargs sed -i 's/http:\/\/ppa.launchpad.net/https:\/\/launchpad.proxy.ustclug.org/g' 35 | 36 | curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - 37 | echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list 38 | 39 | # https://mirrors.tuna.tsinghua.edu.cn/ 2021-02-05移除 nodesource 镜像 40 | 41 | curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - 42 | echo 'deb https://deb.nodesource.com/node_10.x focal main' > /etc/apt/sources.list.d/nodesource.list 43 | echo 'deb-src https://deb.nodesource.com/node_10.x focal main' >> /etc/apt/sources.list.d/nodesource.list 44 | 45 | apt-get update 46 | } 47 | 48 | function install_basic_softwares { 49 | apt-get install -y curl git build-essential unzip supervisor 50 | } 51 | 52 | function install_node_yarn { 53 | apt-get install -y nodejs yarn 54 | sudo -H -u ${WWW_USER} sh -c 'cd ~ && yarn config set registry https://registry.npm.taobao.org' 55 | } 56 | 57 | function install_php { 58 | apt-get install -y php8.2-bcmath php8.2-cli php8.2-curl php8.2-fpm php8.2-gd php8.2-mbstring php8.2-mysql php8.2-opcache php8.2-pgsql php8.2-readline php8.2-xml php8.2-zip php8.2-sqlite3 php8.2-redis php8.2-imagick 59 | } 60 | 61 | function install_others { 62 | apt-get remove -y apache2 63 | debconf-set-selections <<< "mysql-server mysql-server/root_password password ${MYSQL_ROOT_PASSWORD}" 64 | debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQL_ROOT_PASSWORD}" 65 | apt-get install -y nginx mysql-server redis-server memcached beanstalkd sqlite3 66 | chown -R ${WWW_USER}.${WWW_USER_GROUP} /var/www/ 67 | systemctl enable nginx.service 68 | } 69 | 70 | function install_composer { 71 | curl https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer 72 | chmod +x /usr/local/bin/composer 73 | sudo -H -u ${WWW_USER} sh -c 'cd ~ && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/' 74 | } 75 | 76 | call_function init_system "正在初始化系统" ${LOG_PATH} 77 | call_function init_repositories "正在初始化软件源" ${LOG_PATH} 78 | call_function install_basic_softwares "正在安装基础软件" ${LOG_PATH} 79 | call_function install_php "正在安装 PHP" ${LOG_PATH} 80 | call_function install_others "正在安装 Mysql / Nginx / Redis / Memcached / Beanstalkd / Sqlite3" ${LOG_PATH} 81 | call_function install_node_yarn "正在安装 Nodejs / Yarn" ${LOG_PATH} 82 | call_function install_composer "正在安装 Composer" ${LOG_PATH} 83 | 84 | ansi --green --bold -n "安装完毕" 85 | ansi --green --bold "Mysql root 密码:"; ansi -n --bold --bg-yellow --black ${MYSQL_ROOT_PASSWORD} 86 | ansi --green --bold -n "请手动执行 source ~/.bash_aliases 使 alias 指令生效。" 87 | -------------------------------------------------------------------------------- /22.04/install_elasticsearch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 4 | source ${CURRENT_DIR}/../common/common.sh 5 | 6 | VERSION=$1 7 | VERSION=${VERSION:-6} 8 | 9 | [ $(id -u) != "0" ] && { ansi -n --bold --bg-red "请用 root 账户执行本脚本"; exit 1; } 10 | 11 | # 设置 JAVA_HOME 12 | export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-openjdk-amd64/bin:/usr/lib/jvm/java-8-openjdk-amd64/db/bin:/usr/lib/jvm/java-8-openjdk-amd64/jre/bin" 13 | export J2SDKDIR="/usr/lib/jvm/java-8-openjdk-amd64" 14 | export J2REDIR="/usr/lib/jvm/java-8-openjdk-amd64/jre*" 15 | export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64" 16 | export DERBY_HOME="/usr/lib/jvm/java-8-openjdk-amd64/db" 17 | 18 | function install_java { 19 | apt-get install -y openjdk-8-jre 20 | } 21 | 22 | function install_es { 23 | curl -sS https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - 24 | echo "deb https://mirrors.tuna.tsinghua.edu.cn/elasticstack/${VERSION}.x/apt stable main" > /etc/apt/sources.list.d/elastic-${VERSION}.x.list 25 | apt-get update 26 | apt-get install -y elasticsearch 27 | service elasticsearch start 28 | } 29 | 30 | function install_es_plugins { 31 | ESVersion=$(/usr/share/elasticsearch/bin/elasticsearch -V|awk -F',' '{print $1}'| awk '{print $2}') 32 | 33 | [[ -e /usr/share/elasticsearch/plugins/analysis-ik ]] || { 34 | /usr/share/elasticsearch/bin/elasticsearch-plugin install --batch https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v${ESVersion}/elasticsearch-analysis-ik-${ESVersion}.zip 35 | } 36 | mkdir -p /etc/elasticsearch/analysis/ 37 | touch /etc/elasticsearch/analysis/synonyms.txt 38 | 39 | service elasticsearch restart 40 | } 41 | 42 | call_function install_java "正在安装 JAVA" ${LOG_PATH} 43 | call_function install_es "正在安装 Elasticsearch ${VERSION}" ${LOG_PATH} 44 | call_function install_es_plugins "正在安装 Elasticsearch 插件" ${LOG_PATH} 45 | 46 | ansi --green --bold -n "安装完毕" 47 | -------------------------------------------------------------------------------- /22.04/mysql_add_user.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 4 | source ${CURRENT_DIR}/../common/common.sh 5 | 6 | read -r -p "请输入 Mysql root 密码:" MYSQL_ROOT_PASSWORD 7 | 8 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "quit" >> ${LOG_PATH} 2>&1 || { 9 | ansi -n --bold --bg-red "密码不正确" 10 | exit 1 11 | } 12 | 13 | read -r -p "请输入要新建的用户名:" MYSQL_NORMAL_USER 14 | 15 | [[ $MYSQL_NORMAL_USER =~ ^[a-zA-Z\0-9_\-]+$ ]] || { 16 | ansi -n --bold --bg-red "用户名包含非法字符" 17 | exit 1 18 | } 19 | 20 | MYSQL_NORMAL_USER_PASSWORD=`random_string` 21 | 22 | read -r -p "是否创建同名数据库并赋予权限?[y/N] " response 23 | case "$response" in 24 | [yY][eE][sS]|[yY]) 25 | CREATE_DB=1 26 | ;; 27 | *) 28 | CREATE_DB=0 29 | ;; 30 | esac 31 | 32 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "CREATE USER '${MYSQL_NORMAL_USER}' IDENTIFIED BY '${MYSQL_NORMAL_USER_PASSWORD}';" >> ${LOG_PATH} 2>&1 33 | 34 | ansi -n --bold --green "用户创建成功"; 35 | 36 | ansi --green --bold "用户名:"; ansi -n --bg-yellow --black ${MYSQL_NORMAL_USER} 37 | ansi --green --bold "密码:"; ansi -n --bg-yellow --black ${MYSQL_NORMAL_USER_PASSWORD} 38 | 39 | if [[ CREATE_DB -eq 1 ]]; then 40 | DATABASE_NAME=${MYSQL_NORMAL_USER} 41 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "CREATE DATABASE \`${DATABASE_NAME}\`;" >> ${LOG_PATH} 2>&1 42 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "GRANT ALL ON \`${DATABASE_NAME}\`.* TO '${MYSQL_NORMAL_USER}';" >> ${LOG_PATH} 2>&1 43 | mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "FLUSH PRIVILEGES;" >> ${LOG_PATH} 2>&1 44 | fi 45 | 46 | ansi -n --bold --green "数据库 ${DATABASE_NAME} 创建成功"; 47 | -------------------------------------------------------------------------------- /22.04/nginx_add_site.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 4 | source ${CURRENT_DIR}/../common/common.sh 5 | 6 | [ $(id -u) != "0" ] && { ansi -n --bold --bg-red "请用 root 账户执行本脚本"; exit 1; } 7 | 8 | read -r -p "请输入项目名:" project 9 | 10 | [[ $project =~ ^[a-zA-Z\0-9_\-\.]+$ ]] || { 11 | ansi -n --bold --bg-red "项目名包含非法字符" 12 | exit 1 13 | } 14 | 15 | read -r -p "请输入站点域名(多个域名用空格隔开):" domains 16 | 17 | project_dir="/var/www/${project}" 18 | 19 | ansi -n --bold --green "域名列表:${domains}" 20 | ansi -n --bold --green "项目名:${project}" 21 | ansi -n --bold --green "项目目录:${project_dir}" 22 | 23 | read -r -p "是否确认? [y/N] " response 24 | case "$response" in 25 | [yY][eE][sS]|[yY]) 26 | ;; 27 | *) 28 | ansi -n --bold --bg-red "用户取消" 29 | exit 1 30 | ;; 31 | esac 32 | 33 | cat ${CURRENT_DIR}/nginx_site_conf.tpl | 34 | sed "s|{{domains}}|${domains}|g" | 35 | sed "s|{{project}}|${project}|g" | 36 | sed "s|{{project_dir}}|${project_dir}|g" > /etc/nginx/sites-available/${project}.conf 37 | 38 | ln -sf /etc/nginx/sites-available/${project}.conf /etc/nginx/sites-enabled/${project}.conf 39 | 40 | ansi -n --bold --green "配置文件创建成功"; 41 | 42 | mkdir -p ${project_dir} && chown -R ${WWW_USER}.${WWW_USER_GROUP} ${project_dir} 43 | 44 | systemctl restart nginx.service 45 | 46 | ansi -n --bold --green "Nginx 重启成功"; 47 | -------------------------------------------------------------------------------- /22.04/nginx_site_conf.tpl: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | server_name {{domains}}; 4 | root "{{project_dir}}/public"; 5 | 6 | index index.html index.htm index.php; 7 | 8 | charset utf-8; 9 | 10 | location / { 11 | try_files $uri $uri/ /index.php?$query_string; 12 | } 13 | 14 | location = /favicon.ico { access_log off; log_not_found off; } 15 | location = /robots.txt { access_log off; log_not_found off; } 16 | 17 | access_log /var/log/nginx/{{project}}.log; 18 | error_log /var/log/nginx/{{project}}-error.log error; 19 | 20 | sendfile off; 21 | 22 | client_max_body_size 100m; 23 | 24 | location ~ \.php$ { 25 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 26 | fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; 27 | fastcgi_index index.php; 28 | include fastcgi_params; 29 | fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 30 | fastcgi_param DOCUMENT_ROOT $realpath_root; 31 | 32 | fastcgi_intercept_errors off; 33 | fastcgi_buffer_size 16k; 34 | fastcgi_buffers 4 16k; 35 | fastcgi_connect_timeout 300; 36 | fastcgi_send_timeout 300; 37 | fastcgi_read_timeout 300; 38 | } 39 | 40 | location ~ /\.ht { 41 | deny all; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /common/ansi.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # ANSI code generator 4 | # 5 | # © Copyright 2015 Tyler Akins 6 | # Licensed under the MIT license with an additional non-advertising clause 7 | # See http://github.com/fidian/ansi 8 | 9 | ansi::addCode() { 10 | local N 11 | 12 | if [[ "$1" == *=* ]]; then 13 | N="${1#*=}" 14 | N="${N//,/;}" 15 | else 16 | N="" 17 | fi 18 | 19 | OUTPUT="$OUTPUT$CSI$N$2" 20 | } 21 | 22 | ansi::addColor() { 23 | OUTPUT="$OUTPUT$CSI${1}m" 24 | 25 | if [ ! -z "$2" ]; then 26 | SUFFIX="$CSI${2}m$SUFFIX" 27 | fi 28 | } 29 | 30 | ansi::colorTable() { 31 | local FNB_LOWER FNB_UPPER PADDED 32 | 33 | FNB_LOWER="$(ansi::colorize 2 22 f)n$(ansi::colorize 1 22 b)" 34 | FNB_UPPER="$(ansi::colorize 2 22 F)N$(ansi::colorize 1 22 B)" 35 | printf 'bold %s ' "$(ansi::colorize 1 22 Sample)" 36 | printf 'faint %s ' "$(ansi::colorize 2 22 Sample)" 37 | printf 'italic %s\n' "$(ansi::colorize 3 23 Sample)" 38 | printf 'underline %s ' "$(ansi::colorize 4 24 Sample)" 39 | printf 'blink %s ' "$(ansi::colorize 5 25 Sample)" 40 | printf 'inverse %s\n' "$(ansi::colorize 7 27 Sample)" 41 | printf 'invisible %s\n' "$(ansi::colorize 8 28 Sample)" 42 | printf 'strike %s ' "$(ansi::colorize 9 29 Sample)" 43 | printf 'fraktur %s ' "$(ansi::colorize 20 23 Sample)" 44 | printf 'double-underline%s\n' "$(ansi::colorize 21 24 Sample)" 45 | printf 'frame %s ' "$(ansi::colorize 51 54 Sample)" 46 | printf 'encircle %s ' "$(ansi::colorize 52 54 Sample)" 47 | printf 'overline%s\n' "$(ansi::colorize 53 55 Sample)" 48 | printf '\n' 49 | printf ' black red green yellow blue magenta cyan white\n' 50 | for BG in 40:black 41:red 42:green 43:yellow 44:blue 45:magenta 46:cyan 47:white xx:no-bg; do 51 | PADDED="bg-${BG:3} " 52 | PADDED="${PADDED:0:13}" 53 | printf '%s' "$PADDED" 54 | BG=${BG:0:2} 55 | if [[ "$BG" == "xx" ]]; then 56 | BG="" 57 | fi 58 | for FG in 30 31 32 33 34 35 36 37; do 59 | printf '%s%s;%sm' "$CSI" "$BG" "${FG}" 60 | printf '%s' "$FNB_LOWER" 61 | printf '%s%sm' "$CSI" "$(( FG + 60 ))" 62 | printf '%s' "$FNB_UPPER" 63 | printf '%s0m ' "${CSI}" 64 | done 65 | printf '\n' 66 | if [[ -n "$BG" ]]; then 67 | printf ' +intense ' 68 | for FG in 30 31 32 33 34 35 36 37; do 69 | printf '%s%s;%sm' "$CSI" "$(( BG + 60 ))" "${FG}" 70 | printf '%s' "$FNB_LOWER" 71 | printf '%s%sm' "$CSI" "$(( FG + 60 ))" 72 | printf '%s' "$FNB_UPPER" 73 | printf '%s0m ' "${CSI}" 74 | done 75 | printf '\n' 76 | fi 77 | done 78 | printf '\n' 79 | printf 'Legend:\n' 80 | printf ' Normal color: f = faint, n = normal, b = bold.\n' 81 | printf ' Intense color: F = faint, N = normal, B = bold.\n' 82 | } 83 | 84 | ansi::colorize() { 85 | printf '%s%sm%s%s%sm' "$CSI" "$1" "$3" "$CSI" "$2" 86 | } 87 | 88 | ansi::isAnsiSupported() { 89 | local cont c str 90 | 91 | if ! test -t 1; then 92 | # stdout is not a terminal 93 | return 1 94 | fi 95 | 96 | if hash tput &> /dev/null; then 97 | if [[ "$(tput colors)" -lt 8 ]]; then 98 | return 1 99 | fi 100 | 101 | return 0 102 | fi 103 | 104 | # Query the console and see if we get ANSI codes back. 105 | # CSI 0 c == CSI c == Primary Device Attributes. 106 | # Idea: CSI c 107 | # Response = CSI ? 6 [234] ; 2 2 c 108 | # The "22" means ANSI color, but terminals don't need to send that back. 109 | printf "%s0c" "$CSI" 110 | str= 111 | cont=true 112 | 113 | while $cont && read -n 1 -s -t 0.1 c; do 114 | if [[ -n "$c" ]]; then 115 | str+=$c 116 | else 117 | cont=false 118 | fi 119 | done 120 | 121 | set | grep ^str= 122 | 123 | # If we get anything back, the terminal is consuming the color codes and 124 | # will probably do its best. Let's assume there's color. 125 | [[ "$str" == "$CSI?6"[234]";"* ]] 126 | } 127 | 128 | ansi::report() { 129 | local BUFF C 130 | 131 | REPORT="" 132 | printf "%s%s" "$CSI" "$1" 133 | read -r -N ${#2} -s -t 1 BUFF 134 | 135 | if [ "$BUFF" != "$2" ]; then 136 | return 1 137 | fi 138 | 139 | read -r -N ${#3} -s -t 1 BUFF 140 | 141 | while [ "$BUFF" != "$3" ]; do 142 | REPORT="$REPORT${BUFF:0:1}" 143 | read -r -N 1 -s -t 1 C || exit 1 144 | BUFF="${BUFF:1}$C" 145 | done 146 | } 147 | 148 | ansi::showHelp() { 149 | cat < ${desc}..." 15 | $func >> ${log_file} 2>&1 16 | ret=$? 17 | echo -n ' [' 18 | if [[ $ret -eq 0 ]]; then 19 | ansi --bold --green "DONE" 20 | else 21 | ansi --bold --red "ERROR" 22 | fi 23 | echo ']' 24 | } 25 | 26 | random_string(){ 27 | length=${1:-32} 28 | echo `cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${length} | head -n 1` 29 | } 30 | -------------------------------------------------------------------------------- /download.16.04.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | { # this ensures the entire script is downloaded # 4 | 5 | lsb_release -d | grep 'Ubuntu' >& /dev/null 6 | [[ $? -ne 0 ]] && { echo "仅支持 Ubuntu 16.04 系统"; exit 1; } 7 | 8 | DISTRO=$(lsb_release -c -s) 9 | [[ ${DISTRO} -ne "xenial" ]] && { echo "仅支持 Ubuntu 16.04 系统"; exit 1; } 10 | 11 | green="\e[1;32m" 12 | nc="\e[0m" 13 | 14 | echo -e "${green}===> 开始下载...${nc}" 15 | cd $HOME 16 | wget -q https://github.com/summerblue/laravel-ubuntu-init/archive/master.tar.gz -O laravel-ubuntu-init.tar.gz 17 | rm -rf laravel-ubuntu-init 18 | tar zxf laravel-ubuntu-init.tar.gz 19 | mv laravel-ubuntu-init-master laravel-ubuntu-init 20 | rm -f laravel-ubuntu-init.tar.gz 21 | echo -e "${green}===> 下载完毕${nc}" 22 | echo "" 23 | echo -e "${green}安装脚本位于: ${HOME}/laravel-ubuntu-init${nc}" 24 | 25 | [ $(id -u) != "0" ] && { 26 | source ${HOME}/laravel-ubuntu-init/common/ansi.sh 27 | ansi -n --bold --bg-yellow --black "当前账户并非 root,请用 root 账户执行安装脚本(使用命令:sudo -H -s 切换为 root)" 28 | } || { 29 | bash ./laravel-ubuntu-init/16.04/install.sh 30 | } 31 | 32 | cd - > /dev/null 33 | } # this ensures the entire script is downloaded # 34 | -------------------------------------------------------------------------------- /download.18.04.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | { # this ensures the entire script is downloaded # 4 | 5 | lsb_release -d | grep 'Ubuntu' >& /dev/null 6 | [[ $? -ne 0 ]] && { echo "仅支持 Ubuntu 18.04 系统"; exit 1; } 7 | 8 | DISTRO=$(lsb_release -c -s) 9 | [[ ${DISTRO} -ne "bionic" ]] && { echo "仅支持 Ubuntu 18.04 系统"; exit 1; } 10 | 11 | green="\e[1;32m" 12 | nc="\e[0m" 13 | 14 | echo -e "${green}===> 开始下载...${nc}" 15 | cd $HOME 16 | wget -q https://github.com/summerblue/laravel-ubuntu-init/archive/master.tar.gz -O laravel-ubuntu-init.tar.gz 17 | rm -rf laravel-ubuntu-init 18 | tar zxf laravel-ubuntu-init.tar.gz 19 | mv laravel-ubuntu-init-master laravel-ubuntu-init 20 | rm -f laravel-ubuntu-init.tar.gz 21 | echo -e "${green}===> 下载完毕${nc}" 22 | echo "" 23 | echo -e "${green}安装脚本位于: ${HOME}/laravel-ubuntu-init${nc}" 24 | 25 | [ $(id -u) != "0" ] && { 26 | source ${HOME}/laravel-ubuntu-init/common/ansi.sh 27 | ansi -n --bold --bg-yellow --black "当前账户并非 root,请用 root 账户执行安装脚本(使用命令:sudo -H -s 切换为 root)" 28 | } || { 29 | bash ./laravel-ubuntu-init/18.04/install.sh 30 | } 31 | 32 | cd - > /dev/null 33 | } # this ensures the entire script is downloaded # 34 | -------------------------------------------------------------------------------- /download.20.04.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | { # this ensures the entire script is downloaded # 4 | 5 | lsb_release -d | grep 'Ubuntu' >& /dev/null 6 | [[ $? -ne 0 ]] && { echo "仅支持 Ubuntu 20.04 系统"; exit 1; } 7 | 8 | DISTRO=$(lsb_release -c -s) 9 | [[ ${DISTRO} -ne "bionic" ]] && { echo "仅支持 Ubuntu 20.04 系统"; exit 1; } 10 | 11 | green="\e[1;32m" 12 | nc="\e[0m" 13 | 14 | echo -e "${green}===> 开始下载...${nc}" 15 | cd $HOME 16 | wget -q https://github.com/summerblue/laravel-ubuntu-init/archive/master.tar.gz -O laravel-ubuntu-init.tar.gz 17 | rm -rf laravel-ubuntu-init 18 | tar zxf laravel-ubuntu-init.tar.gz 19 | mv laravel-ubuntu-init-master laravel-ubuntu-init 20 | rm -f laravel-ubuntu-init.tar.gz 21 | echo -e "${green}===> 下载完毕${nc}" 22 | echo "" 23 | echo -e "${green}安装脚本位于: ${HOME}/laravel-ubuntu-init${nc}" 24 | 25 | [ $(id -u) != "0" ] && { 26 | source ${HOME}/laravel-ubuntu-init/common/ansi.sh 27 | ansi -n --bold --bg-yellow --black "当前账户并非 root,请用 root 账户执行安装脚本(使用命令:sudo -H -s 切换为 root)" 28 | } || { 29 | bash ./laravel-ubuntu-init/20.04/install.sh 30 | } 31 | 32 | cd - > /dev/null 33 | } # this ensures the entire script is downloaded # 34 | -------------------------------------------------------------------------------- /download.22.04.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | { # this ensures the entire script is downloaded # 4 | 5 | lsb_release -d | grep 'Ubuntu' >& /dev/null 6 | [[ $? -ne 0 ]] && { echo "仅支持 Ubuntu 22.04 系统"; exit 1; } 7 | 8 | DISTRO=$(lsb_release -c -s) 9 | [[ ${DISTRO} -ne "bionic" ]] && { echo "仅支持 Ubuntu 22.04 系统"; exit 1; } 10 | 11 | green="\e[1;32m" 12 | nc="\e[0m" 13 | 14 | echo -e "${green}===> 开始下载...${nc}" 15 | cd $HOME 16 | wget -q https://github.com/summerblue/laravel-ubuntu-init/archive/master.tar.gz -O laravel-ubuntu-init.tar.gz 17 | rm -rf laravel-ubuntu-init 18 | tar zxf laravel-ubuntu-init.tar.gz 19 | mv laravel-ubuntu-init-master laravel-ubuntu-init 20 | rm -f laravel-ubuntu-init.tar.gz 21 | echo -e "${green}===> 下载完毕${nc}" 22 | echo "" 23 | echo -e "${green}安装脚本位于: ${HOME}/laravel-ubuntu-init${nc}" 24 | 25 | [ $(id -u) != "0" ] && { 26 | source ${HOME}/laravel-ubuntu-init/common/ansi.sh 27 | ansi -n --bold --bg-yellow --black "当前账户并非 root,请用 root 账户执行安装脚本(使用命令:sudo -H -s 切换为 root)" 28 | } || { 29 | bash ./laravel-ubuntu-init/22.04/install.sh 30 | } 31 | 32 | cd - > /dev/null 33 | } # this ensures the entire script is downloaded # 34 | -------------------------------------------------------------------------------- /download.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | { # this ensures the entire script is downloaded # 4 | 5 | lsb_release -d | grep 'Ubuntu' >& /dev/null 6 | [[ $? -ne 0 ]] && { echo "仅支持 Ubuntu 16.04 系统"; exit 1; } 7 | 8 | DISTRO=$(lsb_release -c -s) 9 | [[ ${DISTRO} -ne "xenial" ]] && { echo "仅支持 Ubuntu 16.04 系统"; exit 1; } 10 | 11 | green="\e[1;32m" 12 | nc="\e[0m" 13 | 14 | echo -e "${green}===> 开始下载...${nc}" 15 | cd $HOME 16 | wget -q https://github.com/summerblue/laravel-ubuntu-init/archive/master.tar.gz -O laravel-ubuntu-init.tar.gz 17 | rm -rf laravel-ubuntu-init 18 | tar zxf laravel-ubuntu-init.tar.gz 19 | mv laravel-ubuntu-init-master laravel-ubuntu-init 20 | rm -f laravel-ubuntu-init.tar.gz 21 | echo -e "${green}===> 下载完毕${nc}" 22 | echo "" 23 | echo -e "${green}安装脚本位于: ${HOME}/laravel-ubuntu-init${nc}" 24 | 25 | [ $(id -u) != "0" ] && { 26 | source ${HOME}/laravel-ubuntu-init/common/ansi.sh 27 | ansi -n --bold --bg-yellow --black "当前账户并非 root,请用 root 账户执行安装脚本(使用命令:sudo -H -s 切换为 root)" 28 | } || { 29 | bash ./laravel-ubuntu-init/16.04/install.sh 30 | } 31 | 32 | cd - > /dev/null 33 | } # this ensures the entire script is downloaded # 34 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | 2 | ![group](https://cloud.githubusercontent.com/assets/324764/18408949/02d3cb2a-7770-11e6-96e2-54bbcfbfa1d1.png) 3 | 4 | ## 简介 5 | 6 | 适用于 Ubuntu 16.04 / 18.04 / 20.04 的 LNMP 安装脚本,并设置了国内镜像加速。 7 | 8 | 请确保所有命令都以 root 账户执行,如果登录账户不是 root,则需要执行 `sudo -H -s` 切换为 root 账户后再下载安装。 9 | 10 | > 注:下文将使用 `{version}` 来替代你选中的系统,如 16.04 / 18.04 / 20.04。 11 | 12 | ## 软件列表 13 | 14 | * Git 15 | * PHP 7.4 16 | * Nginx 17 | * MySQL 18 | * Sqlite3 19 | * Composer 20 | * Nodejs 10 21 | * Yarn 22 | * Redis 23 | * Beanstalkd 24 | * Memcached 25 | 26 | ## 可选软件列表 27 | 28 | 以下软件需手动执行安装脚本: 29 | 30 | * Elasticsearch:`./{version}/install_elasticsearch.sh`,默认为 6.x,如果要安装 7.x 则执行 `./{version}/install_elasticsearch.sh 7` 31 | 32 | ## 安装 33 | 34 | ### Ubuntu 16.04 35 | 36 | ``` 37 | wget -qO- https://raw.githubusercontent.com/summerblue/laravel-ubuntu-init/master/download.16.04.sh - | bash 38 | ``` 39 | 40 | 41 | ### Ubuntu 18.04 42 | 43 | ``` 44 | wget -qO- https://raw.githubusercontent.com/summerblue/laravel-ubuntu-init/master/download.18.04.sh - | bash 45 | ``` 46 | 47 | 48 | ### Ubuntu 20.04 49 | 50 | ``` 51 | wget -qO- https://raw.githubusercontent.com/summerblue/laravel-ubuntu-init/master/download.20.04.sh - | bash 52 | ``` 53 | 54 | 55 | ### 特别说明 56 | 57 | 此脚本会将安装脚本下载到当前用户的 Home 目录下的 `laravel-ubuntu-init` 目录并自动执行安装脚本。 58 | 59 | **安装结束之后会在屏幕上输出 Mysql root 账号的密码,请妥善保存。** 60 | 61 | 如果当前不是 root 账户则不会自动安装,需要切换到 root 账户后执行 `./{version}/install.sh`。 62 | 63 | ## 日常使用 64 | 65 | ### 1. 新增 Nginx 站点 66 | 67 | ``` 68 | ./{version}/nginx_add_site.sh 69 | ``` 70 | 71 | 会提示输入站点名称(只能是英文、数字、`-` 和 `_`)、域名(多个域名用空格隔开),确认无误后会创建对应的 Nginx 配置并重启 Nginx。 72 | 73 | ### 2. 新增 Mysql 用户、数据库 74 | 75 | ``` 76 | ./{version}/mysql_add_user.sh 77 | ``` 78 | 79 | 会提示输入 root 密码,如果错误将无法继续。输入需要创建的 Mysql 用户名,以及确认是否需要创建对应用户名的数据库。 80 | 81 | 创建完毕之后会将新用户的密码输出到屏幕上,请妥善保存。 82 | 83 | ### 3. 以 www-data 身份执行命令 84 | 85 | 本项目提供了一个 `sudowww` 的 `alias`,当需要以 `www-data` 用户身份执行命令时(如 `git clone 项目`、`php artisan config:cache` 等),可以直接在命令前加上 `sudowww`,同时在原命令两端加上单引号,如: 86 | 87 | ``` 88 | sudowww 'php artisan config:cache' 89 | ``` 90 | --------------------------------------------------------------------------------