diff --git a/manual/setup/migrate_non_docker_to_docker.md b/manual/setup/migrate_non_docker_to_docker.md index 8b0fbff2..f98a40fb 100644 --- a/manual/setup/migrate_non_docker_to_docker.md +++ b/manual/setup/migrate_non_docker_to_docker.md @@ -1,13 +1,22 @@ # Migrate from non-docker Seafile deployment to docker !!! note "For Seafile cluster" - This document is writting to about the single node, you have to do the following opeartions (except database) in **all nodes** + This document is writting to about the single node, you have to do the following opeartions (except migtating database) in **all nodes** + +The recommended steps to migrate from non-docker deployment to docker deployment are: + +1. Shutdown Seafile and native Nginx, Memcached +2. Backup Seafile data (database also neet to backup if you are not use an existed MySQL database to deploy non-Docker version Seafile) +3. Create the directory needed for Seafile Docker image to run, and recover the data. (If you are use an existed MySQL database to deploy non-Docker version Seafile, the data from database also need to recover) +4. Download the `.yml` files and `.env`. +5. Start Seafile Docker ## Before Migration - Upgrade the version of the binary package to [latest version](../upgrade/upgrade_notes_for_12.0.x.md), and ensure that the system is running normally. - - !!! tip - If you running a very old version of Seafile, you can following the [FAQ item](https://cloud.seatable.io/dtable/external-links/7b976c85f504491cbe8e/?tid=0000&vid=0000&row-id=VYQI9DJfRmCv5NggcX4f0Q) to migrate to the latest version + +Upgrade the version of the binary package to [latest version](../upgrade/upgrade_notes_for_12.0.x.md), and ensure that the system is running normally. + +!!! tip + If you running a very old version of Seafile, you can following the [FAQ item](https://cloud.seatable.io/dtable/external-links/7b976c85f504491cbe8e/?tid=0000&vid=0000&row-id=VYQI9DJfRmCv5NggcX4f0Q) to migrate to the latest version ## Stop Services @@ -30,55 +39,71 @@ su seafile ./seahub.sh start # Start seahub website, port defaults to 127.0.0.1:8000 ``` -### Stop Nginx and cached server (e.g., *Memcached*) +### Stop Nginx, cached server (e.g., *Memcached*), ElasticSearch + +You have to stop the above services to avoid losing data before migrating. ```sh systemctl stop nginx && systemctl disable nginx systemctl stop memcached && systemctl disable memcached +docker stop es && docker remove es ``` +If you are not using an existed MySQL, you have to shutdown MySQL service too. + ## Backup Seafile Please follow [here](../administration/backup_recovery.md#backup-and-restore-for-binary-package-based-deployment) to backup: -- Backing up Databases +- Backing up Databases (only if you are not using an existed database to deploy non-Docker version Seafile) - Backing up Seafile library data -## +## Download the docker-compose files + +You have to download the latest docker-compose files (i.e., series of `.yml` and its configuration file `.env`) in order to startup the relative services: + +=== "Seafile CE" + + ```sh + wget -O .env https://manual.seafile.com/12.0/docker/ce/env + wget https://manual.seafile.com/12.0/docker/ce/seafile-server.yml + wget https://manual.seafile.com/12.0/docker/caddy.yml + ``` + +=== "Seafile Pro" + + ```sh + wget -O .env https://manual.seafile.com/12.0/docker/pro/env + wget https://manual.seafile.com/12.0/docker/pro/seafile-server.yml + wget https://manual.seafile.com/12.0/docker/caddy.yml + ``` + +Then modify the `.env` according to your configurations. + +!!! warning "Important" + **Do not** use the `.env` in the non-Docker Seafile server as the `.env` in Docker-base Seafile server directly, which misses some key variables in running Docker-base Seafile. Otherwise the Seafile server may **not work properly**. -The recommended steps to migrate from non-docker deployment to docker deployment are: +## Create the directory and recovery data for Seafile Docker -1. ss -2. Close Seafile and native Nginx, Memcached -3. Create the directory needed for Seafile Docker image to run, and copy some files of the locally deployed Seafile to this directory -4. Download the docker-compose.yml file and configure Seafile Docker to use non-Docker version configuration information to connect to the old MySQL database and the old seafile-data directory. -5. Start Seafile Docker +In Docker-base Seafile, the default working directory for Seafile is `/opt/seafile-data` (you can modify them in the `.env` file). Here, you have to create this directory, and recovery from backuped file: -The following document assumes that the deployment path of your non-Docker version of Seafile is /opt/seafile. If you use other paths, before running the command, be careful to modify the command path. +```sh +mkdir -p /opt/seafile-data/seafile -!!! note - You can also refer to the Seafile backup and recovery documentation, deploy Seafile Docker on another machine, and then copy the old configuration information, database, and seafile-data to the new machine to complete the migration. The advantage of this is that even if an error occurs during the migration process, the existing system will not be destroyed. - -## Migrate - -### Stop Seafile, Nginx - -Stop the locally deployed Seafile, Nginx, Memcache - -``` -systemctl stop nginx && systemctl disable nginx -systemctl stop memcached && systemctl disable memcached -./seafile.sh stop && ./seahub.sh stop +# recover seafile data +cp /backup/data/* /opt/seafile-data/seafile ``` -### Prepare MySQL and the folders for Seafile docker +## Recover the Database (only if not use an existed MySQL) -#### Add permissions to the local MySQL Seafile user +You should start the services Firstly, otherwise you cannot connect to MySQL service (`mariadb` now in docker-compose Seafile): -The non-Docker version uses the local MySQL. Now if the Docker version of Seafile connects to this MySQL, you need to increase the corresponding access permissions. +```sh +docker compose up -d +``` -The following commands are based on that you use `seafile` as the user to access: +After startuping the MySQL service, you should create the MySQL user (e.g., `seafile`, defined in your `.env` file) and add related permissions: ``` ## Note, change the password according to the actual password you use @@ -88,105 +113,30 @@ GRANT ALL PRIVILEGES ON *.* TO 'seafile'@'%' IDENTIFIED BY 'your-password' WITH GRANT ALL PRIVILEGES ON `ccnet_db`.* to 'seafile'@'%'; GRANT ALL PRIVILEGES ON `seafile_db`.* to 'seafile'@'%'; GRANT ALL PRIVILEGES ON `seahub_db`.* to 'seafile'@'%'; - -## Restart MySQL -systemctl restart mariadb ``` -#### Create the required directories for Seafile Docker image +Then you can follow [here](../administration/backup_recovery.md#restore-the-databases-1) to restore the database data -By default, we take `/opt/seafile-data` as example. +## Restart the services -``` -mkdir -p /opt/seafile-data/seafile -``` - -#### Prepare config files - -Copy the original config files to the directory to be mapped by the docker version of seafile - -``` -cp -r /opt/seafile/conf /opt/seafile-data/seafile -cp -r /opt/seafile/seahub-data /opt/seafile-data/seafile -``` - -Modify the MySQL configuration in `/opt/seafile-data/seafile/conf`, including `ccnet.conf`, `seafile.conf`, `seahub_settings`, change `HOST=127.0.0.1` to `HOST=`. - -Modify the memcached configuration in `seahub_settings.py` to use the Docker version of Memcached: change it to `'LOCATION': 'memcached:11211'` (the network name of Docker version of Memcached is `memcached`). - -#### Download and modify Seafile-docker yml - -We recommond you download Seafile-docker yml into `/opt/seafile-data` +Finally, the migration is complete. You can restart the Seafile server of Docker-base by restarting the service: ```sh -mkdir -p /opt/seafile-data -cd /opt/seafile-data -# e.g., pro edition -wget -O .env https://manual.seafile.com/12.0/docker/pro/env -wget https://manual.seafile.com/12.0/docker/pro/seafile-server.yml -wget https://manual.seafile.com/12.0/docker/caddy.yml - -nano .env -``` - -After downloading relative configuration files, you should also modify the `.env` by following steps - -- Follow [here](./setup_with_an_existing_mysql_server.md) to setup the database user infomations. - -- Mount the old Seafile data to the new Seafile server - -```sh -SEAFILE_VOLUME= -``` - -### Start Seafile docker - -Start Seafile docker and check if everything is okay: - -``` -cd /opt/seafile-data -docker compose up -d -``` - -## Security -While it is not possible from inside a docker container to connect to the host database via localhost but via `` you also need to bind your databaseserver to that IP. If this IP is public, it is strongly advised to protect your database port with a firewall. Otherwise your databases are reachable via internet. -An alternative might be to start another local IP from [RFC 1597](https://tools.ietf.org/html/rfc1597) e.g. `192.168.123.45`. Afterwards you can bind to that IP. - -### iptables -Following iptables commands protect MariaDB/MySQL: -``` -iptables -A INPUT -s 172.16.0.0/12 -j ACCEPT #Allow Dockernetworks -iptables -A INPUT -p tcp -m tcp --dport 3306 -j DROP #Deny Internet -ip6tables -A INPUT -p tcp -m tcp --dport 3306 -j DROP #Deny Internet -``` -Keep in mind this is not bootsafe! - -### Binding based -For Debian based Linux Distros you can start a local IP by adding in `/etc/network/interfaces` something like: -``` -iface eth0 inet static - address 192.168.123.45/32 -``` -`eth0` might be `ensXY`. Or if you know how to start a dummy interface, thats even better. - -SUSE based is by editing `/etc/sysconfig/network/ifcfg-eth0` (ethXY/ensXY/bondXY) - -If using MariaDB the server just can bind to one IP-address (192.158.1.38 or 0.0.0.0 (internet)). So if you bind your MariaDB server to that new address other applications might need some reconfigurement. - -In `/etc/mysql/mariadb.conf.d/50-server.cnf` edit the following line to: -``` -bind-address = 192.168.123.45 -``` -then edit /opt/seafile-data/seafile/conf/ -> seafile.conf seahub_settings.py in the Host-Line to that IP and execute the following commands: - -``` -service networking reload -ip a #to check whether the ip is present -service mysql restart -ss -tulpen | grep 3306 #to check whether the database listens on the correct IP -cd /opt/seafile-data/ -docker compose down docker compose up -d - -## restart your applications ``` + +!!! success + After staring the services, you can use `docker logs -f seafile` to follow the logs output from *Seafile* to check the status of the server. When the service is running normally, you will get the following message: + + ``` + Starting seafile server, please wait ... + Seafile server started + + Done. + + Starting seahub at port 8000 ... + + Seahub is started + + Done. + ```