手头的树莓派没跑多少东西,一直放置也是吃灰,不如先练手建立本地博客站。云服务器建站有很多优势,但是续费也很贵,不如直接在本地服务器建站
备份源站
利用宝塔面板的备份功能我们可以快速备份数据库和/usr
文件夹到本地
建站
宝塔对于树莓派的兼容性好像不太好,树莓派系统虽然有宝塔的虚拟机可以使用,但是我们有更好的选择,没错,就是默认启用的docker,typecho的镜像有很多,这里选用灯大的typeho镜像,其可以使用MYSQL
作为数据库
拉取镜像
docker pull 80x86/typecho:arm64 #arm64和latest标签是一样的镜像ID,也可以默认拉取
启动容器
docker run -d \
--name=blog \
--restart always \
--mount type=tmpfs,destination=/tmp \
-v /srv/typecho:/data \ #挂载的typecho目录
-e PHP_TZ=Asia/Shanghai \
-e PHP_MAX_EXECUTION_TIME=600 \
-p 90:80 \ #http端口
-p 8008:443 \ #https端口
-p 3306:3306 \ #数据库端口
80x86/typecho:arm64
#自行决定开放https和数据库端口
如无意外,容器已经运行
建立数据库
你可以选择再建立一个数据库容器进行连接,不过你的typecho已经集成了大部分环境,再把数据库单独弄出来我觉得不太美,所以我选择直接集成到容器中
灯大的typecho镜像的基础镜像是alpine
,mysql
在alpine
中安装其实是MariaDB
,其完全兼容mysql,因此按照mysql来设置即可
docker exec -it blog sh #进入容器
# 安装数据库及客户端
apk add mysql mysql-client
# 初始化数据库
mysql_install_db --user=mysql --datadir=/var/lib/mysql
# 启动服务
apk add openrc #安装openrc
rc-service mariadb start #启动服务
mysqld_safe & #重要命令,容器启用了健康检查,当重启容器后显示不健康状态,大概率是由于数据库守护进程没启动,在容器内使用此命令即可
设置密码
mysql_secure_installation #命令
#以下为交互界面
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
/ #
建立数据库
mysql -u root -p #登录
#交互界面
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.20-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database typecho; #创建数据库命令,记得带着分号
Query OK, 1 row affected (0.002 sec)
MariaDB [(none)]>
导入数据库备份文件
use test;
source </www/example/students.sql test
安装typecho
打开ip:90,会出现typecho安装界面,安装完成后会提示数据库使用,保留原有数据库,将备份文件夹/usr
覆盖到挂载的目录下,这样镜像站就会和源站一模一样
问题解决
容器状态un-healthy,在容器内使用命令mysqld_safe &
即可
版权属于:mancornuto
本文链接:https://mancornuto.xyz/archives/0010.html
转载时须注明出处及本声明
博主用的什么型号的树莓派啊,纠结买@(滑稽)
4B4G版@(哈哈),如果真想玩那就买一个,现在有8G版了,可以按自己的需求来买