使用Plik搭建一个临时文件上传系统,自定义时长/下载即摧毁

/ 0评 / 0

说明:Plik是一个基于golang的可扩展且友好的临时文件上传系统。上传者可自定义文件保留时长,设置下载密码,允许上传者随时删除文件,设置下载一次就自动删除,二维码下载,上传者还可以选择不保存在服务器里,直接传到免费服务(貌似用的ShareX),还支持在线播放mp3/mp4文件,及一些功能拓展,挺强的,安装也简单。

截图

请输入图片描述
请输入图片描述

安装

Github地址:https://github.com/root-gg/plik

可以直接用作者编译好的包安装,下载地址:点击查看

<span class="hljs-meta"><span class="com">#</span></span><span class="bash"><span class="com">下载最新版本的Plik,目前是1.2.3版本</span></span><span class="pln">
wget https</span><span class="pun">:</span><span class="com">//github.com/root-gg/plik/releases/download/1.2.3/plik-1.2.3-linux-64bits.tar.gz</span>
<span class="hljs-meta"><span class="com">#</span></span><span class="bash"><span class="com">解压</span></span><span class="pln">
tar xzvf plik</span><span class="pun">-</span><span class="lit">1.2</span><span class="pun">.</span><span class="lit">3</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="lit">64bits</span><span class="pun">.</span><span class="pln">tar</span><span class="pun">.</span><span class="pln">gz
</span><span class="hljs-meta"><span class="com">#</span></span><span class="bash"><span class="com">运行</span></span><span class="pln">
cd plik</span><span class="pun">-</span><span class="lit">1.2</span><span class="pun">.</span><span class="lit">3</span><span class="pun">/</span><span class="pln">server
</span><span class="pun">./</span><span class="pln">plikd</span>

然后就可以访问IP:8080查看了,程序的配置文件在server/plikd.cfg,可以设置监听端口/最大上传/默认保存天数等等,上传文件默认保存在server/files

如果Web界面打不开,可能需要开启防火墙端口。

<span class="hljs-comment"><span class="com">#CentOS 6</span></span>
<span class="hljs-attribute"><span class="pln">iptables</span></span> <span class="pun">-</span><span class="pln">I INPUT </span><span class="pun">-</span><span class="pln">p tcp </span><span class="pun">--</span><span class="pln">dport </span><span class="hljs-number"><span class="lit">8080</span></span> <span class="pun">-</span><span class="pln">j ACCEPT
service iptables save
service iptables restart

</span><span class="hljs-comment"><span class="com">#CentOS 7</span></span><span class="pln">
firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">zone</span><span class="pun">=</span><span class="kwd">public</span> <span class="pun">--</span><span class="pln">add</span><span class="pun">-</span><span class="pln">port</span><span class="pun">=</span><span class="hljs-number"><span class="lit">8080</span></span><span class="pun">/</span><span class="pln">tcp </span><span class="pun">--</span><span class="hljs-literal"><span class="pln">permanent</span></span><span class="pln">
firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">reload</span>

最后设置完毕后就需要程序常驻后台了,可以使用screen命令。

Docker安装

1、安装Docker

<span class="hljs-comment"><span class="com">#CentOS 6</span></span>
<span class="hljs-attribute"><span class="pln">rpm</span></span> <span class="pun">-</span><span class="pln">iUvh http</span><span class="pun">:</span><span class="com">//dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm</span><span class="pln">
yum update </span><span class="pun">-</span><span class="pln">y
yum </span><span class="pun">-</span><span class="pln">y install docker</span><span class="pun">-</span><span class="pln">io
service docker start
chkconfig docker </span><span class="hljs-literal"><span class="pln">on</span></span>

<span class="hljs-comment"><span class="com">#CentOS 7、Debian、Ubuntu</span></span><span class="pln">
curl </span><span class="pun">-</span><span class="pln">sSL https</span><span class="pun">:</span><span class="com">//get.docker.com/ | sh</span><span class="pln">
systemctl start docker
systemctl enable docker</span><span class="pun">.</span><span class="pln">service</span>

2、安装镜像

