本文是滴滴云开源框架教程系列文章的一篇。
Seafile 介绍
Seafile 是一个开源的文件云存储平台,解决文件集中存储、同步、多平台访问的问题,注重安全和性能。
Seafile 通过“资料库”来分类管理文件,每个资料库可单独同步,用户可加密资料库, 且密码不会保存在服务器端,所以即使是服务器管理员也无权访问你的文件。
Seafile 允许用户创建“群组”,在群组内共享和同步文件,方便了团队协同工作。
如何基于滴滴云来搭建Seafile
目前滴滴云提供的服务器和SSD存储盘价格低,产品操作易用,且通过了多项信息安全认证,数据可靠性很高。
准备工作
- 1台滴滴云DC2服务器,1个弹性IP地址
- 操作系统:Linux CentOS7.4
- 规格:2CPU 4GB内存 40GBSSD系统盘
- 带宽:5M
- 1台云数据库Mysql(可选,也可以自建Mysql)
- 1台云盘EBS
- 规格:50GB
- 配置:SSD云盘
- 挂载的云服务器:选择之前准备的服务器主机名
- 在安全组规则中,添加8000和8012端口允许访问策略
当一切准备就绪,我们就可以按照下面的操作步骤开始搭建Seafile了。
安装过程
Step 1:Seafile目录设计和软件下载
首先,在滴滴云服务器上对安装软件的目录和数据存放的空间进行规划,确保所有的软件程序和文件数据,都有序的存放在服务器上,方便后期的维护。另外,下载最新版本的Seafile Server安装包到目录上。
首先,使用用户名dc2-user登陆到你的滴滴云服务器
1 2 |
$ ssh dc2-user@116.85.10.39 |
切换到root用户,并为root用户设定登陆密码
1 2 3 |
$ sudo su # passwd |
使用mkdir
创建一个起名为Seafile的文件夹,用于存放所有Seafile的配置文件和数据文件
1 2 |
# mkdir seafile |
在Seafile文件夹中,使用wget
命令下载最新的seafile server版安装包
1 2 3 |
# cd seafile # wget http://seafile-downloads.oss-cn-shanghai.aliyuncs.com/seafile-server_6.3.3_x86-64.tar.gz |
使用tar
命令将软件包解压
1 2 |
# tar -xzf seafile-server_6.3.3_x86-64.tar.gz |
Step 2:安装Seafile前的软件依赖环境检查
安装Seafile服务器之前,请确认以下软件已经安装在了操作系统中,滴滴云DC2服务器上默认已经配置好了yum源,可以通过yum的相关命令直接查看软件的安装情况或直接进行安装,并为安装好的Mysql设置密码,以便后续创建Seafile数据库使用。
- MariaDB 或者 MySQL 服务器 (或者使用滴滴云提供的Mysql产品)
- python 2.7 (从 Seafile 5.1 开始,python 版本最低要求为2.7)
- python-setuptools
- python-mysqldb
- python-ldap
- python-urllib3
- python-memcache (或者 python-memcached)
使用rpm
命令,查看软件包的安装情况
1 2 3 4 5 |
# rpm -qa mysql python python-setuptools python-mysqldb python-ldap python-urllib3 python-memcache python-setuptools-0.9.8-7.el7.noarch python-2.7.5-58.el7.x86_64 python-urllib3-1.10.2-3.el7.noarch |
接下来,使用yum
命令,安装还未安装的系统软件包
1 2 |
# yum -y install mariadb mariadb-server python-ldap python-memcached MySQL-python |
启动Mariadb数据库,并验证3306端口启用情况
1 2 3 4 |
# service mariadb start # netstat -tulpn | grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 12879/mysqld |
使用命令mysql_secure_installation
,为Mariadb进行初始化配置,并为root设置密码
1 2 |
# mysql_secure_installation #除了密码设置,其余选项可以直接输入y通过 |
Step 3:安装Seafile
这一步,开始安装Seafile软件包,在安装的过程中,脚本会依次询问一些服务器的配置问题,从而引导你完成整个配置过程,如果上面步骤的软件包没有安装完成,Seafile初始化脚本会提醒你进行安装。
运行安装脚本并回答预设问题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# cd seafile-server-6.3.3/ # ./setup-seafile-mysql.sh What is the name of the server? It will be displayed on the client. 3 - 15 letters or digits [ server name ] didiyun #输入服务器名称 What is the ip or domain of the server? For example: www.mycompany.com, 192.168.1.101 [ This server's ip or domain ] 116.85.10.39 #输入滴滴云服务器的EIP公网地址 Where do you want to put your seafile data? Please use a volume with enough free space [ default "/root/seafile/seafile-data" ] #直接回车 Which port do you want to use for the seafile fileserver? [ default "8082" ] #直接回车 ------------------------------------------------------- Please choose a way to initialize seafile databases: ------------------------------------------------------- [1] Create new ccnet/seafile/seahub databases [2] Use existing ccnet/seafile/seahub databases #如果选择1,你需要提供根密码.脚本程序会创建数据库和用户。 #如果选择2,使用已经存在的ccnet/seafile/seahub数据库文件。 |
我们选择1,创建新的数据库和用户
1 2 3 4 5 6 7 8 9 10 11 |
[ 1 or 2 ] 1 What is the host of mysql server? [ default "localhost" ] #直接回车 What is the port of mysql server? [ default "3306" ] #直接回车 What is the password of the mysql root user? [ root password ] #输入之前设定的root密码 |
密码验证完成后,进入到对于Seafile用户的信息配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Enter the name for mysql user of seafile. It would be created if not exists. [ default "seafile" ] #直接回车 Enter the password for mysql user "seafile": [ password for seafile ] #设定seafile用户密码 Enter the database name for ccnet-server: [ default "ccnet-db" ] #直接回车 Enter the database name for seafile-server: [ default "seafile-db" ] #直接回车 Enter the database name for seahub: [ default "seahub-db" ] #直接回车 |
Seafile用户信息配置完成后,如果你正常的安装了Seafile,你将得到如下的输出
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
----------------------------------------------------------------- Your seafile server configuration has been finished successfully. ----------------------------------------------------------------- run seafile server: ./seafile.sh { start | stop | restart } run seahub server: ./seahub.sh { start <port> | stop | restart <port> } ----------------------------------------------------------------- If you are behind a firewall, remember to allow input/output of these tcp ports: ----------------------------------------------------------------- port of seafile fileserver: 8082 port of seahub: 8000 When problems occur, Refer to https://github.com/haiwen/seafile/wiki for information. |
Step 4:启动Seafile服务器
在 seafile-server-latest 目录下,运行如下命令启动Seafile服务器
- 启动Seafile
1 2 |
# ./seafile.sh start |
- 启动Seahub
1 2 |
# ./seahub.sh start |
- 在第一次启动Seahub时,
seahub.sh
脚本会提示您创建一个Seafile管理员账号
1 2 3 4 5 6 7 8 9 |
What is the email for the admin account? [ admin email ] admin@didiyun.com What is the password for the admin account? [ admin password ] Enter the password again: [ admin password again ] |
服务启动后,打开浏览器并输入以下地址,你就会被重定向到登陆页面,输入管理员用户名和密码,即可登录。
1 2 |
http://116.85.10.39:8000/ #IP地址为您个人的服务器IP |
恭喜 您的Seafile已经安装成功!您可以登录到Seafile中任意上传或者下载您所需要的文件,一个私密的个人网盘,就搭建完成了。
更优化、更安全的文件存储方式
在Seafile安装完成后,通常情况下,我们会建议把系统盘和数据盘做分离,由于Seafile的功能主要是用于存储文件,所以可以将存放文件的seafile-data目录,单独挂载一块大容量的SSD云盘,方便对数据目录做统一的备份和管理。
在滴滴云购买的EBS云盘,在控制台可以直接挂载到DC2服务器上,完成挂载的操作,就可以直接通过lsblk
的命令显示出来
1 2 3 4 5 6 |
# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 253:0 0 40G 0 disk └─vda1 253:1 0 40G 0 part / vdb 253:16 0 50G 0 disk |
- 首先我们使用
fdisk
命令,对数据盘vdb进行磁盘分区
1 2 |
# fdisk /dev/vdb |
分区过程不做赘述,具体可以访问滴滴云官网的连接查看
https://help.didiyun.com/hc/kb/article/1121818/
- 使用
mkfs.xfs
命令,将已经分区的磁盘进行格式化
1 2 |
# mkfs.xfs /dev/vdb1 |
- 将磁盘挂载到seafile-data目录之前,先将seafile-data目录中已经存在的文件转移到另外的文件夹中,做临时中转
1 2 3 |
# mkdir /root/backup # mv /root/seafile/seafile-data/* /root/backup/ |
- 使用
mount
命令,将已经格式化好的数据盘挂载到/root/seafile/seafile-data/下,注意需要加入读写权限
1 2 3 4 5 6 7 8 9 10 11 |
# mount -rw /dev/vdb1 /root/seafile/seafile-data/ # df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 40G 2.1G 38G 6% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 17M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup tmpfs 380M 0 380M 0% /run/user/1001 /dev/vdb1 50G 33M 50G 1% /root/seafile/seafile-data |
- 挂载完成后,将seafile-data之前移出的文件转回seafile-data文件夹
1 2 |
# mv /root/backup/* /root/seafile/seafile-data/ |
到此,您已经具备了一个私密性和可靠性极高的Seafile网盘空间
本文作者:宋佩
用户评论(1)
搭建中的任何问题,可以邮箱联系 songpei@didiglobal.com