19
2025
06
15:39:45

MyUrls 基于 Go 1.24 与 Redis 实现的本地短链接服务,用于缩短 URL 与短链接还原。

QQ_1750320556201.png


MyUrls

基于 Go 1.24 与 Redis 实现的本地短链接服务,用于缩短 URL 与短链接还原。

Table of Contents

Dependencies

本服务依赖于 Redis 提供长短链接映射关系存储,你需要本地安装 Redis 服务来保证短链接服务的正常运行。

sudo apt-get update# 安装Redissudo add-apt-repository ppa:chris-lea/redis-server -y 
sudo apt-get update 
sudo apt-get install redis-server -y

Docker

现在你可以无需安装其他服务,使用 docker 或 docker-compose 部署本项目。注:请自行修改 .env 中参数。

docker run -d --restart always --name myurls careywong/myurls:latest -domain example.com -port 8002 -conn 127.0.0.1:6379 -password ''
git clone https://github.com/CareyWang/MyUrls.git MyUrlscd MyUrls
cp .env.example .env

docker-compose up -d

Install

安装项目依赖

make install

生成可执行文件,目录位于 build/ 。默认当前平台,其他平台请参照 Makefile 或执行对应 go build 命令。

make

Usage

前往 Actions 下载对应平台可执行文件。

Usage of ./MyUrls:
  -conn string
        address of the redis server (default "localhost:6379")
  -domain string
        domain of the server (default "localhost:8080")
  -h    display help
  -password string
        password of the redis server
  -port string
        port to run the server on (default "8080")
  -proto string
        protocol of the server (default "https")

建议配合 pm2 开启守护进程。

pm2 start myurls --name myurls -- -domain example.com

日志清理

假定工作目录为 /app,可基于 logrotate 配置应用日志的自动轮转与清理。可参考示例配置,每天轮转一次日志文件,保留最近7天

tee > /etc/logrotate.d/myurls <<EOF/app/logs/access.log {    daily    rotate 7    missingok    notifempty    compress    delaycompress    copytruncate    create 640 root adm}EOF# 测试是否正常工作,不会实际执行切割logrotate -d /etc/logrotate.d/myurls

Maintainers

@CareyWang

Contributing

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2024 CareyWang


开源地址分享https://github.com/CareyWang/MyUrls 



Almalinux9(CentOS9)安装MyUrls 短链接

下载MyUrls

git clone https://github.com/CareyWang/MyUrls.git

安装golang

dnf -y install golang

编译MyUrls

cd MyUrls
make

生成的二进制文件再build目录

整个目录拷到nginx的root的目录下 配合nginx访问

cp MyUrls /usr/wwwroot/myurls/myurls

创建myurls服务文件

vim /etc/systemd/system/myurls.service

[Unit]
Description=A API For Subscription Convert
After=network.target

[Service]
Type=simple
ExecStart=/usr/wwwroot/myurls/myurls -domain "example.com"WorkingDirectory=/usr/wwwroot/myurls
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.targetBASH复制全屏

安装redis

dnf -y install redis

启用服务

systemctl daemon-reload
systemctl start myurl.service

监听端口 8002




推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

本文链接:https://www.hqyman.cn/post/11683.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:
打赏





休息一下~~


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

请先 登录 再评论,若不是会员请先 注册

您的IP地址是: