旧电脑通过dockers部署seafile笔记

本文详细描述了如何在配置较低的旧电脑和虚拟机上部署Seafile服务,包括安装CentOS、配置网络、安装Docker、设置SeafileDocker-compose.yml、同步数据并进行定期备份。文中还列举了可能出现的问题及其解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2023年11月

软硬件配置:

软件版本:ventoy-1.0.96-windows,CentOS-7-x86_64-Minimal-2009,

Seafile服务使用的旧电脑配置:2核DE5100I/i65HMx4G内存,存放seafile数据备份的电脑配置:VirtualBox虚拟机2G内存,U盘:32G一个。

两台电脑配置部署

类别

运行Seafile系统的电脑

备份数据的电脑

硬件

旧电脑:2核DE5100I/i65HMx4G内存

虚拟机:VirtualBox虚拟机2G内存

操作系统

CentOS-7-x86_64-Minimal-2009

CentOS-7-x86_64-Minimal-2009

安装软件

安装docker、安装seafile系统、安装rsync

安装rsync并开启deamon模式

IP地址

192.168.126.159

192.168.126.106

rsync同步方式

push 方式将数据推送(上传)备份电脑中

需要设置SELinux和设置防火墙

rsync密码文件格式

密码

用户名:密码

安装centos系统准备:

下载U盘启动工具:ventoy-1.0.96-windows 下载网站: Download . Ventoy

安装到U盘

下载CentOS-7-x86_64-Minimal-2009 x86_64架构下载网站:Download

拷贝到U盘

在备份用电脑下载VirtualBox 7.0.12 windows版 :下载网站:Downloads – Oracle VM VirtualBox

旧电脑开始安装seafile系统:

centos系统安装

将CentOS的ISO镜像文件拷到制作好引导系统的U盘中,通过U盘将CentOS安装到旧的电脑上。设置好语言、安装路径、管理员密码等待安装完毕。

设置网络(192.168.126.159)

root账号登陆,

查看网卡接口名称命令: ip address

配置接口ip地址:编辑文件vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 注:enp0s3是网卡接口名称

编辑这几项没有的添加,

  BOOTPROTO=static

  IPADDR=192.168.126.159

  NETMASK=掩码

  GATEWAY=网关

  DNS1=dns地址

  onboot=yes

存盘退出:

  esc键  :wq!

重启网络服务:  

  systemctl restart network

检验网络是否畅通:

 ping 192.168.126.159

为了方便操作使用winscp+putty连接CentOS系统。

安装docker

root账号登陆

配置阿里云yum源:

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

安装Docker以及系统的基础依赖

yum install -y yum-utils device-mapper-persistent-data lvm2

设置docker的 yum源

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

使用yum源提供的docker安装包进行安装

sudo yum install -y  docker-ce

检验是否成功安装

docker run hello-world

创建docker配置文件目录

mkdir -p /etc/docker

启动Docker并设置开机自启

systemctl enable docker –now

检查docker是否自启

systemctl list-unit-files | grep docker

通过docker 安装seafile

官方指导文档:

中文用 Docker 部署 Seafile 服务 - seafile-manual-cn

英文:Seafile Community Installation - Seafile Admin Manual 英文文档内容更全一些

从官方文档页面下载 docker-compose.yml到/etc/docker/seafile/目录中

cd /etc/docker

mkdir seafile

curl -L -k "https://docs.seafile.com/d/cb1d3f97106847abbf31/files/?p=%2Fdocker%2Fdocker-compose.yml&dl=1" -o /etc/docker/seafile/docker-compose.yml

或者windows系统下使用winscp软件将 docker-compose.yml 文件复制到/etc/docker/seafile/文件夹中       

编辑配置文件 vi /etc/docker/seafile/docker-compose.yml

services:

  db:

    image: mariadb:10.11

    restart: always  #开机自启db服务

    container_name: seafile-mysql

    environment:

      - MYSQL_ROOT_PASSWORD=数据库密码  # Requested, set the root's password of MySQL service.

      - MYSQL_LOG_CONSOLE=true

    volumes:

      - /opt/seafile-mysql/db:/var/lib/mysql  # Requested, specifies the path to MySQL data persistent store.

    networks:

      - seafile-net

  memcached:

    image: memcached:1.6

    restart: always   #开机自启memcached服务

    container_name: seafile-memcached

    entrypoint: memcached -m 256

    networks:

      - seafile-net

         

  seafile:

    image: seafileltd/seafile-mc:latest

    restart: always  #开机自启seafile服务

    container_name: seafile

    ports:

      - "80:80"

