如何使用 Docker 快速搭建 ZrLog 博客系统

ZrLog 虽然提供了一个简易的安装引导,然而安装过程好像也并没有想象的那么顺利,介于整个过程还是有不少需要注意的地方(也有不少网友也写过相关的安装教程,只是都基于的版本多是18年以前的版本),所有就有这篇更加详尽的安装向导

这篇文章为 Docker 环境下的安装向导,如果是基于 zip/war 的安装方式还是查看这篇文章 安装向导

运行配置

最低 推荐
内存 1GB >=2GB
磁盘 5G 10GB
网络带宽 1mbps 越大越好(前台页面静态资源,通过1mbps,也能有一个很好的体验)

安装前环境

  • MySQL >= 5.7(不建议将 MySQL 也安装在 Docker 里面,维护麻烦)
  • Docker

注:本文以 CentOS7.9 为例,Windows/MacOS/其它 Linux发行版本安装流程大致一致,就不外额补充了

安装 MySQL

推荐使用 yum 方式安装而不是 rpm 安装

  1. rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
  2. sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/mysql-community.repo
  3. # 导入 GPG 钥匙
  4. rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
  5. yum --enablerepo=mysql80-community install mysql-community-server

启动 MySQL

  1. sudo systemctl start mysqld
  2. sudo systemctl status mysqld

完成 MySQL 初始化

查看 root 默认密码

  1. grep "temporary" /var/log/mysqld.log

控制台输入

  1. 2022-10-15T00:58:36.703195Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: gHuMzY==:4wx
  1. mysql_secure_installation
流程详细说明

在输入完上面的的默认密码后,会对 MySQL 进行一些基础的配置

  1. New password:
  2. Re-enter new password:
  3. Estimated strength of the password: 100
  4. Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
  5. By default, a MySQL installation has an anonymous user,
  6. allowing anyone to log into MySQL without having to have
  7. a user account created for them. This is intended only for
  8. testing, and to make the installation go a bit smoother.
  9. You should remove them before moving into a production
  10. environment.
  11. #是否移除默认的匿名用户,这个通常用不上,意见移除
  12. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
  13. Success.
  14. Normally, root should only be allowed to connect from
  15. 'localhost'. This ensures that someone cannot guess at
  16. the root password from the network.
  17. #是否禁止远程使用 root 账户登录,这个为了数据库安全也建议禁止掉
  18. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
  19. Success.
  20. By default, MySQL comes with a database named 'test' that
  21. anyone can access. This is also intended only for testing,
  22. and should be removed before moving into a production
  23. environment.
  24. #是否移除测试数据库,这个通常没什么用处,意见移除
  25. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
  26. - Dropping test database...
  27. Success.
  28. - Removing privileges on test database...
  29. Success.
  30. Reloading the privilege tables will ensure that all changes
  31. made so far will take effect immediately.
  32. #是否马上生效的上面配置,意见马上生效
  33. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
  34. Success.
  35. All done!

到这里为止就完成了 CentOS7 下的 MySQL 安装和初始化了,接下进入下一步,为 zrlog 创建一个独立账户和数据库

创建账户和数据库

  1. [root@iZbp1jenlv6zmaxas62hduZ ~]# mysql -u root -p
  2. Enter password: (键入刚才重新设置的密码后,会登录进入MySQL的操作界面)
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 30
  5. Server version: 8.0.31 MySQL Community Server - GPL
  6. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql>

按照这个脚步来创建账户

  1. create database zrlog_demo;
  2. CREATE USER 'zrlog_demo'@'%' IDENTIFIED WITH mysql_native_password BY 'aeshai0..Een1jah'; --MySQL这里需要指定一个密码强度高的,不如会出现无法授权的情况
  3. use mysql;
  4. GRANT ALL privileges ON `zrlog_demo`.* TO 'zrlog_demo'@'%';

控制台输出

  1. mysql> create database zrlog_demo;
  2. Query OK, 1 row affected (0.00 sec)
  3. mysql> CREATE USER 'zrlog_demo'@'%' IDENTIFIED WITH mysql_native_password BY 'aeshai0..Een1jah';
  4. Query OK, 0 rows affected (0.01 sec)
  5. mysql> use mysql;
  6. Reading table information for completion of table and column names
  7. You can turn off this feature to get a quicker startup with -A
  8. Database changed
  9. mysql> GRANT ALL privileges ON `zrlog_demo`.* TO 'zrlog_demo'@'%';
  10. Query OK, 0 rows affected (0.00 sec)
  11. mysql> exit
  12. Bye

测试下创建的账户是否可用

mysql -uzrlog_demo -p

  1. mysql> show databases;
  2. +--------------------+
  3. | Database |
  4. +--------------------+
  5. | information_schema |
  6. | performance_schema |
  7. | zrlog_demo |
  8. +--------------------+
  9. 3 rows in set (0.00 sec)
  10. mysql> use zrlog_demo;
  11. Database changed
  12. mysql> create table test(id bigint);
  13. Query OK, 0 rows affected (0.02 sec)
  14. mysql> select * from test;
  15. Empty set (0.01 sec)

到目前为止数据库的部分就大功告成了

安装 Docker

注意是安装的 docker,基础就可以
docker-compose 是可选(如果使用 Docker 安装的MySQL 才用的上容器的编排)

  1. # 这里建议安装一下 git 便于后面下载安装脚步
  2. yum install docker.x86_64 git -y

启动 Docker 服务是否正常启动

  1. sudo systemctl start docker
  2. sudo systemctl status docker

拉取最新的 Docker 编译脚步,并完成安装和配配置

  1. # (如果由于某些特殊原因无法完成 clone 可以使用 https://gitee.com/94fzb/zrlog-docker)
  2. git clone https://github.com/94fzb/zrlog-docker
  3. cd zrlog-docker
  4. # 构建最新的 zrlog docker 镜像
  5. sh build.sh
  6. # 进入安装引导模式
  7. sh install.sh
  8. # 访问 http://xxx.xx.xx.xx:28080/ (host部分自己改成对于的) 通过安装引导完成 zrlog 初始化
  9. # 安装完后,将刚才输入数据库信息,录入到 config/config.properties 里面
  10. vim config/config.properties
  11. # \u6570\u636E\u5E93\u4FE1\u606F
  12. db.password=aeshai0..Een1jah
  13. db.host=172.17.0.1
  14. db.port=3306
  15. db.username=zrlog_demo
  16. db.database=zrlog_demo
  17. # \u5BB9\u5668\u91CC tomcat \u4F7F\u7528\u7684\u7AEF\u53E3
  18. server.port=8080
  19. # \u5BB9\u5668\u5BF9\u5916\u516C\u5F00\u7684\u7AEF\u53E3
  20. export.port=28080
  21. app.name=zrlog
  22. contextPath=
  23. # 完成上述的配置后,重启 zrlog
  24. sh stop.sh && sh start.sh

访问一下 http://xxx.xx.xx.xx:28080/ 是否正常,若页面正常就,恭喜你,完成了 zrlog 的安装了,开始愉快的写作吧

参考