Delete lcmp directory

This commit is contained in:
NewName
2024-08-17 06:16:14 +08:00
parent a5fc15eb4d
commit b84728ef99
3 changed files with 0 additions and 641 deletions

View File

@@ -1,45 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>LCMP 环境安装脚本</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="keywords" content="LCMP安装脚本">
<meta name="description" content="LCMP 安装成功">
<style type="text/css">
body {
color: #333333;
font-family: "Microsoft YaHei", tahoma, arial, helvetica, sans-serif;
font-size: 14px;
}
.links {
color: #06C
}
#main {
margin-right: auto;
margin-left: auto;
width: 600px;
}
a {
text-decoration: none;
color: #06C;
-webkit-transition: color .2s;
-moz-transition: color .2s;
-ms-transition: color .2s;
-o-transition: color .2s;
transition: color .2s
}
</style>
</head>
<body>
<div id="main">
<div align="center"><span style="font-size:18px;color:red;">恭喜LCMP 环境安装成功!</span></div>
<p><span>LCMP (Linux + Caddy + MariaDB + PHP) 是一个强大的 Bash 脚本,用于一键安装 Caddy2 + MariaDB + PHP 等。</span></p>
</div>
</body>
</html>

View File

@@ -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" <<EOF
${domain} {
header {
Strict-Transport-Security "max-age=31536000; preload"
X-Content-Type-Options nosniff
X-Frame-Options SAMEORIGIN
}
root * ${vhostdir}
encode gzip
php_fastcgi ${php_sock}
file_server {
index index.html
}
log {
output file /var/log/caddy/access_${domain}.log {
roll_size 100mb
roll_keep 3
roll_keep_for 7d
}
}
}
EOF
}
list_vhost() {
_info "Caddy 虚拟主机列表:"
local vhosts=()
while IFS=' ' read -r line; do vhosts+=("${line}"); done < <(find /etc/caddy/conf.d/ -name "*.conf" -type f -printf "%f\n" | sed 's/.conf//g' | grep -v "default")
if [ "${#vhosts[@]}" -gt 0 ]; then
for i in "${vhosts[@]}"; do
_info "$(_green "${i}")"
done
else
_info "未找到 Caddy 虚拟主机。您可以使用命令 $(_green "lcmp vhost add") 创建一个新的 Caddy 虚拟主机。"
fi
}
del_vhost() {
list_vhost
while true; do
read -r -p "[$(date)] 请输入要删除的域名: " domain
if [ -z "${domain}" ]; then
_red "域名不能为空。\n"
else
break
fi
done
if [ -f "/etc/caddy/conf.d/${domain}.conf" ]; then
rm -f "/etc/caddy/conf.d/${domain}.conf"
_info "域名 $(_red "${domain}") 已被删除。"
_info "网站文件不会被删除以保证安全。"
_info "删除虚拟主机配置"
_error_detect "systemctl restart caddy"
else
_error "未找到域名 ${domain} 的虚拟主机配置。"
fi
}
add_database_menu() {
_info "添加 MariaDB 数据库菜单"
_info "数据库创建选项:"
_info "1. 创建一个新的数据库"
_info "2. 创建一个新的数据库用户"
_info "3. 创建数据库及用户"
_info "4. 退出"
}
verify_db_password() {
while true; do
read -r -p "[$(date)] 请输入 MariaDB root 用户密码: " -s root_password
echo
read -r -p "[$(date)] 请再次输入 MariaDB root 用户密码: " -s root_password_confirm
echo
if [ "${root_password}" == "${root_password_confirm}" ]; then
break
else
_red "两次输入的密码不匹配,请重试。"
fi
done
}
add_database() {
local choice
while true; do
read -r -p "[$(date)] 请选择数据库创建选项 [1-4]: " choice
case $choice in
1)
read -r -p "[$(date)] 请输入数据库名称: " database_name
_info "创建数据库: $(_green "${database_name}")"
_error_detect "mysql -uroot -p${root_password} -e \"CREATE DATABASE ${database_name};\""
;;
2)
read -r -p "[$(date)] 请输入数据库用户名: " database_user
read -r -p "[$(date)] 请输入数据库用户密码: " -s database_password
echo
_info "创建数据库用户: $(_green "${database_user}")"
_error_detect "mysql -uroot -p${root_password} -e \"CREATE USER '${database_user}'@'localhost' IDENTIFIED BY '${database_password}';\""
;;
3)
read -r -p "[$(date)] 请输入数据库名称: " database_name
read -r -p "[$(date)] 请输入数据库用户名: " database_user
read -r -p "[$(date)] 请输入数据库用户密码: " -s database_password
echo
_info "创建数据库: $(_green "${database_name}")"
_info "创建数据库用户: $(_green "${database_user}")"
_error_detect "mysql -uroot -p${root_password} -e \"CREATE DATABASE ${database_name};\""
_error_detect "mysql -uroot -p${root_password} -e \"CREATE USER '${database_user}'@'localhost' IDENTIFIED BY '${database_password}';\""
_error_detect "mysql -uroot -p${root_password} -e \"GRANT ALL PRIVILEGES ON ${database_name}.* TO '${database_user}'@'localhost';\""
_error_detect "mysql -uroot -p${root_password} -e \"FLUSH PRIVILEGES;\""
;;
4)
break
;;
*)
_red "无效的选项,请选择 1-4。"
;;
esac
done
}
list_database() {
_info "数据库列表:"
_error_detect "mysql -uroot -p${root_password} -e \"SHOW DATABASES;\""
}
del_database() {
read -r -p "[$(date)] 请输入要删除的数据库名称: " database_name
_info "删除数据库: $(_red "${database_name}")"
_error_detect "mysql -uroot -p${root_password} -e \"DROP DATABASE ${database_name};\""
}
edit_database() {
_info "编辑数据库功能尚未实现。"
}
# 主程序
if [ "$#" -lt 1 ]; then
_error "用法: lcmp [vhost|db]"
fi
case "$1" in
[vV][hH][oO][sS][tT])
vhost "$2"
;;
[dD][bB])
database "$2"
;;
*)
_error "无效的命令: $1"
;;
esac
if [ "$#" -lt 1 ]; then
_error "用法: lcmp [start|stop|restart|status|vhost|db]"
fi
case "$1" in
start)
lcmp_start
;;
stop)
lcmp_stop
;;
restart)
lcmp_stop
sleep 1
lcmp_start
;;
status)
lcmp_status
;;
vhost)
vhost "$2"
;;
db)
verify_db_password
database "$2"
clean_temp_mycnf
;;
*)
_info "用法:"
_info "$(_green "lcmp start") 启动所有 LCMP 服务"
_info "$(_green "lcmp stop") 停止所有 LCMP 服务"
_info "$(_green "lcmp restart") 重启所有 LCMP 服务"
_info "$(_green "lcmp status") 查看所有 LCMP 服务的状态"
_info "$(_green "lcmp vhost add") 创建一个新的 Caddy 虚拟主机"
_info "$(_green "lcmp vhost list") 列出所有 Caddy 虚拟主机"
_info "$(_green "lcmp vhost del") 删除一个 Caddy 虚拟主机"
_info "$(_green "lcmp db add") 创建一个 MariaDB 数据库和同名用户"
_info "$(_green "lcmp db list") 列出所有 MariaDB 数据库"
_info "$(_green "lcmp db del") 删除一个 MariaDB 数据库和同名用户"
_info "$(_green "lcmp db edit") 更新 MariaDB 数据库用户的密码"
;;
esac

View File

@@ -1,213 +0,0 @@
#!/bin/bash
# 该脚本引用自https://github.com/teddysun/lcmp
# Linux + Caddy + MariaDB + PHP 安装脚本
# 处理退出信号
trap _exit INT QUIT TERM
cur_dir="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
# 输出颜色格式
_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"
}
# 信息输出函数
_info() {
printf -- "%s" "[$(date)] $1\n"
}
_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() {
command -v "$1" >/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 <<EOF
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.core.rmem_max = 2500000
EOF
sysctl -p >/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 "所有步骤已完成!"