#      - "443:443"  # If https is enabled, cancel the comment.

    volumes:

      - /opt/seafile-data:/shared   # Requested, specifies the path to Seafile data persistent store.

    environment:

      - DB_HOST=db

      - DB_ROOT_PASSWD=数据库密码和上面相同  # Requested, the value shuold be root's password of MySQL service.

      - TIME_ZONE=Asia/Shanghai # Optional, default is UTC. Should be uncomment and set to your local time zone.

      - SEAFILE_ADMIN_EMAIL=管理员账号 # Specifies Seafile admin user, default is 'me@example.com'.

      - SEAFILE_ADMIN_PASSWORD=管理员密码    # Specifies Seafile admin password, default is 'asecret'.

      - SEAFILE_SERVER_LETSENCRYPT=false   # Whether use letsencrypt to generate cert.

      - SEAFILE_SERVER_HOSTNAME=seafile主机名 # Specifies your host name.

    depends_on:

      - db

      - memcached

    networks:

      - seafile-net

networks:

  seafile-net:

启动 Seafile 服务

           cd /etc/docker/seafile

           docker compose up -d  #注意:在 docker-compose.yml 文件所在的目下执行该条命令。

检查是否安装成功:

浏览器上访问http://seafile主机名 来打开 Seafile 主页。

docker常用几个命令:

列出项目中目前的所有容器

 docker compose ps

    共有三个容器seafile ,seafile-memcached,seafile-mysql

与容器seafile-mysql进行交互

docker exec -it seafile-mysql /bin/bash 退出交互模式命令是exit

docker 的启动/停止/重启

    docker compose start/stop/restart

查看日志

    docker compose logs

docker相关命令:

        docker stop $(docker ps -a -q):停止所有容器

        docker rm $(docker ps -a -q):删除所有容器

        docker rmi $(docker images -q):删除所有镜像

        docker network rm $(docker network ls -q):删除所有网络

备份数据前准备

安装rsync软件,为后面的备份做准备

     yum install rsync -y

 创建rsync自动同步时使用虚拟账号的密码文件

    echo "a12345" >/etc/rsync.password

   

设置密码文件的权限

chmod 500 /etc/rsync.password

创建脚本备份数据

等配置好存放备份数据的电脑后再开始操作以下命令

备份seafile数据的步骤

1.备份 MySQL 数据库数据

   首先导出数据库到/opt/seafile-backup/databases目录中

2.同步MySQL 数据库数据(/opt/seafile-backup/databases/)到备份电脑/opt/seafile-backup/databases/目录中。

3.同步 Seafile 数据(/opt/seafile-data/seafile/)到备份电脑/opt/seafile-backup/data/目录中。

创建mysql数据库备份目录

 mkdir –p /opt/seafile-backup/databases

创建/usr/seafile/seafilebackup.sh

vi  /usr/seafile/seafilebackup.sh  #不能在windows系统里编辑,否则无法正确运行

        #!/bin/bash

        #设置mysql数据库文件备份目录

        backupdir=/opt/seafile-backup/databases

        #备份mysql数据库

        #time=$(date +%Y%m%d%H)

        docker exec  seafile-mysql mysqldump  -uroot -prootr00t --opt ccnet_db  > $backupdir/ccnet-db-$(date +%Y%m%d%H).sql

        docker exec  seafile-mysql mysqldump  -uroot -prootr00t --opt seafile_db  > $backupdir/seafile-db-$(date +%Y%m%d%H).sql

        docker exec  seafile-mysql mysqldump  -uroot -prootr00t --opt seahub_db  > $backupdir/seahub-db-$(date +%Y%m%d%H).sql

        #删除5天前备份的数据库

        find $backupdir/ -name "*.sql" -type f -mtime +5 -exec rm {} \; > /dev/null 2>&1

        

        #同步mysql数据库文件到备份电脑(192.168.126.106)

        rsync –avz --delete $backupdir/  rsync_backup@192.168.126.106::seafile_databases/  --password-file=/etc/rsync.password --log-file=/etc/docker/rsync_log/rsync_data_$(date +%Y%m%d%H%M%S).log

        #备份seafile文件

        rsync -avz /opt/seafile-data/seafile/  rsync_backup@192.168.126.106::seafile_data/  --password-file=/etc/rsync.password --log-file=/etc/docker/rsync_log/rsync_data_$(date +%Y%m%d%H%M%S).log

运行/usr/seafile/seafilebackup.sh进行备份

        bash /usr/seafile/seafilebackup.sh

每天进行数据备份

将/usr/seafile/seafilebackup.sh加入cron定时任务,创建定时任务

crontab -e

        0 4 * * * /usr/seafile/seafilebackup.sh

列出crontab文件

crontab –l

查看cron日志

cat /var/log/cron

存储备份数据的电脑安装操作步骤:

安装虚拟机软件VirtualBox

网络配置(同上IP地址:192.168.126.106)

安装rsync软件 root用户登陆

  yum install rsync -y

防火墙允许rsyncd

  firewall-cmd --add-service=rsyncd –permanent

  firewall-cmd --reload

rsync开机自启

设置开机自启是因为要使用rsync的daemon模式,每天自动进行同步数据。

systemctl enable rsyncd

允许SELinux对rsync放行

getsebool -a | grep rsync      getsebool命令查看rsync对应设置

postgresql_can_rsync --> on

