使用 Docker 快速搭建


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

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

运行配置

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

安装前环境

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

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

安装 MySQL

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

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

启动 MySQL

sudo systemctl start mysqld
sudo systemctl status mysqld

完成 MySQL 初始化

查看 root 默认密码

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

控制台输入

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

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

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y 
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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.

#是否禁止远程使用 root 账户登录,这个为了数据库安全也建议禁止掉

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

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

创建账户和数据库

[root@iZbp1jenlv6zmaxas62hduZ ~]# mysql -u root -p
Enter password:  (键入刚才重新设置的密码后,会登录进入MySQL的操作界面)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30
Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type "help;" or "\h" for help. Type "\c" to clear the current input statement.

mysql>

按照这个脚本来创建账户

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

控制台输出

mysql> create database zrlog_demo;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE USER "zrlog_demo"@"%" IDENTIFIED WITH mysql_native_password BY "aeshai0..Een1jah";
Query OK, 0 rows affected (0.01 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> GRANT ALL privileges ON `zrlog_demo`.* TO "zrlog_demo"@"%";
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

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

mysql -uzrlog_demo -p

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| performance_schema |
| zrlog_demo         |
+--------------------+
3 rows in set (0.00 sec)

mysql> use zrlog_demo;
Database changed
mysql> create table test(id bigint);
Query OK, 0 rows affected (0.02 sec)

mysql> select * from test;
Empty set (0.01 sec)

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

安装 Docker

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

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

启动 Docker 服务是否正常启动

sudo systemctl start docker
sudo systemctl status docker

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

# (如果由于某些特殊原因无法完成 clone 可以使用 https://gitee.com/94fzb/zrlog-docker)
git clone https://github.com/94fzb/zrlog-docker
cd zrlog-docker
# 构建最新的 zrlog docker 镜像
sh build.sh
# 进入安装引导模式
sh install.sh
# 访问 http://xxx.xx.xx.xx:28080/ (host部分自己改成对于的) 通过安装引导完成 zrlog 初始化,根据安装提示完成配置

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

参考