NextCloud - Funky Penguin's Geek Cookbook

Nextcloud (a fork of OwnCloud, led by original developer Frank Karlitschek) is a suite of client-server software for creating and using file hosting services. It is functionally similar to Dropbox, although Nextcloud is free and open-source, allowing anyone to install and operate it on a private server. - https://en.wikipedia.org/wiki/Nextcloud


This is a companion discussion topic for the original entry at https://geek-cookbook.funkypenguin.co.nz/recipies/nextcloud/

I had a pop at this today and I just get the following error:

 Error while trying to create admin user: Failed to connect to the database:
 An exception occured in driver: SQLSTATE[HY000] [1130] 
 Host '172.16.12.12' is not allowed to connect to this MariaDB server	

I followed the instructions to the letter, updated the Traefik hostname and deployed it. I get taken to a page to finalise setup where most of the fields are already filled in. I’m just asked to provide the admin password and the database password. Here is a pic: Imgur: The magic of the Internet

Any ideas?

EDIT: Yes, I made sure to use the same passwords as I set up in the env file :stuck_out_tongue:

OK, I think what we’re seeing here might be an interaction between the env variables used for the database backup container, and the built-in env variables mysql/mariadb uses.

I just confirmed this simple example is working

services:
  nextcloud:
    image: nextcloud
    env_file: /var/data/config/nextcloud/nextcloud-dbtest.env
    networks:
      - internal
      - traefik_public
    deploy:
      labels:
        - traefik.frontend.rule=Host:nextcloud-dbtest.funkypenguin.co.nz
        - traefik.docker.network=traefik_public
        - traefik.port=80
    volumes:
      - /var/data/nextcloud-dbtest/:/var/www/html
      - /var/data/nextcloud-dbtest/apps:/var/www/html/custom_apps
      - /var/data/nextcloud-dbtest/config:/var/www/html/config
      - /var/data/nextcloud-dbtest/data:/var/www/html/data

  db:
    image: mariadb:10
    env_file: /var/data/config/nextcloud/nextcloud-dbtest.env
    networks:
      - internal
    volumes:
      - /var/data/runtime/nextcloud-dbtest/db:/var/lib/mysql

With env file:

[root@ds1 nextcloud]# cat nextcloud-dbtest.env
DB_TYPE=mysql
DB_NAME=nextcloud
DB_USER=nextcloud
DB_PASSWORD=nextcloud
DB_HOST=db

# For mysql
MYSQL_ROOT_PASSWORD=batman
MYSQL_DATABASE=nextcloud
MYSQL_USER=nextcloud
MYSQL_PASSWORD=nextcloud

Can you try stripping out the last 5 lines of the env file per the recipe (starting with # For database backup), and see whether this works? You may need to delete the contents of /var/data/runtime/nextcloud/db/ to force MariaDB to recreate them.

D

Bingo! Thanks boss :smiley:

If anyone has an issue with Solr not starting properly, try:

sudo chmod 777 /var/data/runtime/nextcloud/solr

Good to know :slight_smile: I’ve updated the recipe to indicate that we need a separate env file for the db-backup container : NextCloud |・∀・

@funkypenguin I have a question, might be a silly one at that. But how are you running this? I am using ESXI VMs and I am trying to decipher how much of this and what parts are applicable to me. What I want to ultimately do is run nextcloud stack and home assistant stack over SSL. Any help would be much appreciated, thanks.

Hey,

Personally, my stack runs Atomic VMs under OpenStack, but that’s just my personal situation. You could do the same under ESXi. I’d suggest you start with just one VM (you can still have a swarm with a single “manager” host), setup NextCloud and HA stacks with traefik per the cookbook.

D

@funkypenguin thanks for the reply, I have it running now. I used one VM with nextcloud and home assistant with traefik. I also didn’t deply a swarm. I would love to see your setup and try to immulate on my lab to see which runs better. I guess I would most likely have to have openstack integrate with my ESXi host then config 3 atomic vms in swarm.

Great guide thanks! This went mostly flawlessly for me, with the additional correction to the solr file permissions mentioned by @nick. Thanks Nick!

FYI The Nextant plugin is depreciated and folks are being directed to using Full Text Search ready for Nextcloud 14’s release. I’ll look at integrating that soon.

Thanks @seffyroff, I’ll be awaiting NextCloud 14 for a recipe refresh :wink:

D

I think that the recipe needs to be updated to use the nextcloud-db-backup.env

db-backup:
image: mariadb:10
env_file: /var/data/config/nextcloud/nextcloud-db-backup.env

@funkypenguin Thanks so much for this brother, it works like a charm in my swarm. minor db backup issues with permissions and nextant since it’s no longer supported and the nextcloud image was already updated to 14. Waiting patiently for the updated recipe (too lazy to update it myself for this as I’m not using it too much :smiley: )

Glad to hear it!

If you join the discord in http://chat.funkypenguin.co.nz, you’ll find there’s some other geeks using later versions of NextCloud, and a recipe update in the works :wink:

D

The command mysqldump -h db --all-databases is breaking shares which are shared from folders/files located on external storage connected via SMB.
Presumably need to put nextcloud in maintenance mode before performing dump.
For reference: Backup — Nextcloud latest Administration Manual latest documentation

The docs don’t explicitly mention switching to maintenance mode to make a database dump, but I do wonder whether --single-transaction might produce a better result… could you give it a try and confirm? (smb-mounted shares are a rarity here in Penguin HQ)…

Nextcloud may trow these errors:

{
  "reqId": "JPpNThdF9pv5dY5az5hV",
  "level": 3,
  "time": "2021-01-09T02:42:03+00:00",
  "remoteAddr": "",
  "user": "--",
  "app": "cron",
  "method": "",
  "url": "--",
  "message": {
    "Exception": "Doctrine\\DBAL\\DBALException",
    "Message": "Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known",
    "Code": 0,
    "Trace": [
      {

{
  "reqId": "xs4IclcejFUDAHThnt14",
  "level": 3,
  "time": "2021-01-09T03:02:57+00:00",
  "remoteAddr": "",
  "user": "--",
  "app": "cron",
  "method": "",
  "url": "--",
  "message": {
    "Exception": "Doctrine\\DBAL\\DBALException",
    "Message": "Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused",
    "Code": 0,
    "Trace": [
      {
        "file": "/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php",
        "line": 1449,
        "function": "connect",
        "class": "OC\\DB\\Connection",
        "type": "->",
        "args": []
      },

Reading from internet:

The --single-transaction should be enough. But what is the best way to implement maintenance mode to make it more safe ?