refactor: 重构 Dockerfile,更换基础镜像并全面更新安装依赖及宝塔面板配置
This commit is contained in:
parent
676336cb5c
commit
6c6d998671
44
Dockerfile
44
Dockerfile
@ -1,11 +1,45 @@
|
|||||||
FROM docker.cnb.cool/btpanel/btpanel:9.0_lts_fresh
|
FROM debian:bookworm
|
||||||
|
|
||||||
# 安装 lib 库
|
# 切换 Debian 镜像源为腾讯云源,更新包列表并安装依赖
|
||||||
RUN curl -o /www/server/panel/install/lib.sh https://dg2.bt.cn/install/1/lib.sh \
|
RUN sed -i 's/deb.debian.org/mirrors.tencent.com/g' /etc/apt/sources.list.d/debian.sources \
|
||||||
&& sh /www/server/panel/install/lib.sh \
|
&& apt update && apt upgrade -y \
|
||||||
|
&& apt install -y \
|
||||||
|
locales \
|
||||||
|
wget iproute2 openssh-server libgd-dev cmake make gcc g++ autoconf \
|
||||||
|
libsodium-dev libonig-dev libssh2-1-dev libc-ares-dev libaio-dev sudo curl dos2unix \
|
||||||
|
build-essential re2c cron bzip2 libzip-dev libc6-dev bison file rcconf flex vim m4 gawk less cpp binutils \
|
||||||
|
diffutils unzip tar libbz2-dev libncurses5 libncurses5-dev libtool libevent-dev libssl-dev libsasl2-dev \
|
||||||
|
libltdl-dev zlib1g-dev libglib2.0-0 libglib2.0-dev libkrb5-dev libpq-dev libpq5 gettext libcap-dev \
|
||||||
|
libc-client2007e-dev psmisc patch git e2fsprogs libxslt1-dev xz-utils libgd3 libwebp-dev libvpx-dev \
|
||||||
|
libfreetype6-dev libjpeg62-turbo libjpeg62-turbo-dev iptables libudev-dev libldap2-dev \
|
||||||
|
&& apt clean \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# 复制脚本
|
||||||
|
COPY ["bt.sh", "init_mysql.sh", "/"]
|
||||||
|
|
||||||
|
# 转换启动脚本
|
||||||
|
RUN dos2unix /bt.sh && dos2unix /init_mysql.sh
|
||||||
|
|
||||||
|
# 下载并安装宝塔面板及 lnmp 环境
|
||||||
|
RUN curl -sSO https://download.bt.cn/install/install_lts.sh \
|
||||||
|
&& echo y | bash install_lts.sh -P 8888 --ssl-disable \
|
||||||
|
&& btpip config set global.index-url https://mirrors.tencent.com/pypi/simple \
|
||||||
|
&& rm -rf /www/server/data/* \
|
||||||
|
&& echo "docker_bt_ltsd12" > /www/server/panel/data/o.pl \
|
||||||
|
&& echo '["memuA", "memuAsite", "memuAdatabase", "memuAcontrol", "memuAfiles", "memuAlogs", "memuAxterm", "memuAcrontab", "memuAsoft", "memuAconfig", "dologin", "memu_btwaf", "memuAssl"]' > /www/server/panel/config/show_menu.json \
|
||||||
|
&& apt clean \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
&& chmod +x /bt.sh \
|
&& chmod +x /bt.sh \
|
||||||
&& chmod +x /init_mysql.sh
|
&& chmod +x /init_mysql.sh
|
||||||
|
|
||||||
|
|
||||||
|
# 配置宝塔面板安全入口和用户名及密码,以及 SSH 密码
|
||||||
|
RUN echo btpanel | bt 6 \
|
||||||
|
&& echo btpaneldocker | bt 5 \
|
||||||
|
&& echo "/btpanel" > /www/server/panel/data/admin_path.pl \
|
||||||
|
&& echo "root:btpaneldocker" | chpasswd
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/sh","-c","/bt.sh"]
|
ENTRYPOINT ["/bin/sh","-c","/bt.sh"]
|
||||||
|
|
||||||
# 暴漏特定端口
|
# 暴漏特定端口
|
||||||
|
97
bt.sh
Normal file
97
bt.sh
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||||
|
export PATH
|
||||||
|
|
||||||
|
init_path=/etc/init.d
|
||||||
|
Root_Path=`cat /var/bt_setupPath.conf`
|
||||||
|
Setup_Path=$Root_Path/server/mysql
|
||||||
|
Data_Path=$Root_Path/server/data
|
||||||
|
O_pl=$(cat /www/server/panel/data/o.pl)
|
||||||
|
|
||||||
|
backup_database() {
|
||||||
|
if [ -d "${Data_Path}" ] && [ ! -z "$(ls -A ${Data_Path})" ]; then
|
||||||
|
if [ ! -d "${Setup_Path}" ] || [ -z "$(ls -A ${Setup_Path})" ]; then
|
||||||
|
timestamp=$(date +"%Y%m%d%H%M%S")
|
||||||
|
tar czf /www/server/data_backup_$timestamp.tar.gz -C ${Data_Path} .
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
restore_panel_data() {
|
||||||
|
if [ -f /www.tar.gz ]; then
|
||||||
|
if [ ! -d /www ] || [ -z "$(ls -A /www)" ] || [ ! -d /www/server/panel ] || [ -z "$(ls -A /www/server/panel)" ] || [ ! -d /www/server/panel/pyenv ] || [ -z "$(ls -A /www/server/panel/pyenv)" ]; then
|
||||||
|
tar xzf /www.tar.gz -C / --skip-old-files
|
||||||
|
rm -rf /www.tar.gz
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
soft_start(){
|
||||||
|
# 扫描并启动所有服务
|
||||||
|
init_scripts=$(ls ${init_path})
|
||||||
|
for script in ${init_scripts}; do
|
||||||
|
case "${script}" in
|
||||||
|
"bt"|"mysqld"|"nginx"|"httpd")
|
||||||
|
continue
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
${init_path}/${script} start
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -f ${init_path}/nginx ]; then
|
||||||
|
${init_path}/nginx start
|
||||||
|
elif [ -f ${init_path}/httpd ]; then
|
||||||
|
${init_path}/httpd start
|
||||||
|
fi
|
||||||
|
|
||||||
|
${init_path}/bt stop
|
||||||
|
${init_path}/bt start
|
||||||
|
|
||||||
|
pkill crond
|
||||||
|
/sbin/crond
|
||||||
|
|
||||||
|
chmod 600 /etc/ssh/ssh_host_*
|
||||||
|
/usr/sbin/sshd -D &
|
||||||
|
}
|
||||||
|
|
||||||
|
init_mysql(){
|
||||||
|
if [ "${O_pl}" != "docker_btlamp_ltsd12" ] && [ "${O_pl}" != "docker_btlnmp_ltsd12" ];then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
if [ -d "${Data_Path}" ]; then
|
||||||
|
check_z=$(ls "${Data_Path}")
|
||||||
|
echo "check_z:"
|
||||||
|
echo ${check_z}
|
||||||
|
if [[ ! -z "${check_z}" ]]; then
|
||||||
|
echo "check_z is not empty"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [ -f /init_mysql.sh ] && [ -d "${Setup_Path}" ];then
|
||||||
|
bash /init_mysql.sh
|
||||||
|
rm -f /init_mysql.sh
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
is_empty_Data(){
|
||||||
|
return "$(ls -A ${Data_Path}/|wc -w)"
|
||||||
|
}
|
||||||
|
|
||||||
|
start_mysql(){
|
||||||
|
if [ -d "${Setup_Path}" ] && [ -f "${init_path}/mysqld" ];then
|
||||||
|
chown -R mysql:mysql ${Data_Path}
|
||||||
|
chgrp -R mysql ${Setup_Path}/.
|
||||||
|
${init_path}/mysqld start
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
restore_panel_data > /dev/null
|
||||||
|
backup_database > /dev/null
|
||||||
|
is_empty_Data > /dev/null
|
||||||
|
init_mysql > /dev/null
|
||||||
|
start_mysql > /dev/null
|
||||||
|
soft_start > /dev/null
|
||||||
|
#tail -f /dev/null
|
||||||
|
${init_path}/bt log
|
41
init_mysql.sh
Normal file
41
init_mysql.sh
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||||
|
export PATH
|
||||||
|
|
||||||
|
Root_Path=`cat /var/bt_setupPath.conf`
|
||||||
|
Setup_Path=$Root_Path/server/mysql
|
||||||
|
Data_Path=$Root_Path/server/data
|
||||||
|
|
||||||
|
Mysql_Initialize(){
|
||||||
|
if [ -d "${Data_Path}" ]; then
|
||||||
|
check_z=$(ls "${Data_Path}")
|
||||||
|
if [[ ! -z "${check_z}" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p ${Data_Path}
|
||||||
|
chown -R mysql:mysql ${Data_Path}
|
||||||
|
chgrp -R mysql ${Setup_Path}/.
|
||||||
|
|
||||||
|
${Setup_Path}/bin/mysqld --initialize-insecure --basedir=${Setup_Path} --datadir=${Data_Path} --user=mysql
|
||||||
|
|
||||||
|
cat > /etc/ld.so.conf.d/mysql.conf<<EOF
|
||||||
|
${Setup_Path}/lib
|
||||||
|
EOF
|
||||||
|
ldconfig
|
||||||
|
ln -sf ${Setup_Path}/lib/mysql /usr/lib/mysql
|
||||||
|
ln -sf ${Setup_Path}/include/mysql /usr/include/mysql
|
||||||
|
/etc/init.d/mysqld start
|
||||||
|
|
||||||
|
mysqlpwd=`cat /dev/urandom | head -n 16 | md5sum | head -c 16`
|
||||||
|
${Setup_Path}/bin/mysqladmin -u root password "${mysqlpwd}"
|
||||||
|
|
||||||
|
cd "${Setup_Path}"
|
||||||
|
rm -f src.tar.gz
|
||||||
|
rm -rf src
|
||||||
|
/etc/init.d/mysqld start
|
||||||
|
rm -rf /init_mysql.sh
|
||||||
|
}
|
||||||
|
|
||||||
|
Mysql_Initialize
|
Loading…
x
Reference in New Issue
Block a user