3

自建 busuanzi 不蒜子平台统计平台

 10 months ago
source link: https://lanyundev.com/posts/c7a2c1cf
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

LanYun の Blog

自建 busuanzi 不蒜子平台统计平台

发表于 2023-08-19|更新于 2023-08-19|教程
字数总计:758|阅读时长:2 分钟 | 阅读量:2

公益统计服务 busuanzi 官网: https://busuanzi.ibruce.info/

由于速度很慢,故打算自建。本文用到的项目地址: https://github.com/soxft/busuanzi

本来不想水一篇的,因为项目中的 wiki 已很清楚了,而且还支持 docker 部署.

但我还是想简单记录一下搭建过程 (省略了某些简单的步骤), 各位可以参考参考.

本文不采用 docker 方式搭建,因为要和 cloudflared 搭配,组成隧道.

基本前提:有域名,有 linux 服务器

本文 linux 服务器以 arch Linux 为例.

在你想要的目录下运行命令.(下面示例为 root)

1
2
3
4
5
pacman -S git go redis # 如果已安装可以跳过
git clone https://github.com/soxft/busuanzi.git # 可以拉取我fork的仓库
# https://github.com/LanYunDev/busuanzi.git 我合并了yuantuo666和soxft仓库,代码最新且带有web管理功能.
cd busuanzi
go build -o busuanzi main.go

修改 busuanzi 目录下 config.yml 配置文件.

首先是 Web 中的 Address, 由于我们要做隧道,所以没必要公网访问,所以加上 127.0.0.1:xxx , 这里 xxx 代表端口号,建议填高位.

可以用命令 lsof -i -n -P | grep LISTEN 来检查端口使用情况,

Debug 测试的时候可以开一下,后面建议关了.

接下来就是 Redis 部分

首先 Address 为你 redis 的地址。例如本机: 127.0.0.1:6379

AddressPassword, 如果你是全新安装的,没动过 redis 配置,那就不用改.

但如果改了,或者想确认一下。可以这样做.

1
2
cat /etc/redis/redis.conf | grep '^port' # 端口
cat /etc/redis/redis.conf | grep '^requirepass' # 密码,如果没有结果代表是被#注释了,即为空密码

关于 Expire, 自用的话,可以设置为 0

关于 JwtSecret, 我推荐用 uuid 来做签名密钥。输入命令 uuidgen 即可得到 uuid

修改 dist/busuanzi.js 文件中 api 的地址。例如我改为 https://busuanzi.lanyundev.com/api

如果你用带有 web 管理功能的 busuanzi

Admin 中 Password 记得改密码.

关于 cloudflared 搭建哪些看官方文档就行了,写的非常清楚.

记录一下,添加 DNS 记录命令: cloudflared tunnel route dns -f xxx busuanzi.lanyundev.com

主要注意一下,cloudflared 进行 DNS (dig) 查询时,别被劫持了.(如果能用,就不用管这个.)

1
systemctl enable --now redis.service # 设置为开机启动并启动redis

vim /etc/systemd/system/busuanzi.service 添加下面内容 (ExecStart 根据个人情况修改.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[Unit]
Description=busuanzi Service
Documentation=https://github.com/soxft/busuanzi
After=network.target nss-lookup.target

[Service]
Type=simple
#DynamicUser=yes
User=root:
Environment=QUIC_GO_ENABLE_GSO=true
ExecStart=/root/busuanzi/busuanzi
WorkingDirectory=/root/busuanzi/
Restart=on-failure
LimitNPROC=512
LimitNOFILE=infinity

[Install]
WantedBy=multi-user.target

弄成服务,方便管理.

1
2
systemctl daemon-reload
systemctl enable --now busuanzi.service

Web 管理

Address + /admin 进入管理界面。可以修改数据.

在没换之前,可以参考这个域名 busuanzi.ibruce.info 的响应,里面有 Site PV Site UV Page PV 等原来的信息.

其实,这个可有可无,数据而已,真假都无所谓的。看个人吧,我就直接取整数.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK