实测Docker搭建短链接服务YOURLS

发布时间 2023-11-27 08:27:49作者: CarlZeng
title: 实测Docker搭建短链接服务YOURLS
tags: [docker,短链接,YOURLS,URL缩短,NPM,debian,docker-compose]
url: https://www.carlzeng.top/202311081003
版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
date: 2023-11-08 10:03:29
categories: Docker

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

有什么用

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

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

报错误:

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

灵感来源

{% tabs 来源%}

Yourls项目地址:https://github.com/YOURLS/YOURLS
旧版本docker说明(实践后无法使用):https://hub.docker.com/_/yourls?tab=description
https://iwanlab.com/docker-compose-install-yourls/
https://blog.laoda.de/archives/yourls-building/
https://www.hellosanta.com.tw/knowledge/category-38/post-219

{% endtabs %}

Docker yours_mysql不断重启的

yours_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]: 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 的冲突了

    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列表是按英文字母的顺序分类排列的,具体还是在页面上搜索文本来查找所需的功能

同一条链接对应多个短链接

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

``` /** 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) );
记得重启容器:
docker-compose -f 'yourls_service.yaml' restart

新增其他功能列表

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

Next TODO

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


Docker安装X-UI

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

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

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

没成功...期待更多的客户端连接测试, 等救援

{% tabs 名称%}

待续。。。

{% endtabs %}