rsync_anon_write --> on

rsync_client --> on

rsync_export_all_ro --> on

rsync_full_access --> off

 如果写数据需要上面rsync开头的四项完全放行,设置成on

    设置选项为on的命令:

setsebool -P rsync_anon_write 1

setsebool -P rsync_client 1

setsebool -P rsync_export_all_ro 1

setsebool -P rsync_full_access 1

再次查看:

getsebool -a | grep rsync     

postgresql_can_rsync --> on

rsync_anon_write --> on

rsync_client --> on

rsync_export_all_ro --> on

rsync_full_access --> on

 编辑/etc/rsyncd.conf文件

# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

uid = root   #备份数据文件的归属用户名

gid = root   #备份数据文件的归属组

use chroot = no

fake super = yes

max connections = 40

pid file = /var/run/rsyncd.pid

exclude = lost+found/

transfer logging = yes

timeout = 900

ignore nonreadable = yes

dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

auth users = rsync_backup    #同步时认证用的虚拟用户名

secrets file = /etc/rsync.passwd    #同步时认证用的虚拟用户名和密码文件

log file = /var/log/rsyncd.log #这行很重要,rsync同步过程中可能有错误,查看日志会快速找到问题。

read only = false #如果数据推送过来需要写权限,要将只读设置为false

max connections = 4

ignore errors

list = false

[data]  

  path = /opt/seafile-data/seafile    #seafile数据备份路径

  comment = seafilebackup

[databases] 

  path = /opt/seafile-backup/databases   #mysql数据库备份路径

  comment = seafiledatabases

   编辑自动同步时认证用户名密码文件

      vi /etc/rsync.password

     rsync_backup:a12345

设置rsync.password密码文件权限

   chmod 500 /etc/rsync.password

开启rsyncd服务进程

              systemctl start rsyncd

       查看rsyncd服务进程

              systemctl status rsyncd

       创建mysql数据备份目录和seafile文件备份目录

              mkdir –p  /opt/seafile-backup/databases/

              mkdir –p  /opt/seafile-backup/data/

操作过程中出现的错误及解决办法:

1. 虚拟机启动报错。

解决办法:启动时错误,需要开启电脑CPU的BIOS虚化。

2. 执行bash /usr/seafile/seafilebackup.sh命令时报错:

(1)mysqldump: Got error: 1049: "Unknown database 'ccnet-db'" when selecting the database

“docker exec  seafile-mysql mysqldump  -uroot -prootr00t --opt ccnet-db> $backupdir/ccnet-db-$(date +%Y%m%d%H).sql”这行出错

解决办法:代码中的数据库名称写错了ccnet-db改为ccnet_db。

(2)@ERROR: auth failed on module databases

rsync error: error starting client-server protocol (code 5) at main.c(1656) [sender=3.1.2]

解决办法:认证问题检查密码文件,密码文件权限。deamon端电脑密码文件内容

格式:用户名:密码 。对端电脑(rsync推送)密码文件内容格式:密码 。

(3)rsync: failed to connect to 192.168.126.106 (192.168.126.106): No route to host (113)

rsync error: error in socket IO (code 10) at clientserver.c(126) [sender=3.1.2]

解决办法:ping命令检查物理链路畅通,检查防火墙。

(4) @ERROR: Unknown module 'databases'

rsync error: error starting client-server protocol (code 5) at main.c(1656) [sender=3.1.2]

rsyncd.conf

解决办法:检查配置文件/etc/rsyncd.conf,模块名称是否正常。

(5) @ERROR: chdir failed

rsync error: error starting client-server protocol (code 5) at main.c(1656) [sender=3.1.2]

解决办法:检查配置文件/etc/rsyncd.conf,模块对应的路径是否存在。

(6)sending incremental file list

rsync: read error: Connection reset by peer (104)

rsync error: error in socket IO (code 10) at io.c(792) [sender=3.1.2]

    解决办法:检查配置文件/etc/rsyncd.conf,需要rsync有写的权限时在/etc/rsyncd.conf文件中添加read only = false。

(7) rsync: failed to connect to 192.168.126.106 (192.168.126.106): Connection refused (111)

rsync error: error in socket IO (code 10) at clientserver.c(126) [sender=3.1.2]

解决办法:检查远程rsyncd 是否开启。

(8)rsync: failed to set times on "." (in seafile_databases): Permission denied (13)

    解决办法:检查SELinux ,放开相应权限

3. 查看rsync的deamon端电脑日志文件/var/log/rsyncd.log

(1)connect from UNKNOWN (192.168.126.159)

2023/11/23 11:36:59 [79533] secrets file must not be other-accessible

密码文件权限为设置

解决办法:chmod 700 /etc/rsync.passwd

(2)rsync to seafile_databases/ from rsync_backup@UNKNOW

2023/11/23 14:20:24 [95486] ERROR: module is read only

解决办法:在/etc/rsyncd.conf 配置文件中添加这行read only =false

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值