【Docker】图床搭建(NextCloud+Redis+Mariadb+PicGo+Typora)

1、准备工作

 # 工作目录请按需修改  
 work=/docker/nextcloud && mkdir -p $work && cd $work  
 
 # 防火墙  
 sudo ufw allow 7602/tcp comment 'nextcloud' && sudo ufw reload  
 sudo ufw allow 6379/tcp comment 'nextcloud' && sudo ufw reload  
 
 # 提前拉取镜像  
 docker pull nextcloud  
 docker pull mariadb  
 docker pull redis

2、配置 docker-compose

[[Docker#2、docker-compose 安装 | 安装]]

vim $work/docker-compose.yml
---
version: '3.2'

networks:
  default:
    name: nextcloud

services:
  app:
    image: nextcloud:latest
    restart: unless-stopped
    volumes:
      - ./app:/var/www/html
    environment:
      - MYSQL_PASSWORD=9x2GDKra # 按需修改
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=db
    ports:
      - 1016:80 # 按需修改
    networks:
      - default

  cache:
    image: redis:latest
    restart: unless-stopped
    expose:
     - "6379" # 可用此默认。因为这是暴露而不是映射
    volumes:
     - ./cache:/data
    command: redis-server --requirepass 'O6jfvJmc' # 按需修改 
    networks:
      - default
    
  db:
    image: mariadb:latest
    restart: unless-stopped
    # 下面的command与官网略有不同。它将有助于避免MYSQL数据库的4047报错。
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW --innodb-file-per-table=1 --skip-innodb-read-only-compressed
    volumes:
      - ./db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=FoSnyYeA # 按需修改
      - MYSQL_PASSWORD=9x2GDKra  # 按需修改,与上面nextcloud设置的MYSQL_PASSWORD相同
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    networks:
      - default
cd $work && docker-compose up -d

3、设置密码

登录NextCloud(http://46.192.16.171:1016/)

4、Redis 生效

sudo vim $work/app/config/config.php

$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  // 'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'memcache.distributed' => '\\OC\\Memcache\\Redis', // 分布式缓存使用Redis
  'memcache.locking' => '\\OC\\Memcache\\Redis', // 启用Redis缓存的文件锁
  'redis' => array(
    'host' => 'cache', // 这里和mariadb的逻辑相同,填写容器links时映射的主机名
    'port' => 6379,
    'password' => 'O6jfvJmc' // 这是之前在配置docker-compose时配置的redis密码
  ),
  'filelocking.enabled' => 'true',
  'apps_paths' =>
  array (
    0 =>
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 =>
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'instanceid' => 'oc3gft2lfnce',
  'passwordsalt' => 'x61JG2Xk/Um6B+parLUaX336xXTPng',
  'secret' => 'oymQ023OpD5cL8GtLiZwEzhAM/SL6Rg11thembvdGvY2goOg',
  'trusted_domains' =>
  array (
    0 => '46.192.16.171:1016',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '23.0.0.10',
  'overwrite.cli.url' => 'http://46.192.16.171:1016',
  'dbname' => 'nextcloud',
  'dbhost' => 'db',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => '9x2GDKra',
  'installed' => true,
);
cd $work && docker-compose down && docker-compose up -d

5、后台任务

由于 nextcloud 内部的文件和配置会在用户操作过程中产生变化,所以需要启用一个定时任务去定期整理和归档这些数据到数据库或者应用到配置中。

sudo vim /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# run nextcloud cron task every 5 min
*/5 * * * * root docker exec -u 33 nextcloud-app-1 php -f /var/www/html/cron.php 2>&1 /dev/null

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

6、下载PicGo下载地址

6.1、设置Server

Typora 默认端口是:36677
【Docker】图床搭建(NextCloud+Redis+Mariadb+PicGo+Typora)_第1张图片

6.2、安装插件

【Docker】图床搭建(NextCloud+Redis+Mariadb+PicGo+Typora)_第2张图片

6.3、图床设置

【Docker】图床搭建(NextCloud+Redis+Mariadb+PicGo+Typora)_第3张图片

6.4、Typora 设置

【Docker】图床搭建(NextCloud+Redis+Mariadb+PicGo+Typora)_第4张图片

你可能感兴趣的:(docker,redis,mariadb)