实测Docker搭建短链接服务YOURLS

URL缩短服务。可以让你在自己的服务器上运行的URL缩短服务
URL简化可以完全控制自己的数据,包括简单的统计、分析和许多插件

2023年12月30日:逃离mysql数据库,拥抱它的分支MariaDB

原因:mysql在意外断电后,在此开启docker时报错无法解决,相比之下mariadb好香

有什么用

URL缩短服务。可以让你在自己的服务器上运行的URL缩短服务
URL简化, 还可以完全控制自己的数据,包括统计、分析、还可以安装一些插件。
发布clash的url链接,进行管理 【done yourls setup】

网上现成的其他方案,有的弊端很明显(有的进行隐藏式特殊的跳转)

现成网址缩短 url

短网址
https://t.hk.uy/b5kg
https://netlify.carlzeng.top 暂不支持您输入的域名(后缀)。
使用这个网址来缩短: https://sage-halva-bac054.netlify.app
https://t.hk.uy/b6qy

轻松缩短链接
https://goo.su/BwRaE1T
https://goo.su/prTA5T5

縮短網址產生器
https://tinyurl.com/yurgh2fm

老牌免费短网址工具
http://s8u.cn/HIG7o
优美,但无法接受:先跳转到一个链接以后,在恢复原始网址。

转变思路:
还是用自己的域名做Nname更短,
自己搭建一个短网址服务;短链接服务

实现方法及过程笔记

图文教程

【好玩儿的Docker项目】10分钟搭建一个自己的短链接服务——YOURLS
【伺服器】如何使用Docker自架私有短網址YOURLS服務

过程+遇到的问题及解决方案

bt 中新建docker-compose模版,
docker-compose -f yours.yml up
然后防火墙开放8200

      添加了一条防火墙规则后,无法连接bt面板了;

自己搭建一个短网址服务;短链接服务
https://blog.laoda.de/archives/docker-compose-install-yourls/index.html
https://www.youtube.com/watch?v=pz3XZG_QZ-U
旧版https://www.cnblogs.com/CyLee/p/16152673.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
version: "3.5"
services:

mysql:
image: mysql:5.7.42 # 如果遇到不正确的数据库配置,或无法连接到数据库PDOException: SQLSTATE[HY000] [1045] 用户'yourls'@'yourls_service.yourls_default'的访问被拒绝(使用密码:是) 可以把5.7.22 改为 5.7
environment:
- MYSQL_ROOT_PASSWORD=my-secret-pw
- MYSQL_DATABASE=yourls
- MYSQL_USER=yourls
- MYSQL_PASSWORD=yourls
volumes:
- ./mysql/db/:/var/lib/mysql
- ./mysql/conf/:/etc/mysql/conf # 此处要注意,原教程作者就是多了一个.d字符(估计是debian下的tab自动输入导致),花了半小时才脑补后排查成功
restart: always
container_name: yourls_mysql #是的这样命名可以避免docker多了以后,名字重复的问题;还一目了然

yourls:
image: yourls
restart: always
ports:
- "8200:80"
environment:
YOURLS_DB_HOST: mysql
YOURLS_DB_USER: admin
YOURLS_DB_PASS: admin
YOURLS_DB_NAME: yourls
YOURLS_USER: admin # 自己起一个名字
YOURLS_PASS: 123admin@@ # 自己换一个登陆密码
YOURLS_SITE: https://c.carlzeng.top:4443 # 换成你自己的域名,然后让Nginx Proxy Manager指向这个地址
YOURLS_HOURS_OFFSET: 8
volumes:
- ./yourls_data/:/var/www/html
container_name: yourls_service
links:
- mysql:mysql

报错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
yours_mysql     | 2023-11-07 13:33:44+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
yours_mysql | 2023-11-07 13:33:44+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
yours_mysql | 2023-11-07 13:33:44+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
yours_mysql | command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.5snRuPe4br
yours_mysql | mysqld: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 13 - Permission denied)
yours_mysql | mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
yours_mysql exited with code 1
yours_mysql | 2023-11-07 13:33:57+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
yours_mysql | 2023-11-07 13:33:57+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
yours_mysql | 2023-11-07 13:33:57+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
yours_mysql | command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.atOD1yOw77
yours_mysql | mysqld: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 13 - Permission denied)
yours_mysql | mysqld: [ERROR] Fatal error in defaults handling. Program aborted!

成功了,原来是sql的 docker-compose,映射,写错了,
- ./mysql/conf/:/etc/mysql/conf.d
应该是:
- ./mysql/conf/:/etc/mysql/conf

安装QR Code插件

过程非常简单:https://yourls.org/docs/development/examples/qrcode

配置:同一条链接对应多个短链接

同样是在刚刚修改语言的地方…/yourls_data/user/config.php
下面一行,把这个改成true就可以了~ (正常应该改成false才对的,感觉是个BUG = =)

1
2
3
4
5
6
7
8
9
10
/** Allow multiple short URLs for a same long URL
** Set to true to have only one pair of shortURL/longURL (default YOURLS behavior)
** Set to false to allow multiple short URLs pointing to the same long URL (bit.ly behavior) */
define( 'YOURLS_UNIQUE_URLS', getenv('YOURLS_UNIQUE_URLS') === true ?: filter_var(getenv('YOURLS_UNIQUE_URLS'), FILTER_VALIDATE_BOOLEAN) );

修改用户名密码等,都在这个配置文件中/user/config.php


记得重启容器:
docker-compose -f 'yourls_service.yaml' restart

新增其他功能列表

YOURLS Password Protection
https://c.carlzeng.top:3/yourls

Migration to MariaDB [Done]

这些都不着急,如何把该死的数据库从mysql换mariadb才是硬道理,数据都丢2次了;只要是意外关闭这个docker(比如强制断电后恢复通电,强制跳掉整台虚拟机),都会导致mysql无法正常启动,导致数据丢失.

