Docker 搭建Koel 详细教程
准备步骤,安装docker
yum -y install docker
systemctl enable docker
安装docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
新建一个 koel 目录备用
mkdir koel
cd koel
新建一个目录存放文件
mkdir /opt/music
/opt/music/covers
准备你的域名 a.com
准备 docker-compose.yml 文件
######################################
# docker-compose.yml 可以修改你的数据库密码
version: '3.5'
services:
koel:
image: hyzual/koel
depends_on:
- koel-database
ports:
- "127.0.0.1:2077:80"
environment:
FORCE_HTTPS: 1
MEMORY_LIMIT: 512
DB_CONNECTION: mysql
DB_HOST: koel-database
DB_USERNAME: koel
DB_PASSWORD: Koko0202#1234
DB_DATABASE: koel
volumes:
- /opt/music:/music
- /opt/music/covers:/var/www/html/public/img/covers
restart: unless-stopped
koel-database:
image: mysql/mysql-server:5.7
environment:
MYSQL_ROOT_PASSWORD: Koko0202#1234
MYSQL_DATABASE: koel
MYSQL_USER: koel
MYSQL_PASSWORD: Koko0202#1234
volumes:
- koel_db:/var/lib/mysql
restart: unless-stopped
volumes:
koel_db:
driver: local
koel_music:
driver: local
koel_covers:
driver: local
#docker-compose.yml 文件结束
###################
启动docker
docker-compose up -d
看到都成功了,即可
安装nginx 和 python-certbot-nginx
python-certbot-nginx 是维护lets' encrypt 证书用的
yum -y install nginx
yum install python-certbot-nginx
初始化koel
docker-compose exec k2_koel_1 php artisan koel:init
docker exec -it k2_koel_1 php artisan koel:admin:change-password
k2_koel_1 是koel 容器名字,根据你情况来。默认管理员是:admin@koel.dev
处理nginx 和 https问题
新建nginx配置文件只带http 80端口版本的,命名为 koel.conf 放在 /etc/nginx/conf.d/
server {
listen 80;
listen [::]:80;
server_name a.com;
location / {
proxy_pass http://127.0.0.1:2207;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
# Not sure if these next two lines are needed. I did not remove them as
# I did not want risk breaking my working configuration. Just remember
# to replace "koel.domain.tld" with your instance's domain.
sub_filter "http://koel.domain.tld" "http://music.idcpay.me";
sub_filter_once off;
}
}
启动nginx
再启动cerbot
certbot certonly --nginx
生成key/pem文件后,重新设置https版本配置文件
server {
listen 80;
listen [::]:80;
listen 443 ssl;
server_name a.com;
ssl_certificate /etc/letsencrypt/live/music.idcpay.me/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/music.idcpay.me/privkey.pem;
location / {
proxy_pass http://127.0.0.1:2077;
# 如果是本机直接复制就行,如果是别的机器,记得换成你的ip地址
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
# Not sure if these next two lines are needed. I did not remove them as
# I did not want risk breaking my working configuration. Just remember
# to replace "koel.domain.tld" with your instance's domain.
sub_filter "http://koel.domain.tld" "https://music.idcpay.me";
sub_filter_once off;
}
}
运行:
nginx -s reload
如果没有错误,就可以输入 https://a.com 欣赏你的音乐了。
其他资源:
阿里云盘音乐豆瓣250无损flac:
https://www.aliyundrive.com/s/xuLCHkV97ML/folder/60dbe0c6f4f846a765ca403e982fa00b2849bd46
linux环境下载阿里云盘的客户端:
https://github.com/tickstep/aliyunpan
不需要下载再上传文件
音乐管理:
把mp3 flac等音乐文件放到虚拟主机的这里:
/opt/music
在Koel 面板上,扫描:
/music 目录,可以扫出新增音乐