Seafile 从 Windows Server 迁移到 Linux 并且转换为 MySQL
目前我已经使用 Windows Server 2012 RC2 安装了 Seafile Server 5.1.3 Windows 版本.
- ip:192.168.2.201
新建了以下三个用户:
新建以下群组:
-
abc
-
中文测试
三个账户均加入群组,其中 abc 群组讨论中留有***中文测试***字样.
Linux 系统使用 Centos7-amd64 最小化安装.
- ip:192.168.2.200
1. 在 Linux 安装基于 SQLite 的 Seafile Server
1.1 下载和 Windows 服务端同一版本的 Linux 版本 Seafile Server
因为 Seafile 的 Windows 版本远比 Linux 滞后,且不同版本间的数据库不能想通,故此不能下载最新版的 Linux 版本,需要下载与 Windows Seafile 版本想同的 Linux 版本.
方法很简单:
目前我这里最新版的 Linux 版本是 6.0.5 下载地址如下
http://download-cn.seafile.com/seafile-server_6.0.5_x86-64.tar.gz
那么我要下载 5.1.3 版本只需要将版本号更改一下即可.
http://download-cn.seafile.com/seafile-server_5.1.3_x86-64.tar.gz
cd /home
mkdir haiwen
yum install wget -y && wget http://download-cn.seafile.com/seafile-server_5.1.3_x86-64.tar.gz
tar xzf seafile-server_5.1.3_x86-64.tar.gz
mkdir installed
mv seafile-server_*.gz installed
现在,你的目录看起来应该像这样:
tree . -L 2
.
├── installed
│ └── seafile-server_5.1.3_x86-64.tar.gz
└── seafile-server-5.1.3
├── check_init_admin.py
├── reset-admin.sh
├── runtime
├── seaf-fsck.sh
├── seaf-fuse.sh
├── seaf-gc.sh
├── seafile
├── seafile.sh
├── seahub
├── seahub.sh
├── setup-seafile-mysql.py
├── setup-seafile-mysql.sh
├── setup-seafile.sh
└── upgrade
6 directories, 11 files
1.2 安装 Seafile 依赖的工具
- python 2.7
- python-setuptools
- python-imaging
- python-ldap
- python-urllib3
- sqlite3
yum install python-setuptools python-imaging python-ldap MySQL-python python-memcached python-urllib3
1.3 安装 Seafile Server
cd seafile-server-5.1.3
./setup-seafile.sh
-----------------------------------------------------------------
This script will guide you to config and setup your seafile server.
Make sure you have read seafile server manual at
https://github.com/haiwen/seafile/wiki
Note: This script will guide your to setup seafile server using sqlite3,
which may have problems if your disk is on a NFS/CIFS/USB.
In these cases, we sugguest you setup seafile server using MySQL.
Press [ENTER] to continue
-----------------------------------------------------------------
Checking packages needed by seafile ...
Checking python on this machine ...
Find python: python2.7
Checking python module: setuptools ... Done.
Checking python module: python-imaging ... Done.
Checking python module: python-sqlite3 ... Done.
Checking for sqlite3 ...Done.
Checking Done.
What would you like to use as the name of this seafile server?
Your seafile users will be able to see the name in their seafile client.
You can use a-z, A-Z, 0-9, _ and -, and the length should be 3 ~ 15
[server name]: Seafile
What is the ip or domain of this server?
For example, www.mycompany.com, or, 192.168.1.101
[This server's ip or domain]: 192.168.2.201^H^C
You have pressed Ctrl-C. Setup is interrupted.
[root@localhost seafile-server-5.1.3]# ./setup-seafile.sh
-----------------------------------------------------------------
This script will guide you to config and setup your seafile server.
Make sure you have read seafile server manual at
https://github.com/haiwen/seafile/wiki
Note: This script will guide your to setup seafile server using sqlite3,
which may have problems if your disk is on a NFS/CIFS/USB.
In these cases, we sugguest you setup seafile server using MySQL.
Press [ENTER] to continue
-----------------------------------------------------------------
Checking packages needed by seafile ...
Checking python on this machine ...
Find python: python2.7
Checking python module: setuptools ... Done.
Checking python module: python-imaging ... Done.
Checking python module: python-sqlite3 ... Done.
Checking for sqlite3 ...Done.
Checking Done.
What would you like to use as the name of this seafile server?
Your seafile users will be able to see the name in their seafile client.
You can use a-z, A-Z, 0-9, _ and -, and the length should be 3 ~ 15
[server name]: seafile
What is the ip or domain of this server?
For example, www.mycompany.com, or, 192.168.1.101
[This server's ip or domain]: 192.168.2.200
Where would you like to store your seafile data?
Note: Please use a volume with enough free space.
[default: /home/haiwen/seafile-data ]
What tcp port do you want to use for seafile fileserver?
8082 is the recommended port.
[default: 8082 ]
This is your config information:
server name: seafile
server ip/domain: 192.168.2.200
seafile data dir: /home/haiwen/seafile-data
fileserver port: 8082
If you are OK with the configuration, press [ENTER] to continue.
Generating ccnet configuration in /home/haiwen/ccnet...
done
Successly create configuration dir /home/haiwen/ccnet.
Generating seafile configuration in /home/haiwen/seafile-data ...
Done.
-----------------------------------------------------------------
Seahub is the web interface for seafile server.
Now let's setup seahub configuration. Press [ENTER] to continue
-----------------------------------------------------------------
Creating seahub database now, it may take one minute, please wait...
Done.
creating seafile-server-latest symbolic link ... done
-----------------------------------------------------------------
Your seafile server configuration has been completed successfully.
-----------------------------------------------------------------
run seafile server: ./seafile.sh { start | stop | restart }
run seahub server: ./seahub.sh { start <port> | stop | restart <port> }
-----------------------------------------------------------------
If the server is behind a firewall, remember to open these tcp ports:
-----------------------------------------------------------------
port of seafile fileserver: 8082
port of seahub: 8000
When problems occur, refer to
https://github.com/haiwen/seafile/wiki
for more information.
如果安装正确完成,会打印以上成功消息
现在你的目录结构将会是如下:
tree . -L 2
.
├── ccnet
│ ├── mykey.peer
│ └── seafile.ini
├── conf
│ ├── ccnet.conf
│ ├── seafdav.conf
│ ├── seafile.conf
│ └── seahub_settings.py
├── installed
│ └── seafile-server_5.1.3_x86-64.tar.gz
├── seafile-data
│ └── library-template
├── seafile-server-5.1.3
│ ├── check_init_admin.py
│ ├── reset-admin.sh
│ ├── runtime
│ ├── seaf-fsck.sh
│ ├── seaf-fuse.sh
│ ├── seaf-gc.sh
│ ├── seafile
│ ├── seafile.sh
│ ├── seahub
│ ├── seahub.sh
│ ├── setup-seafile-mysql.py
│ ├── setup-seafile-mysql.sh
│ ├── setup-seafile.sh
│ └── upgrade
├── seafile-server-latest -> seafile-server-5.1.3
├── seahub-data
│ └── avatars
└── seahub.db
1.4 运行服务
在 seafile-server-latest 目录下运行启动脚本
- 启动 Seafile
cd seafile-server-latest
./seafile.sh start
[11/16/16 17:21:19] ../common/session.c(132): using config file /home/haiwen/conf/ccnet.conf
Starting seafile server, please wait ...
Seafile server started
Done.
- 启动 Seahub,启动时默认会让你设置管理员账号(邮箱格式)和密码.
./seahub.sh start
LC_ALL is not set in ENV, set to en_US.UTF-8
Starting seahub at port 8000 ...
----------------------------------------
It's the first time you start the seafile server. Now let's create the admin account
----------------------------------------
What is the email for the admin account?
[ admin email ] test@test
Aborted.
[root@localhost seafile-server-latest]# ./seahub.sh start
LC_ALL is not set in ENV, set to en_US.UTF-8
Starting seahub at port 8000 ...
----------------------------------------
It's the first time you start the seafile server. Now let's create the admin account
----------------------------------------
What is the email for the admin account?
[ admin email ] neroxps@gmail.com
What is the password for the admin account?
[ admin password ]
Enter the password again:
[ admin password again ]
----------------------------------------
Successfully created seafile admin
----------------------------------------
Seahub is started
Done.
1.5 测试安装结果
配置 firewall 放开 8000 端口和 8082 端口
firewall-cmd --add-service=http --permanent #永久开启默认区域中 http 服务
firewall-cmd --zone=public --add-port=8000/tcp --permanent
firewall-cmd --zone=public --add-port=8082/tcp --permanent
用 Web 浏览器访问 http://192.168.2.200:8000 使用我们启动 seahub.sh 时候创建的管理员账号登陆,成功登陆并可以使用.
2. 迁移
2.1 删除 Linux 的配置文件和数据
rm /home/haiwen/conf/seahub_settings.py*
rm /home/haiwen/seahub.db
rm -r /home/haiwen/seafile-data
cp /home/haiwen/ccnet/seafile.ini /home/haiwen/seafile.ini
rm -r /home/haiwen/ccnet
删除完后目录解构应该是这样的
tree . -L 2
.
├── conf
│ ├── ccnet.conf
│ ├── seafdav.conf
│ └── seafile.conf
├── installed
│ └── seafile-server_5.1.3_x86-64.tar.gz
├── logs
│ ├── ccnet.log
│ ├── controller.log
│ ├── seafile.log
│ ├── seahub_django_request.log
│ └── seahub.log
├── pids
│ ├── ccnet.pid
│ └── seaf-server.pid
├── seafile.ini
├── seafile-server-5.1.3
│ ├── check_init_admin.py
│ ├── reset-admin.sh
│ ├── runtime
│ ├── seaf-fsck.sh
│ ├── seaf-fuse.sh
│ ├── seaf-gc.sh
│ ├── seafile
│ ├── seafile.sh
│ ├── seahub
│ ├── seahub.sh
│ ├── setup-seafile-mysql.py
│ ├── setup-seafile-mysql.sh
│ ├── setup-seafile.sh
│ └── upgrade
└── seafile-server-latest -> seafile-server-5.1.3
10 directories, 22 files
2.2 拷贝配置文件和数据
停止 Linux Seafile 服务
./seafile.sh stop
./seahub.sh stop
找到 Windows Server 下的 seafile-server 文件夹,将以下几个文件传到 Linux 系统内.
- X:\seafile-server\conf\ccnet -> /home/haiwen/
- X:\seafile-server\conf\seahub_settings.py -> /home/haiwen/conf/seahub_settings.py
- X:\seafile-server\seafile-data -> /home/haiwen/
- X:\seafile-server\seahub.db -> /home/haiwen
- /home/haiwen/seafile.ini -> /home/haiwen/conf/ccnet
我在 Windows 下是使用 zip 压缩后用 rz 命令上传到 Linux 服务器上的,大家可以使用其他办法上传文件到 Linux 服务器中.
3. SQLite 测试
启动 Linux Seafile
./seafile.sh start
./seahub.sh start
无报错
登陆 http://192.168.2.200:8000
页面显示成功,但是头像图片丢失.
经过排查,发现 Windows 版本的 Seafile 头像是存放在 C:\SeafileProgram\seafile-server-5.1.3\seahub\media\avatars,而 Linux 版本头像也在类似目录,但是这个目录仅仅是一个软连接,avatars -> …/…/…/seahub-data/avatars,实际路径是 /home/haiwen/seahub-data/avatars.找到问题就好办了,我们将 C:\SeafileProgram\seafile-server-5.1.3\seahub\media\avatars 的内容迁移到 Linux 的 /home/haiwen/seahub-data/avatars 问题就解决了.
迁移后无需重启,直接刷新页面,头像正常显示.
好,使用 SQLite 的 Seafile 已经正常使用了,接下来转换数据库,使用 MySQL.
4. 将 SQLite 数据库转换为 MySQL 数据库
4.1 准备工作
- MariaDB 服务器 (MariaDB 是 MySQL 的分支)
- python 2.7 (从 Seafile 5.1 开始,python 版本最低要求为2.7)
- python-setuptools
- python-imaging
- python-mysqldb
- python-ldap
- python-urllib3
- python-memcache (或者 python-memcached)
yum install mariadb-server mariadb
yum install python-setuptools python-imaging python-ldap MySQL-python python-memcached python-urllib3
其实除了数据库,其他基本在部署 SQLite 的时候已经安装了.
为避免遗漏,建议还是跑一下.
安装好后,别忘了修改 MySQL 的 root 密码.
systemctl start mariadb #启动mariadb
mysqladmin -u root password "newpass" #设置root密码为newpass
下载 sqlite2mysql.sh 和 sqlite2mysql.py 到 Seafile 的安装根目录 /home/haiwen/.
4.2 转换数据库
停止 Seafile 和 Seahub
./seafile.sh stop
./seahub.sh stop
运行 sqlite2mysql.sh 脚本
chmod +x sqlite2mysql.sh
./sqlite2mysql.sh
/home/haiwen/ccnet/ccnet.conf does not exists.
Please provide your ccnet.conf path(e.g. /data/haiwen/ccnet/ccnet.conf): /home/haiwen/conf/ccnet.conf
sqlite3 /home/haiwen/conf/PeerMgr/usermgr.db .dump | python sqlite2mysql.py > ccnet-db.sql
Error: unable to open database "/home/haiwen/conf/PeerMgr/usermgr.db": unable to open database file
sqlite3 /home/haiwen/conf/GroupMgr/groupmgr.db .dump | python sqlite2mysql.py >> ccnet-db.sql
Error: unable to open database "/home/haiwen/conf/GroupMgr/groupmgr.db": unable to open database file
sqlite3 /home/haiwen/seafile-data/seafile.db .dump | python sqlite2mysql.py > seafile-db.sql
sqlite3 /home/haiwen/seahub.db .dump | tr -d '\n' | sed 's/;/;\n/g' | python sqlite2mysql.py > seahub-db.sql
这个脚本将生成三个文件:ccnet-db.sql, seafile-db.sql, seahub-db.sql.
但是报错了,打开 sqlite2mysql.sh
发现他将 usermgr.db
和 groupmgr.db
都定位到我们填写的 /home/haiwen/conf/ccnet.conf
这个目录下了,那么肯定是错的,从 5.0 开始 ccnet.conf就改到了 conf目录下,所以这里导出的 ccnet-db.sql
是没有数据的.修改办法很简单.
vim sqlite2mysql.sh
#将 22 行的 ${seafile_path}/ccnet/ccnet.conf
修改为 ${seafile_path}/conf/ccnet.conf
修改后在执行以下脚本
./sqlite2mysql.sh
sqlite3 /home/haiwen/ccnet/PeerMgr/usermgr.db .dump | python sqlite2mysql.py > ccnet-db.sql
sqlite3 /home/haiwen/ccnet/GroupMgr/groupmgr.db .dump | python sqlite2mysql.py >> ccnet-db.sql
sqlite3 /home/haiwen/seafile-data/seafile.db .dump | python sqlite2mysql.py > seafile-db.sql
sqlite3 /home/haiwen/seahub.db .dump | tr -d '\n' | sed 's/;/;\n/g' | python sqlite2mysql.py > seahub-db.sql
无报错,vim 打开 ccnet-db.sql
查看,是有数据的,证明已经导出成功.
4.3 导入数据
进入 MySQL 新建3个数据库,分别命名为 ccnet-db, seafile-db, seahub-db.
mysql -u root -pnewpass
create database `ccnet-db` character set = 'utf8';
create database `seafile-db` character set = 'utf8';
create database `seahub-db` character set = 'utf8';
如果以上语句执行无误的话,那么你的数据库应该是这样的:
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| ccnet-db |
| mysql |
| performance_schema |
| seafile-db |
| seahub-db |
| test |
+--------------------+
7 rows in set (0.00 sec)
修改 /etc/my.conf, 添加下列语句,并重启 mysql (systemctl restart mariadb),这个语句主要是确保数据库使用 UTF8 编码.
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
下面是修改好的 my.conf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
重启 MySQL systemctl restart mariadb
将之前转换的 sql 导入到数据库
mysql -uroot -pnewpass ccnet-db < ccnet-db.sql
mysql -uroot -pnewpass seafile-db < seafile-db.sql
mysql -uroot -pnewpass seahub-db < seahub-db.sql
4.4 修改 Seafile 配置
在 conf/ccnet.conf
中增加以下语句:
[Database]
ENGINE=mysql
HOST=127.0.0.1
USER=root
PASSWD=newpass
DB=ccnet-db
CONNECTION_CHARSET=utf8
注意: 使用 127.0.0.1
, 不要使用 localhost
.
将 conf/seafile.conf
中的数据库配置信息更改文以下语句:
[database]
type=mysql
host=127.0.0.1
user=root
password=newpass
db_name=seafile-db
CONNECTION_CHARSET=utf8
在 conf/seahub_settings.py
中增加以下语句:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'USER' : 'root',
'PASSWORD' : 'newpass',
'NAME' : 'seahub-db',
'HOST' : '127.0.0.1',
'OPTIONS': {
"init_command": "SET storage_engine=INNODB",
}
}
}
并删除conf/seahub_settings.pyc
rm -rf conf/seahub_settings.pyc
5. 重启 Seafile and Seahub 测试
启动 Linux Seafile
./seafile.sh start
./seahub.sh start
启动成功无报错.
页面中文正常…