xiedeacc
发布于 2023-12-22 / 76 阅读
0
0

halo2 fatjar方式部署

halo2.0官方不再支持fatjar方式部署,遇到的坑不少,本文记录下fatjar方式遇到的坑。

一、环境搭建

首先参考官方文档https://docs.halo.run/developer-guide/core/prepare,搭建好开发环境。这里直接给下安装链接,环境变量等

1.1 java

参考 https://blog.xiedeacc.com/archives/init%20ubuntu%2022.04#8-5-java

1.2 nodejs

参考 https://blog.xiedeacc.com/archives/init%20ubuntu%2022.04#8-3-nvm

nvm install 18.19.0
nvm use 18.19.0

注意nvm windows环境下,如果安装在C盘的话,需要使用管理员权限运行cmd或者powershell,否则会因为权限问题,安装不成功

1.3 pnpm

# ubuntu
curl -fsSL https://get.pnpm.io/install.sh | sh -

# windows 用管理员权限运行powershell
iwr https://get.pnpm.io/install.ps1 -useb | iex

1.4 intellij idea

# ubuntu
https://download.jetbrains.com.cn/idea/ideaIU-2023.3.2.tar.gz

# windows
https://download.jetbrains.com.cn/idea/ideaIC-2023.3.2.exe

二、编译

git clone https://github.com/halo-dev/halo
cd halo
cd console
pnpm install
pnpm build:packages
pnpm build
cd ..

# 下载插件
# Windows
./gradlew.bat downloadPluginPresets
# macOS / Linux
./gradlew downloadPluginPresets

# 构建
# Windows
./gradlew.bat clean build -x check
# macOS / Linux
./gradlew clean build -x check

三、部署

3.1 安装mysql

apt install mysql-server
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

在[mysqld]下面加入skip-grant-tables并保存,然后重启mysql

sudo systemctl restart mysql

3.2 创建halo需要的用户、权限和库

mysql -uroot
create user 'tiger'@'localhost' identified by 'password'; 
grant all privileges on halodb.* to 'tiger'@'localhost' with grant option; 
flush privileges;
exit
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

删除skip-grant-tables并保存,然后重启mysql

3.3 配置halo

  • 将D:\code\java\halo\application\build\libs中的application-2.12.0-SNAPSHOT.jar包上传到/home/ubuntu/halo

  • 增加halo运行配置

mkdir ~/.halo2
vi ~/.halo2/application.yaml

添加如下内容

server:
  port: 8090
  # Response data gzip.
  compression:
    enabled: false
spring:
  #sql:
  #  init.platform: mysql
  r2dbc:
    url: r2dbc:pool:mysql://127.0.0.1:3306/halodb
    username: tiger
    password: xxxx

halo:
  # Your admin client path is https://your-domain/{admin-path}
  admin-path: admin
  # memory or level
  cache: level
  • 添加systemd配置

sudo vi /lib/systemd/system/halo2.service

添加如下内容

[Unit]
Description=Halo Service
Documentation=https://halo.run
After=network-online.target
Wants=network-online.target

[Service]
#ExecStart=/usr/local/jdk-17.0.9/bin/java -server -Xms256m -Xmx256m -jar /home/ubuntu/halo/application-2.12.0-SNAPSHOT.jar --spring.r2dbc.url=r2dbc:pool:mysql://127.0.0.1:3306/halodb --spring.r2dbc.username=tiger --spring.r2dbc.password=qh6288QHW
User=ubuntu
ExecStart=/usr/local/jdk-17.0.9/bin/java -server -Xms256m -Xmx256m -jar /home/ubuntu/halo/application-2.12.0-SNAPSHOT.jar --spring.config.additional-location=/home/ubuntu/.halo2/application.yaml
[Install]
WantedBy=multi-user.target

3.4 启动halo

sudo systemctl daemon-reload
sudo systemctl start halo2

3.5 安装插件

在console页面点击Plugins,点右上角Install,安装D:\code\java\halo\application\src\main\resources\presets\plugins目录下所有插件

四、推荐插件

  1. Vditor编辑器

  2. highlight.js 代码高亮

五、推荐主题

  1. Theme Joe3

六、tips

  • 使用浏览器访问xx.xxx.com,第一次会让设置账户密码等

  • systemd方式启动时一定要注意用户,如果不指定用户,将使用root用户启动进程,那么halo创建的目录将会是/root/.halo2而不是/home/ubuntu/.halo2

  • 如果不安装./gradlew downloadPluginPresets下载的插件,启动时将报错,但是不影响使用,可以参考 https://github.com/halo-dev/halo/issues/5089

  • 重启报LockObtainFailedException: Lock held by this virtual machine: /home/ubuntu/.halo2/indices/posts/write.lock是正常现象,一般会出现3次左右,但是持续不停的出现则不正常,可以参考https://github.com/halo-dev/halo/issues/5090

  • mysql存储方式,只有一张表,post,评论啥都存储在mysql

  • 验证码无法接收问题 https://github.com/halo-dev/halo/issues/5100


评论