<span class="hljs-comment"><span class="com">#建一个保存Plik数据的文件夹</span></span>
<span class="hljs-attribute"><span class="pln">mkdir</span></span> <span class="pun">/</span><span class="typ">Plik</span> <span class="pun">&&</span><span class="pln"> cd </span><span class="pun">/</span><span class="typ">Plik</span>
<span class="hljs-comment"><span class="com">#下载配置文件,可以保持默认,也可以编辑</span></span><span class="pln">
wget https</span><span class="pun">:</span><span class="com">//raw.githubusercontent.com/root-gg/plik/master/server/plikd.cfg</span>
<span class="hljs-comment"><span class="com">#启动容器</span></span><span class="pln">
docker run </span><span class="pun">--</span><span class="pln">name pilk </span><span class="pun">-</span><span class="pln">d </span><span class="pun">-</span><span class="pln">p </span><span class="hljs-number"><span class="lit">8080</span></span><span class="pun">:</span><span class="hljs-number"><span class="lit">8080</span></span> <span class="pun">-</span><span class="pln">v </span><span class="pun">/</span><span class="typ">Plik</span><span class="pun">/</span><span class="pln">plikd</span><span class="pun">.</span><span class="pln">cfg</span><span class="pun">:</span><span class="str">/home/</span><span class="pln">plik</span><span class="pun">/</span><span class="pln">server</span><span class="pun">/</span><span class="pln">plikd</span><span class="pun">.</span><span class="pln">cfg </span><span class="pun">-</span><span class="pln">v </span><span class="pun">/</span><span class="typ">Plik</span><span class="pun">/</span><span class="pln">files</span><span class="pun">:</span><span class="str">/home/</span><span class="pln">plik</span><span class="pun">/</span><span class="pln">server</span><span class="pun">/</span><span class="pln">files rootgg</span><span class="pun">/</span><span class="pln">plik</span>

然后就可以打开IP:8080了,配置文件为/Plik/plikd.cfg,上传文件在/Plik/files,当然外部端口,文件路径可自行修改。

最后我们需要给外部存储目录,也就是/Plik/files文件夹777权限,不然上传会失败。

<span class="hljs-attribute"><span class="pln">chmod</span></span> <span class="hljs-number"><span class="lit">777</span></span> <span class="pun">/</span><span class="typ">Plik</span><span class="pun">/</span><span class="pln">files</span>

域名访问

如果想通过域名访问的就需要使用域名反代了,这里就使用最方便的Caddy,请提前解析好域名到服务器,过程会自动签发SSL

1、安装Caddy
使用命令:

<span class="hljs-attribute"><span class="pln">wget</span></span> <span class="pun">-</span><span class="pln">N </span><span class="pun">--</span><span class="hljs-literal"><span class="kwd">no</span></span><span class="pun">-</span><span class="pln">check</span><span class="pun">-</span><span class="pln">certificate https</span><span class="pun">:</span><span class="com">//raw.githubusercontent.com/ToyoDAdoubi/doubi/master/caddy_install.sh && chmod +x caddy_install.sh && bash caddy_install.sh install http.filemanager</span>
<span class="hljs-comment"><span class="com">#备用地址</span></span><span class="pln">
wget </span><span class="pun">-</span><span class="pln">N </span><span class="pun">--</span><span class="hljs-literal"><span class="kwd">no</span></span><span class="pun">-</span><span class="pln">check</span><span class="pun">-</span><span class="pln">certificate https</span><span class="pun">:</span><span class="com">//www.moerats.com/usr/shell/Caddy/caddy_install.sh && chmod +x caddy_install.sh && bash caddy_install.sh install http.filemanager</span>

2、配置Caddy

<span class="hljs-comment"><span class="com">#以下全部内容是一个整体,请修改域名后一起复制到SSH运行!</span></span>
<span class="hljs-attribute"><span class="pln">echo</span></span> <span class="hljs-string"><span class="str">"xx.com {
 gzip
 tls admin</span><span class="hljs-variable"><span class="str">@moerats</span></span><span class="str">.com
 proxy / 0.0.0.0:8080
}"</span></span> <span class="pun">></span> <span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">caddy</span><span class="pun">/</span><span class="typ">Caddyfile</span>

tls参数会自动帮你签发ssl证书,如果你要使用自己的ssl,改为tls /root/xx.crt /root/xx.key即可。后面为ssl证书路径。

3、启动Caddy

<span class="str">/etc/</span><span class="pln">init</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">caddy </span><span class="hljs-keyword"><span class="pln">start</span></span>

如果启动失败,使用tail -f /tmp/caddy.log查看启动日志,可以自己分析下错误日志,如果不会就留言。

启动成功后就可以打开https://xx.com访问了。最后Plik附带一个功能强大的golang多平台cli客户端,不过使用起来挺麻烦的,适用性貌似不是很大,就不研究了。当然如果你有兴趣,可以查看Github项目地址。

发表评论