win10 下 WSL Ubuntu 安装宝塔数据库问题
一直找不到 Win10 下合适的开发环境,又不想安装虚拟机,于是就利用 Win10 自带的 WSL 来安装 Linux 环境
在 Win10 下测试安装了 Ubuntu 22 、20、18 三个版本进行测试
安装宝塔没有问题,但均在数据库上卡住了
安装宝塔后如果给出的 IP 地址不正确,请在命令窗口使用 ifconfig 来查询内网 IP 来链接控制面板
面板安装数据库显示运行成功,但在面板操作数据库上就是显示 ‘数据库连接失败,请检查数据库服务是否启动!’
后来搜索相关文章,宝塔的官方回复为不支持 WSL 版本安装
但还是尝试进行了更多搜索,发现了一位网友的解决方案
我前几天也遇到这个问题...
后来在改云数据库支持的时候发现了问题在哪了..
在宝塔面板的文件里打开/www/server/panel/class/panelMysql.py
可以看到是使用socket进行连接的,使用本地文件/tmp/mysql.sock,我查看了下这个文件也是确实存在的..可能是权限?或者其他问题.总之这个连接方式连接不上...那么我们换一个连接方式,修改第60行
self.__DB_CONN = MySQLdb.connect(host = self.__DB_HOST,user = self.__DB_USER,passwd = self.__DB_PASS,port = self.__DB_PORT,charset="utf8",connect_timeout=1,unix_socket=socket)
把后面的unix_socket=socket去掉,超时时间connect_timeout改改,比如1000吧,
self.__DB_CONN = MySQLdb.connect(host = self.__DB_HOST,user = self.__DB_USER,passwd = self.__DB_PASS,port = self.__DB_PORT,charset="utf8",connect_timeout=1000)
保存,重启面板,数据库就能正常使用了...
apt 使用较慢的话更新为国内源
备份原始文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
编辑替换为阿里的源
vi /etc/apt/sources.list
注意版本选择,或者直接替换 http://archive.ubuntu.com 为 https://mirrors.aliyun.com
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb https://mirrors.aliyun.com/ubuntu/ jammy universe
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy universe
deb https://mirrors.aliyun.com/ubuntu/ jammy-updates universe
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb https://mirrors.aliyun.com/ubuntu/ jammy multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-updates multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted
deb http://security.ubuntu.com/ubuntu/ jammy-security universe
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security universe
deb http://security.ubuntu.com/ubuntu/ jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security multiverse
当然也可以使用清华大学的镜像:https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/