diff --git a/lcmp/conf/index.html b/lcmp/conf/index.html deleted file mode 100644 index ca8ef32..0000000 --- a/lcmp/conf/index.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - LCMP 环境安装脚本 - - - - - - - -
-
恭喜!LCMP 环境安装成功!
-

LCMP (Linux + Caddy + MariaDB + PHP) 是一个强大的 Bash 脚本,用于一键安装 Caddy2 + MariaDB + PHP 等。

-
- - - diff --git a/lcmp/conf/lcmp b/lcmp/conf/lcmp deleted file mode 100644 index e16a48f..0000000 --- a/lcmp/conf/lcmp +++ /dev/null @@ -1,383 +0,0 @@ -#!/bin/bash - -trap _exit INT QUIT TERM - -_red() { - printf '\033[1;31;31m%b\033[0m' "$1" -} - -_green() { - printf '\033[1;31;32m%b\033[0m' "$1" -} - -_yellow() { - printf '\033[1;31;33m%b\033[0m' "$1" -} - -_printargs() { - printf -- "%s" "[$(date)] " - printf -- "%s" "$1" - printf "\n" -} - -_info() { - _printargs "$@" -} - -_warn() { - printf -- "%s" "[$(date)] " - _yellow "$1" - printf "\n" -} - -_error() { - printf -- "%s" "[$(date)] " - _red "$1" - printf "\n" - exit 2 -} - -_exit() { - printf "\n" - _red "$0 已终止。" - printf "\n" - exit 1 -} - -_exists() { - local cmd="$1" - if eval type type >/dev/null 2>&1; then - eval type "$cmd" >/dev/null 2>&1 - elif command >/dev/null 2>&1; then - command -v "$cmd" >/dev/null 2>&1 - else - which "$cmd" >/dev/null 2>&1 - fi - local rt=$? - return ${rt} -} - -_error_detect() { - local cmd="$1" - _info "${cmd}" - if ! eval "${cmd}" 1>/dev/null; then - _error "执行命令 (${cmd}) 失败,请检查并重试。" - fi -} - -_sleep_sec() { - seconds=$1 - while [ "${seconds}" -ge "0" ]; do - echo -ne "\r \r" - _green "${seconds}" - seconds=$((seconds - 1)) - sleep 1 - done - echo -ne "\r" -} - -check_sys() { - local value="$1" - local release='' - if [ -f /etc/redhat-release ]; then - release="rhel" - elif grep -Eqi "debian" /etc/issue; then - release="debian" - elif grep -Eqi "ubuntu" /etc/issue; then - release="ubuntu" - elif grep -Eqi "centos|red hat|redhat" /etc/issue; then - release="rhel" - elif grep -Eqi "debian" /proc/version; then - release="debian" - elif grep -Eqi "ubuntu" /proc/version; then - release="ubuntu" - elif grep -Eqi "centos|red hat|redhat" /proc/version; then - release="rhel" - fi - if [ "${value}" == "${release}" ]; then - return 0 - else - return 1 - fi -} - -vhost() { - case "$1" in - [aA][dD][dD]) - add_vhost - ;; - [lL][iI][sS][tT]) - list_vhost - ;; - [dD][eE][lL]) - del_vhost - ;; - *) - _error "用法: lcmp vhost [add|list|del]" - ;; - esac -} - -database() { - case "$1" in - [aA][dD][dD]) - add_database_menu - add_database - ;; - [lL][iI][sS][tT]) - list_database - ;; - [dD][eE][lL]) - del_database - ;; - [eE][dD][iI][tT]) - edit_database - ;; - *) - _error "用法: lcmp db [add|list|del|edit]" - ;; - esac -} - -add_vhost() { - while true; do - read -r -p "[$(date)] 请输入域名(例如: www.example.com): " domain - if [ -n "${domain}" ] && [[ "${domain}" = "${domain%[[:space:]]*}" ]]; then - if [ -f "/etc/caddy/conf.d/${domain}.conf" ]; then - _error "域名 ${domain} 已存在,请检查并重试。" - else - _info "域名: $(_green "${domain}")" - fi - break - else - _red "域名不能为空或包含空格。\n" - fi - done - - read -r -p "[$(date)] 请输入域名 ${domain} 的目录(默认目录: /data/www/${domain}): " vhostdir - if [ -z "${vhostdir}" ]; then - vhostdir="/data/www/${domain}" - fi - _info "虚拟主机目录: $(_green "${vhostdir}")" - - read -r -p "[$(date)] 是否创建一个 MariaDB 数据库及相同名称的用户 (y/n): " create_database - if [ "${create_database}" == "y" ] || [ "${create_database}" == "Y" ]; then - verify_db_password - add_database_menu - fi - _info "创建虚拟主机目录" - _error_detect "mkdir -p ${vhostdir}" - _info "设置虚拟主机目录权限" - _error_detect "chmod -R 755 ${vhostdir}" - _error_detect "chown -R caddy:caddy ${vhostdir}" - add_vhost_config - if [ "${create_database}" == "y" ] || [ "${create_database}" == "Y" ]; then - add_database - fi - _error_detect "systemctl restart caddy" - _info "虚拟主机信息:" - _info "域名: $(_green "${domain}")" - _info "虚拟主机目录: $(_green "${vhostdir}")" - _info "虚拟主机配置: $(_green "/etc/caddy/conf.d/${domain}.conf")" - list_vhost - if [ "${create_database}" == "y" ] || [ "${create_database}" == "Y" ]; then - _info "数据库用户名: ${database_name}" - _info "数据库用户密码: ${mysql_password}" - _info "数据库名称: ${database_name}" - fi -} - -add_vhost_config() { - cat >"/etc/caddy/conf.d/${domain}.conf" </dev/null 2>&1 -} - -# 检查操作系统类型 -check_sys() { - if [ -f /etc/os-release ]; then - . /etc/os-release - case "$ID" in - debian|ubuntu|centos|rhel) - return 0 - ;; - *) - return 1 - ;; - esac - else - return 1 - fi -} - -# 版本比较 -version_ge() { - test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1" -} - -# 检查内核版本是否大于4.9 -check_kernel_version() { - local kernel_version - kernel_version=$(uname -r | cut -d- -f1) - version_ge "${kernel_version}" 4.9 -} - -# 检查BBR状态 -check_bbr_status() { - local param - param=$(sysctl net.ipv4.tcp_congestion_control | awk '{print $3}') - [[ "${param}" == "bbr" ]] -} - -# 检查用户权限 -[ ${EUID} -ne 0 ] && _red "此脚本必须以root身份运行!\n" && exit 1 - -# 检查支持的操作系统 -if ! check_sys; then - _error "不支持的操作系统,请切换为Debian, Ubuntu 或 RHEL/CentOS。" -fi - -# 设置MariaDB的root密码 -_info "请输入MariaDB的root密码:" -read -r -p "[$(date)] (默认密码: MariaDB22333):" db_pass -[ -z "${db_pass}" ] && db_pass="MariaDB22333" -_info "---------------------------" -_info "密码 = $(_red "${db_pass}")" -_info "---------------------------" - -# 选择PHP版本 -while true; do - _info "请选择PHP版本:" - _info "$(_green 1). PHP 7.4" - _info "$(_green 2). PHP 8.0" - _info "$(_green 3). PHP 8.1" - _info "$(_green 4). PHP 8.2" - _info "$(_green 5). PHP 8.3" - read -r -p "[$(date)] 请输入一个数字: (默认2) " php_version - [ -z "${php_version}" ] && php_version=2 - case "${php_version}" in - 1) php_ver="7.4"; break ;; - 2) php_ver="8.0"; break ;; - 3) php_ver="8.1"; break ;; - 4) php_ver="8.2"; break ;; - 5) php_ver="8.3"; break ;; - *) _info "输入错误! 请输入1-5的数字" ;; - esac -done -_info "---------------------------" -_info "PHP版本 = $(_red "${php_ver}")" -_info "---------------------------" - -_info "按任意键开始...或按Ctrl+C取消" -char=$(get_char) - -# VPS初始化 -_info "VPS初始化开始" -_error_detect "rm -f /etc/localtime" -_error_detect "ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime" - -# 检查系统类型并安装相关工具 -if check_sys rhel; then - _error_detect "yum install -yq yum-utils epel-release" - _error_detect "yum-config-manager --enable epel" - if get_rhelversion 8; then - yum-config-manager --enable powertools >/dev/null 2>&1 || yum-config-manager --enable PowerTools >/dev/null 2>&1 - _info "设置PowerTools存储库完成" - fi - if get_rhelversion 9; then - _error_detect "yum-config-manager --enable crb" - _info "设置CRB存储库完成" - fi - _error_detect "yum makecache" - _error_detect "yum install -yq vim tar zip unzip net-tools bind-utils screen git virt-what wget whois firewalld mtr traceroute iftop htop jq tree" -elif check_sys debian || check_sys ubuntu; then - _error_detect "apt-get update" - _error_detect "apt-get -yq install lsb-release ca-certificates curl" - _error_detect "apt-get -yq install vim tar zip unzip net-tools bind9-utils screen git virt-what wget whois mtr traceroute iftop htop jq tree" -fi - -# 启用BBR -if check_kernel_version; then - if ! check_bbr_status; then - sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf - sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf - sed -i '/net.core.rmem_max/d' /etc/sysctl.conf - cat >>/etc/sysctl.conf </dev/null 2>&1 - _info "BBR已启用" - fi -fi - -# 设置Caddy -_info "开始安装Caddy" -if check_sys rhel; then - _error_detect "yum install -yq caddy" -elif check_sys debian || check_sys ubuntu; then - _error_detect "wget -qO caddy-stable_deb.sh https://dl.cloudsmith.io/public/caddy/stable/setup.deb.sh" - _error_detect "chmod +x caddy-stable_deb.sh" - _error_detect "./caddy-stable_deb.sh" - _error_detect "rm -f caddy-stable_deb.sh" - _error_detect "apt-get install -y caddy" -fi -_info "Caddy安装完成" - -# 设置MariaDB -_info "开始安装MariaDB" -_error_detect "wget -qO mariadb_repo_setup.sh https://downloads.mariadb.com/MariaDB/mariadb_repo_setup" -_error_detect "chmod +x mariadb_repo_setup.sh" -_info "./mariadb_repo_setup.sh --mariadb-server-version=mariadb-10.11" -./mariadb_repo_setup.sh --mariadb-server-version=mariadb-10.11 >/dev/null 2>&1 -_error_detect "rm -f mariadb_repo_setup.sh" -if check_sys rhel; then - _error_detect "yum install -y MariaDB-common MariaDB-server MariaDB-client MariaDB-shared MariaDB-backup" - mariadb_cnf="/etc/my.cnf.d/server.cnf" -elif check_sys debian || check_sys ubuntu; then - _error_detect "apt-get install -y mariadb-common mariadb-server mariadb-client mariadb-backup" - mariadb_cnf="/etc/mysql/mariadb.conf.d/50-server.cnf" -fi -_info "MariaDB安装完成" - -# 配置MariaDB -lnum=$(sed -n '/\[mysqld\]/=' "${mariadb_cnf}") -sed -i "${lnum}ainnodb_buffer_pool_size = 100M\nmax_allowed_packet = 1024M\nnet_read_timeout = 3600\nnet_write_timeout = 3600" "${mariadb_cnf}" -lnum=$(sed -n '/\[mariadb\]/=' "${mariadb_cnf}") -sed -i "${lnum}acharacter-set-server = utf8mb4\n\n\[client-mariadb\]\ndefault-character-set = utf8mb4" "${mariadb_cnf}" -_error_detect "systemctl start mariadb" -/usr/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"${db_pass}\" with grant option;" -/usr/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"${db_pass}\" with grant option;" -/usr/bin/mysql -e "delete from mysql.user where password = '' or password is null;" -/usr/bin/mysql -e "delete from mysql.user where not (user='root') or host not in ('localhost', '127.0.0.1', '::1');" -/usr/bin/mysql -e "delete from mysql.db where db='test' or db='test\_%';" -/usr/bin/mysql -e "flush privileges;" -_error_detect "systemctl enable mariadb" -_info "MariaDB配置完成" - -_info "所有步骤已完成!"