切换成功, 把上面的yaml中的mysql数据库部分切换成这样,就ok了,
期待下次意外断电或任何特殊情况下的数据恢复表现。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
mysql:
image: mariadb:jammy #mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=my-secret-pw
- MYSQL_DATABASE=yourls
- MYSQL_USER=yourls
- MYSQL_PASSWORD=yourls
volumes:
#- ./mysql20231229/db/:/var/lib/mysql
#- ./mysql20231229/conf/:/etc/mysql/conf
- ./yMariaDb:/var/lib/mysql
#- ./OLDmysql_20231120/db/:/var/lib/mysql
restart: always
container_name: yourls_mysql

灵感来源

Docker yours_mysql不断重启的

yours_mysql,查看日志:

1
2
3
4
5
6
7
2023-11-19 11:58:34+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
2023-11-19 11:58:34+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2023-11-19 11:58:34+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
2023-11-19 11:58:34+00:00 [Note] [Entrypoint]: Initializing database files
2023-11-19T11:58:34.668526Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-11-19T11:58:34.671001Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2023-11-19T11:58:34.671049Z 0 [ERROR] Aborting

安装目录:cd /www/server/panel/data/compose/yourls_service/template

发现是mysql 的冲突了

1
2
3
4
5
6
7
8
9
    docker update --restart=no mysql
docker stop mysql

docker stop php nginx redis

#先关闭
docker-compose -f 'yourls_service.yaml' down
#再开启
docker-compose -f 'yourls_service.yaml' up

docker exec -it yourls_mysql /bin/bash
无法进入。

the issue is about the volume.
https://www.youtube.com/watch?v=pFQC2F8SRag

  1. docker info
    Docker Root Dir: /var/lib/docker
  2. cd /var/lib/docker
  3. cd volumes/
  4. ls
    backingFsBlockDev metadata.db
    没有发现视频中说的额外的volume,也就无从删除

20231120 无法解决[已解决];直接更换docker的映射目录,全部重装。数据丢失(包含缩短网址的数据和访问统计数据)。
这样配置的端地址的列表,要支持导出(或备份);在特殊情况下,直接全部重来(更省时)

完成的方案是:使用GautamGupta/YOURLS-Import-Export插件即可轻松实现导出和导入功能
详细的安装步骤为

  1. Download the zip.
  2. Extract the zip.
  3. Put the YOURLS-Import-Export folder in the user/plugins directory.
  4. Activate the plugin.
  5. Restart the docker
    docker-compose -f ‘yourls_service.yaml’ restart

感受:非常好用,比如导出了一个当前的所有链接yourls_export.csv

衍生阅读:https://github.com/YOURLS/awesome#plugins
这个Plugins列表是按英文字母的顺序分类排列的,具体还是在页面上搜索文本来查找所需的功能

Next TODO

功能:分析用户的具体属性信息,比如IP地址,GEO地址,类似于statcounter.com那样的详细列表

yourls-geoip-update

https://mirror.ghproxy.com/https://github.com/ozh/yourls-geoip-update/archive/refs/heads/master.zip

1
2
Database not updated.
Error downloading "GeoLite2-Country". Invalid license key.
尽力了,哪位大神来帮忙纠正一下子?

20231208 尝试在目录下手工更新mmdb数据库文件 ./yourls_data20231120/includes/geo

  1. 上传GeoLite2-City.mmdb
  2. 复制并覆盖原先的GeoLite2-Country.mmdb
  3. 这样就有两个从原先5.41MB的文件变成了两个最新版64.34MB的文件
  4. TODO 静观其变

20231216 实践证明没有变化。下一步动作

  1. 下载alecthw/mmdb_china_ip_list获得文件Country.mmdb

  2. 上传至./yourls_data20231120/includes/geo,覆盖原先的GeoLite2-Country.mmdb.

  3. 重启Docker,TODO 静观其变

优缺点

Yourls的优点

很多插件可以随意拼装。插件列表:https://github.com/YOURLS/awesome

Yourls的缺点

统计功能很初级,很弱;基本上在搞笑的级别。

文档也不清晰易得,GeoIP update失败,那么手动上传IP数据到那么目录呢? 居然google不到


Docker安装X-UI

docker 搭建 支持单端口多用户、多协议的 xray 面板,究极缝合怪

使用FranzKafkaYu/x-ui版本,仅需要讲上述镜像修改为 enwaiax/x-ui:alpha-zh
由于telegram bot暂时没用,切换回第一个默认https://github.com/vaxilu/x-ui

1
2
3
4
5
6
7
8
9
10
version: "3.9"
services:
xui:
image: enwaiax/x-ui
container_name: xui
volumes:
- $PWD/db/:/etc/x-ui/
- $PWD/cert/:/root/cert/
restart: unless-stopped
network_mode: host

新建目录,并把上面的配置放到x-ui.yaml中
root@Debian11:/www/server/panel/data/compose/x-ui/template# docker-compose -f x-ui.yaml up

https://www.amadues.link/archives/dockerda-jian-jie-dian-vless-ws-tls-web
docker-compose.yaml的方案follow:https://hostloc.com/thread-1108468-1-1.html
配置的方案follow:https://iwanlab.com/npm-xui/
相关的视频:https://www.youtube.com/watch?v=V3nsDicSMBc

待测试:vless://39fde2d2-c88c-4bea-d491-fb6990d49741@vmess.carlzeng.top:17866?type=ws&security=none&path=%2Fgugu#gugugee

可以打开后台配置 http://192.168.6.116:54321/fk/xui/
没成功…期待更多的客户端连接测试, 等救援

思路有问题:x-ui是一个服务端的节点!

待续。。。