jhtone
jhtone
Published on 2024-10-07 / 67 Visits
2
0

WEB版二步验证

环境说明: 需要提前安装jdk8+版本

apk add openjdk11   #(alpine系统)
apt install default-jdk   #(Debian/Ubuntu)

登录Linux服务器,切换root用户

创建文件夹

mkdir -p mfa-start && cd mfa-start
mkdir -p data

下载安装包和配置文件

wget https://gitlab.com/jinhuaitao66/mfa/-/raw/main/mfa-start-release.jar
wget https://gitlab.com/jinhuaitao66/mfa/-/raw/main/mfa-start.yml
wget https://gitlab.com/jinhuaitao66/mfa/-/raw/main/mfa-start.sh

四:配置说明:

server:
  port: 9999(修改为自己的端口号)

spring:
  security:
    user:
      name: 面板登录用户名,自行指定
      password: 面板登录密码,自行指定

五:启动

5.1:给mfa-start.sh 执行权限添加 chmod 777 mfa-start.sh

5.2:启动程序 ./mfa-start.sh start

5.3:查看程序启动状态 ./mfa-start.sh status

5.4:停止程序 ./mfa-start.sh stop

开机自启(alpine系统)

创建自定义服务脚本 /etc/init.d/mfa-start

nano /etc/init.d/mfa-start

使用以下内容替换文件内容:

#!/sbin/openrc-run

command="/root/mfa-start/mfa-start.sh"
command_args="start"
pidfile="/var/run/mfa-start.pid"

depend() {
    need localmount
}

start_pre() {
    ebegin "Preparing to start mfa"
    # Ensure the script is executable
    chmod +x $command
    eend $?
}

start() {
    ebegin "Starting mfa"
    start-stop-daemon --start --pidfile $pidfile --make-pidfile --background --exec $command -- $command_args
    eend $?
}

stop() {
    ebegin "Stopping mfa"
    start-stop-daemon --stop --pidfile $pidfile
    eend $?
}

赋予执行权限:

chmod +x /etc/init.d/mfa-start

将服务添加到启动项

将服务添加到默认运行级别:

rc-update add mfa-start default

验证服务状态

手动启动服务以确认其正常工作:

rc-service mfa-start start

检查服务状态:

rc-service mfa-start status

Debian系统(开机自启)

nano /etc/systemd/system/mfa-start.service

1.修改内容如下:

[Unit]
Description=MFA Start Script
After=network.target

[Service]
Type=forking
ExecStart=/bin/bash /root/mfa-start/mfa-start.sh start
ExecStop=/bin/bash /root/mfa-start/mfa-start.sh stop
WorkingDirectory=/root/mfa-start
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
PIDFile=/var/run/mfa-start.pid
Restart=on-failure
User=root

[Install]
WantedBy=multi-user.target

2. 加载并测试服务

重新加载 systemd 配置并启动服务:

systemctl daemon-reload
systemctl enable mfa-start
systemctl start mfa-start
systemctl status mfa-start


Comment