佛系生活,缓慢更新,AFK!!

MENU

树莓派建立镜像博客站点

May 7, 2020 • Read: 162 • 树莓派,docker

手头的树莓派没跑多少东西,一直放置也是吃灰,不如先练手建立本地博客站。云服务器建站有很多优势,但是续费也很贵,不如直接在本地服务器建站

备份源站

利用宝塔面板的备份功能我们可以快速备份数据库和/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镜像的基础镜像是alpinemysqlalpine中安装其实是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 &即可

Archives QR Code
QR Code for this page
Tipping QR Code
Leave a Comment

2 Comments
  1. 哈士奇社区 哈士奇社区     Windows 10 /    Google Chrome

    博主用的什么型号的树莓派啊,纠结买@(滑稽)

    1. mancornuto mancornuto     Windows 10 /    Google Chrome

      @哈士奇社区4B4G版@(哈哈),如果真想玩那就买一个,现在有8G版了,可以按自己的需求来买