filebrowser
filebrowser 是一个使用go语言编写的软件,功能是可以通过浏览器对服务器上的文件进行管理。可以是修改文件,或者是添加删除文件,甚至可以分享文件,是一个很棒的文件管理器,你甚至可以当成一个网盘来使用。总之使用非常简单方便,功能很强大。
caddy
Caddy 2是一个强大的,企业就绪的开源Web服务器,具有用Go编写的自动HTTPS
go
使用 Go 构建简单、安全、可扩展的系统。
download
go | caddy | filebrowser | nssm | ||
download | download | download | download | 命令使用参考 |
前提条件
- 开启wmi,配置网卡,参考
创建一键部署脚本
- 实现在线下载,安装,解压,目录创建,环境变量设置,配置文件创建,启动服务创建,防火墙配置,删除软件包。
- go 安装目录C:\Program Files\go
- caddy 安装目录C:\Program Files\Caddy
- caddy 配置文件目录C:\Caddy
- caddy 端口80 ,反向代理filebrowser 82端口
- filebrowser安装目录C:\Program Files\filebrowser
- nssm 安装目录C:\Program Files\nssm
- c:\filebrowser_data 此目录是filebrowser文件系统存储目录
- c:\filebrowser 数据库目录,日志输出目录
- filebrowser 默认用户名密码 admin/admin,建议更改默认密码,安全性考虑
.\powershell-install-filebrowser.ps1
<# Powershell Install filebrowser
+++++++++++++++++++++++++++++++++++++++++++++++++++++
+ _____ _____ _ _ _ +
+ | __ \ / ____| | | | |+
+ | |__) |____ _____ _ _| (___ | |__ ___| | |+
+ | ___/ _ \ \ /\ / / _ \ '__\___ \| '_ \ / _ \ | |+
+ | | | (_) \ V V / __/ | ____) | | | | __/ | |+
+ |_| \___/ \_/\_/ \___|_| |_____/|_| |_|\___|_|_|+
+ +++++++++++++++++++++++++++++++++++++++++++++++++++# Powershell Install filebrowser
# .\powershell-install-filebrowser.ps1
#> $drive="c:\"
$caddy_url="https://github.com/caddyserver/caddy/releases/download/v2.6.4/"
$caddy_zip="caddy_2.6.4_windows_amd64.zip"
$caddy_new="Caddy"
$system_site="C:\Program Files\"$filebrowser_url="https://github.com/filebrowser/filebrowser/releases/download/v2.23.0/"
$filebrowser_zip="windows-amd64-filebrowser.zip"
$filebrowser_new="filebrowser"
$filebrowser_data="filebrowser_data"$go_url="https://golang.google.cn/dl/"
$go_zip="go1.20.3.windows-amd64.zip"$nssm_url="https://nssm.cc/release/"
$nssm_zip="nssm-2.24.zip"
$nssm_catalogue="nssm-2.24"
$nssm_new="nssm"Write-Host "download caddy" -ForegroundColor Green
Invoke-WebRequest -Uri $caddy_url\$caddy_zip -OutFile $drive\$caddy_zip
New-Item -ItemType Directory -Path $system_site\$caddy_new -Force
Expand-Archive -Path $drive\$caddy_zip -DestinationPath $system_site\$caddy_new -ForceWrite-Host "download filebrowser" -ForegroundColor Green
Invoke-WebRequest -Uri $filebrowser_url\$filebrowser_zip -OutFile $drive\$filebrowser_zip
New-Item -ItemType Directory -Path $system_site\$filebrowser_new -Force
Expand-Archive -Path $drive\$filebrowser_zip -DestinationPath $system_site\$filebrowser_new -ForceWrite-Host "download go" -ForegroundColor Green
Invoke-WebRequest -Uri $go_url\$go_zip -OutFile $drive\$go_zip
Expand-Archive -Path $drive\$go_zip -DestinationPath $system_site -ForceWrite-Host "download nssm" -ForegroundColor Green
Invoke-WebRequest -Uri $nssm_url\$nssm_zip -OutFile $drive\$nssm_zip
Expand-Archive -Path $drive\$nssm_zip -DestinationPath $system_site -Force
Rename-Item -Path $system_site\$nssm_catalogue -NewName $nssm_newWrite-Host "Create caddy go filebrowser nssm environment variables" -ForegroundColor Green
$env:path += ";C:\Program Files\Caddy"
$env:path += ";C:\Program Files\filebrowser"
$env:path += ";C:\Program Files\go"
$env:path += ";C:\Program Files\go\bin"
$env:path += ";C:\Program Files\nssm\win64"
setx PATH $env:path /MWrite-Host "create directory caddy filebrowser filebrowser_data" -ForegroundColor Green
New-Item -ItemType Directory -Path $drive$caddy_new -Force
New-Item -ItemType Directory -Path $drive\$filebrowser_new -Force
New-Item -ItemType Directory -Path $drive\$filebrowser_data -ForceWrite-Host "caddy config Caddyfile" -ForegroundColor Green
@"
:80 {
# Set this path to your site's directory.
root * C:\filebrowser# Enable the static file server.
file_server
encode gzip# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080
reverse_proxy localhost:82# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000
}
"@ | Out-File -Encoding utf8 "C:\Caddy\Caddyfile"Write-Host "Create a system service for Caddy" -ForegroundColor Green
New-Service -Name Caddy -BinaryPathName "C:\Program Files\Caddy\caddy.exe run --environ --config C:\Caddy\Caddyfile" -DisplayName "Caddy" -Description "Caddy Engine - Enterprise Edition"
Start-Service "Caddy"#手动启动Filebrowser服务,创建多个目录就可以实现多个Filebrowser服务产生
#& 'C:\Program Files\filebrowser\filebrowser.exe' -r C:\filebrowser_data -d C:\filebrowser\filebrowser.db --port 82 --log C:\filebrowser\filebrowser.logWrite-Host "Example Create a system startup service filebrowser" -ForegroundColor Green
nssm install Filebrowser "C:\Program Files\filebrowser\filebrowser.exe"
nssm set Filebrowser Application C:\Program Files\filebrowser\filebrowser.exe
nssm set Filebrowser AppDirectory C:\Program Files\filebrowser
nssm set Filebrowser AppParameters -r C:\filebrowser_data -d C:\filebrowser\filebrowser.db --port 82 --log C:\filebrowser\filebrowser.log
Start-Service FilebrowserWrite-Host "check Caddy go filebrowser nssm version" -ForegroundColor Green
go version
filebrowser version
caddy version
(Get-Item "C:\Program Files\nssm\win64\nssm.exe").VersionInfo.FileVersionWrite-Host "firewall caddy port" -ForegroundColor Green
New-NetFirewallRule -DisplayName "caddy" -Direction Outbound -profile any -LocalPort 80 -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "caddy" -Direction Inbound -profile any -LocalPort 80 -Protocol TCP -Action AllowWrite-Host "delete all software package" -ForegroundColor Green
Remove-Item c:\*.zip -Recurse -Force -Verbose
Remove-Item c:\*.ps1 -Recurse -Force -Verbose
执行安装
.\powershell-install-filebrowser.ps1
输出结果
登录系统
- http://you_ip
- 默认用户名密码 admin/admin,建议登录更改默认密码
- 默认filebrowser 82,禁止外部直接访问,只允许通过caddy 80 端口代理访问