在目前眾多網(wǎng)盤小場紛紛宣布自己倒下或者即將倒下的時代,大家除了使用幾個大廠的服務外,也可另辟蹊徑搭建一套屬于自己的網(wǎng)盤服務。
針對個人需要的數(shù)據(jù)云備份、云存儲、數(shù)據(jù)分享、在線視頻、音樂等本文中部署的個人網(wǎng)盤皆可滿足。話不多說,下面我們就進入個人網(wǎng)盤搭建的正文。本文中底層的云存儲工具我們以owncloud為例。
根據(jù)維基百科介紹,ownCloud 是一個自由且開源的個人云存儲解決方案,包括服務器和客戶端兩部分。
ownCloud 最早由KDE開發(fā)者Frank Karlitschek于2010年一月創(chuàng)建,目標是成為商業(yè)云存儲服務商的替代。與商業(yè)云存儲不同,ownCloud可以自由獲取無需付費,但相應的,用戶必須自行架設ownCloud服務器。
ownCloud在客戶端可透過網(wǎng)頁界面,或者安裝專用的客戶端軟件來使用。網(wǎng)頁界面當然就是任何能開網(wǎng)頁的平臺都支持,而客戶端軟件也支持相當多平臺,Windows、Linux、iOS、Android皆有。
以下為部署的具體過程。
首先我們需要一臺服務器,在此我們以本地自己搭建的一臺虛擬機為例,發(fā)行版和內(nèi)核信息如下:
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@localhost ~]# uname -a
Linux work 3.10.0-327.36.1.el7.x86_64 #1 SMP Sun Sep 18 13:04:29 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]#
部署環(huán)境準備完成后,我們在虛擬機上安裝下紅帽的yum源:
[root@localhost ~]# yum install -y epel-release
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
* base: ftp.sjtu.edu.cn
* epel: mirrors.huaweicloud.com
* extras: mirrors.163.com
* updates: mirrors.zju.edu.cn
Package epel-release-7-11.noarch already installed and latest version
Nothing to do
[root@localhost ~]#
由于我前面已經(jīng)更新過虛擬機的yum源,因此并未做什么更新。
然后我們需要在虛擬機上部署下Docker 運行的環(huán)境,在此我們直接采用yum在線安裝的方式直接安裝下。其他部署方式,諸如源碼編譯安裝等感興趣的同學可以自行參考Docker 官網(wǎng)安裝教程(https://docs.sevenbridges.com/docs/install-docker)進行部署。
Docker 安裝過程可能需要幾分鐘的時間,安裝完成后需要啟動下 Docker 守護進程:
[root@localhost ~]# systemctl start docker
[root@localhost ~]#
查看下 Docker 守護進程是否已經(jīng)在運行:
[root@localhost ~]# systemctl status docker
docker.service - Docker Application Container Engine
Loaded: loaded (/etc/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2019-02-25 15:35:52 CST; 46s ago
Docs: http://docs.docker.com
Main PID: 14413 (dockerd-current)
CGroup: /system.slice/docker.service
├─14413 /usr/bin/dockerd-current --exec-opt native.cgroupdriver=systemd --selinux-enabled=false --insecure-registry gcr...
└─14428 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-int...
Feb 25 15:35:52 work docker-current[14413]: time='2019-02-25T15:35:52.555468533+08:00' level=info msg='Firewalld running: false'
Feb 25 15:35:52 work docker-current[14413]: time='2019-02-25T15:35:52.650339401+08:00' level=info msg='Default bridge (docke...dress'
Feb 25 15:35:52 work docker-current[14413]: time='2019-02-25T15:35:52.675313581+08:00' level=info msg='Loading containers: done.'
Feb 25 15:35:52 work docker-current[14413]: time='2019-02-25T15:35:52.676370514+08:00' level=warning msg='Not using native d...o fix'
Feb 25 15:35:52 work docker-current[14413]: time='2019-02-25T15:35:52.676966551+08:00' level=warning msg='failed to retrieve...$PATH'
Feb 25 15:35:52 work docker-current[14413]: time='2019-02-25T15:35:52.677003665+08:00' level=warning msg='failed to retrieve...rsion'
Feb 25 15:35:52 work docker-current[14413]: time='2019-02-25T15:35:52.677250954+08:00' level=info msg='Daemon has completed ...ation'
Feb 25 15:35:52 work docker-current[14413]: time='2019-02-25T15:35:52.677267059+08:00' level=info msg='Docker daemon' commit...1.13.1
Feb 25 15:35:52 work docker-current[14413]: time='2019-02-25T15:35:52.681264961+08:00' level=info msg='API listen on /var/ru....sock'
Feb 25 15:35:52 work systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]#
設置開機自啟:
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /etc/systemd/system/docker.service.
確認下是否可以查看到 Docker 的info 信息,正常部署完成可以看到Docker 的 info 信息:
[root@localhost ~]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 1.13.1
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: false
Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: systemd
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: (expected: aa8187dbd3b7ad67d8e5e3a15115d3eef43a7ed1)
runc version: N/A (expected: 9df8b306d01f59d3a8029be411de015b7304dd8f)
init version: N/A (expected: 949e6facb77383876aeff8a6944dde66b3089574)
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-327.36.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
Number of Docker Hooks: 3
CPUs: 4
Total Memory: 976.9 MiB
Name: work
ID: V7HM:XRBY:P6ZU:SGWK:J52L:VYOY:UK6L:TR45:YJRC:SZBS:DQRF:CFP5
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://hub-mirror.c.163.com/v1/
Experimental: false
Insecure Registries:
gcr.io
127.0.0.0/8
Live Restore Enabled: false
Registries: hub-mirror.c.163.com (secure), docker.io (secure)
[root@localhost ~]#
從結(jié)果可以看出,當前我們安裝的Docker 版本為1.13。
Docker 環(huán)境部署結(jié)束后,我們需要pull下ownload 的鏡像,在docker pull 之前我們需要先登錄下目標hub:
[root@localhost ~]# docker login -u 賬號 -e your@email hub.c.163.com
Flag --email has been deprecated, will be removed in 1.14.
Password:
Login Succeeded
[root@localhost ~]#
拉取owncloud 鏡像:
[root@localhost ~]# docker pull hub.c.163.com/library/owncloud:latest
Trying to pull repository hub.c.163.com/library/owncloud ...
sha256:fdda568e8fef81f69df873d965d67d112eff770cff64f9b1ba055c7e19ea6ac0: Pulling from hub.c.163.com/library/owncloud
3ebc4e3ed1b2: Pull complete
c564d17b49c8: Pull complete
c424469b3e97: Pull complete
5e11f00270e2: Pull complete
4e954eec6dd4: Pull complete
176ba716cc40: Pull complete
59f7c8998494: Pull complete
7c3913488b7f: Pull complete
2409b3c9501c: Pull complete
b675e82c75a1: Pull complete
6f624c1c100d: Pull complete
7d41dd54b1c4: Pull complete
b7990372920c: Pull complete
99d88c7f1c49: Pull complete
00e2690b63a6: Pull complete
8ff08f48bba5: Pull complete
658c2474e164: Pull complete
92371a48c368: Pull complete
fc513e087257: Pull complete
bf45de679453: Pull complete
Digest: sha256:fdda568e8fef81f69df873d965d67d112eff770cff64f9b1ba055c7e19ea6ac0
Status: Downloaded newer image for hub.c.163.com/library/owncloud:latest
[root@localhost ~]#
檢查本地鏡像:
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hub.c.163.com/library/owncloud latest 183d08975211 19 months ago 587 MB
[root@localhost ~]#
可以看到ownload 鏡像已經(jīng)被拉取到本地,且tag為latest。
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hub.c.163.com/library/owncloud latest 183d08975211 19 months ago 587.2 MB
[root@localhost ~]#
運行owncloud容器:
[root@localhost ~]# docker run --name owncloud –p 80:80 -d hub.c.163.com/library/owncloud:latest
a4e48b60d0eb3b233000c70d35bc602f1233bc37a9dac9252a3e0ffeddf4de29
容器名稱owncloud,并將容器中的80端口映射到虛擬機的80端口,這樣我們訪問虛擬機的80端口時即可訪問到容器的80端口,即owncloud。
查看owncloud 容器是否已經(jīng)在后臺運行起來:
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a4e48b60d0eb hub.c.163.com/library/owncloud:latest 'docker-entrypoint.sh' 6 seconds ago Up 3 seconds 80/tcp owncloud
[root@localhost ~]#
Owncloud 中注冊信息、配置信息等需要寫入mysql,因此下面我們需要部署一下mysql 數(shù)據(jù)庫服務,本文中我們將mysql部署到虛擬機上。
建議安裝mysql5.7 或者更高的版本,否則在設置錄owncloud時會報錯:
具體過程如下:
首先需要先卸載掉CentOS7.x上自帶的mariadb數(shù)據(jù)庫,刪除mariadb 數(shù)據(jù)庫殘留的數(shù)據(jù)庫文件:
[root@localhost ~]# rm -rf /var/lib/mysql*
下載mysql yum 源安裝文件:
[root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
--2019-02-25 20:57:41-- http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm [following]
--2019-02-25 20:57:41-- https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm [following]
--2019-02-25 20:57:52-- https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.78.217.58
Connecting to repo.mysql.com (repo.mysql.com)|23.78.217.58|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25548 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-10.noarch.rpm’
100%[==============================================================================>] 25,548 --.-K/s in 0.03s
2019-02-25 20:57:52 (751 KB/s) - ‘mysql57-community-release-el7-10.noarch.rpm’ saved [25548/25548]
-c: No such file or directory
No URLs found in -c.
FINISHED --2019-02-25 20:57:52--
Total wall clock time: 12s
Downloaded: 1 files, 25K in 0.03s (751 KB/s)
安裝下載的mysql yum 源:
[root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
Loaded plugins: fastestmirror, langpacks
Examining mysql57-community-release-el7-10.noarch.rpm: mysql57-community-release-el7-10.noarch
Marking mysql57-community-release-el7-10.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-10 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================================
Package Arch Version Repository Size
========================================================================================================================
Installing:
mysql57-community-release noarch el7-10 /mysql57-community-release-el7-10.noarch 30 k
Transaction Summary
========================================================================================================================
Install 1 Package
Total size: 30 k
Installed size: 30 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql57-community-release-el7-10.noarch 1/1
Verifying : mysql57-community-release-el7-10.noarch 1/1
Installed:
mysql57-community-release.noarch 0:el7-10
Complete!
yum 安裝 mysql 服務:
[[root@localhost ~]# yum -y install mysql-community-server
Loaded plugins: fastestmirror, langpacks
mysql57-community | 2.5 kB 00:00:00
mysql57-community/x86_64/primary_db | 170 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* epel: mirror.premi.st
* extras: mirrors.163.com
* updates: mirrors.zju.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.25-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.25-1.el7 for package: mysql-community-server-5.7.25-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.25-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.25-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.25-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.6.43-2.el7 will be updated
---> Package mysql-community-common.x86_64 0:5.7.25-1.el7 will be an update
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.6.43-2.el7 will be updated
---> Package mysql-community-libs.x86_64 0:5.7.25-1.el7 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================================
Package Arch Version Repository Size
========================================================================================================================
Installing:
mysql-community-server x86_64 5.7.25-1.el7 mysql57-community 165 M
Installing for dependencies:
mysql-community-client x86_64 5.7.25-1.el7 mysql57-community 24 M
Updating for dependencies:
mysql-community-common x86_64 5.7.25-1.el7 mysql57-community 274 k
mysql-community-libs x86_64 5.7.25-1.el7 mysql57-community 2.2 M
Transaction Summary
========================================================================================================================
Install 1 Package (+1 Dependent package)
Upgrade ( 2 Dependent packages)
Total download size: 192 M
Downloading packages:
No Presto metadata available for mysql57-community
(1/4): mysql-community-common-5.7.25-1.el7.x86_64.rpm | 274 kB 00:00:00
(2/4): mysql-community-libs-5.7.25-1.el7.x86_64.rpm | 2.2 MB 00:00:01
(3/4): mysql-community-client-5.7.25-1.el7.x86_64.rpm | 24 MB 00:00:13
(4/4): mysql-community-server-5.7.25-1.el7.x86_64.rpm | 165 MB 00:01:47
------------------------------------------------------------------------------------------------------------------------
Total 1.8 MB/s | 192 MB 00:01:48
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
……
……
Installed:
mysql-community-server.x86_64 0:5.7.25-1.el7
Dependency Installed:
mysql-community-client.x86_64 0:5.7.25-1.el7
Dependency Updated:
mysql-community-common.x86_64 0:5.7.25-1.el7 mysql-community-libs.x86_64 0:5.7.25-1.el7
Complete!
[root@localhost ~]#
安裝完成后,需要啟動下mysql服務:
[root@localhost ~]# systemctl start mysqld
查看mysql 服務狀態(tài):
[root@localhost ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2019-02-25 21:10:23 CST; 11s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 8120 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 8042 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 8123 (mysqld)
Memory: 295.7M
CGroup: /system.slice/mysqld.service
└─8123 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Feb 25 21:10:10 localhost.localdomain systemd[1]: Starting MySQL Server...
Feb 25 21:10:23 localhost.localdomain systemd[1]: Started MySQL Server.
[root@localhost ~]#
設置mysql 開機自啟:
[root@localhost ~]# systemctl enable mysqld
設置完成后需要為owncloud 設置一個數(shù)據(jù)庫賬號,并新建一個數(shù)據(jù)庫owncloud。
查看數(shù)據(jù)庫原始密碼:
[root@localhost ~]# grep 'password' /var/log/mysqld.log
2019-02-25 20:36:49 3776 [Note] Shutting down plugin 'sha256_password'
2019-02-25 20:36:49 3776 [Note] Shutting down plugin 'mysql_old_password'
2019-02-25 20:36:49 3776 [Note] Shutting down plugin 'mysql_native_password'
2019-02-25 20:52:46 7441 [Note] Shutting down plugin 'sha256_password'
2019-02-25 20:52:46 7441 [Note] Shutting down plugin 'mysql_old_password'
2019-02-25 20:52:46 7441 [Note] Shutting down plugin 'mysql_native_password'
2019-02-25T13:10:18.272936Z 1 [Note] A temporary password is generated for root@localhost: tletSusYl3%S
2019-02-25T13:11:14.004386Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost ~]#
從結(jié)果看初始密碼為:tletSusYl3%S。
我們先用原始密碼登錄數(shù)據(jù)庫,然后修改初始密碼,修改mysql 賬號白名單:
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.25
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root@owncloud123';
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> grant all privileges on *.* to 'root'@'%' identified by 'Root@owncloud123';
Query OK, 0 rows affected, 1 warning (0.01 sec)
新建數(shù)據(jù)庫owncloud:
mysql> create database owncloud;
Query OK, 1 row affected (0.00 sec)
mysql>
以上即配置數(shù)據(jù)庫的過程。
下面我們通過虛擬機的IP訪問下owncloud:
根據(jù)頁面提示配置信息。
Admin count 根據(jù)自己需要進行設置即可,中間的數(shù)據(jù)存放路徑采用默認即可,數(shù)據(jù)庫此處我們選擇mysql/Mariadb,填寫上文中我們設置的mysql的賬號、密碼、數(shù)據(jù)庫,host填寫虛擬機IP 即可。
此過程需要約1分鐘,初始化成功后會自動跳轉(zhuǎn)到登錄界面:
查看數(shù)據(jù)庫,此時可看到庫owncloud中已經(jīng)新建了很多表,且表oc_accounts中已經(jīng)寫入了我們剛剛注冊的賬號信息:
mysql> use owncloud;
Database changed
mysql> show tables;
+-----------------------------+
| Tables_in_owncloud |
+-----------------------------+
| oc_account_terms |
| oc_accounts |
| oc_addressbookchanges |
| oc_addressbooks |
| oc_appconfig |
| oc_authtoken |
| oc_calendarchanges |
| oc_calendarobjects |
| oc_calendars |
| oc_calendarsubscriptions |
| oc_cards |
| oc_cards_properties |
| oc_comments |
| oc_comments_read_markers |
| oc_credentials |
| oc_dav_shares |
| oc_external_applicable |
| oc_external_config |
| oc_external_mounts |
| oc_external_options |
| oc_federated_reshares |
| oc_file_locks |
| oc_filecache |
| oc_files_trash |
| oc_group_admin |
| oc_group_user |
| oc_groups |
| oc_jobs |
| oc_migrations |
| oc_mimetypes |
| oc_mounts |
| oc_notifications |
| oc_preferences |
| oc_privatedata |
| oc_properties |
| oc_schedulingobjects |
| oc_share |
| oc_share_external |
| oc_storages |
| oc_systemtag |
| oc_systemtag_group |
| oc_systemtag_object_mapping |
| oc_trusted_servers |
| oc_users |
| oc_vcategory |
| oc_vcategory_to_object |
+-----------------------------+
46 rows in set (0.00 sec)
mysql> select * from oc_accounts;
+----+-------+----------+---------------+--------------+-------+------------+------------------+-----------------------------+-------+
| id | email | user_id | lower_user_id | display_name | quota | last_login | backend | home | state |
+----+-------+----------+---------------+--------------+-------+------------+------------------+-----------------------------+-------+
| 1 | NULL | owncloud | owncloud | owncloud | NULL | 0 | OC\User\Database | /var/www/html/data/owncloud | 1 |
+----+-------+----------+---------------+--------------+-------+------------+------------------+-----------------------------+-------+
1 row in set (0.00 sec)
mysql>
登錄owncloud:
作者簡介:阿木,目前就職于國內(nèi)某知名互聯(lián)網(wǎng)公司,擔任云計算技術部高級工程師,近3年云計算從業(yè)經(jīng)驗,愛讀書、愛寫作、愛技術。