在目前眾多網(wǎng)盤小場(chǎng)紛紛宣布自己倒下或者即將倒下的時(shí)代,大家除了使用幾個(gè)大廠的服務(wù)外,也可另辟蹊徑搭建一套屬于自己的網(wǎng)盤服務(wù)。 針對(duì)個(gè)人需要的數(shù)據(jù)云備份、云存儲(chǔ)、數(shù)據(jù)分享、在線視頻、音樂等本文中部署的個(gè)人網(wǎng)盤皆可滿足。話不多說,下面我們就進(jìn)入個(gè)人網(wǎng)盤搭建的正文。本文中底層的云存儲(chǔ)工具我們以owncloud為例。 根據(jù)維基百科介紹,ownCloud 是一個(gè)自由且開源的個(gè)人云存儲(chǔ)解決方案,包括服務(wù)器和客戶端兩部分。 
ownCloud 最早由KDE開發(fā)者Frank Karlitschek于2010年一月創(chuàng)建,目標(biāo)是成為商業(yè)云存儲(chǔ)服務(wù)商的替代。與商業(yè)云存儲(chǔ)不同,ownCloud可以自由獲取無需付費(fèi),但相應(yīng)的,用戶必須自行架設(shè)ownCloud服務(wù)器。 ownCloud在客戶端可透過網(wǎng)頁(yè)界面,或者安裝專用的客戶端軟件來使用。網(wǎng)頁(yè)界面當(dāng)然就是任何能開網(wǎng)頁(yè)的平臺(tái)都支持,而客戶端軟件也支持相當(dāng)多平臺(tái),Windows、Linux、iOS、Android皆有。
以下為部署的具體過程。 首先我們需要一臺(tái)服務(wù)器,在此我們以本地自己搭建的一臺(tái)虛擬機(jī)為例,發(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)境準(zhǔn)備完成后,我們?cè)谔摂M機(jī)上安裝下紅帽的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)更新過虛擬機(jī)的yum源,因此并未做什么更新。 然后我們需要在虛擬機(jī)上部署下Docker 運(yùn)行的環(huán)境,在此我們直接采用yum在線安裝的方式直接安裝下。其他部署方式,諸如源碼編譯安裝等感興趣的同學(xué)可以自行參考Docker 官網(wǎng)安裝教程(https://docs./docs/install-docker)進(jìn)行部署。 Docker 安裝過程可能需要幾分鐘的時(shí)間,安裝完成后需要啟動(dòng)下 Docker 守護(hù)進(jìn)程: [root@localhost ~]# systemctl start docker [root@localhost ~]#
查看下 Docker 守護(hù)進(jìn)程是否已經(jīng)在運(yùn)行: [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. 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 ~]#
設(shè)置開機(jī)自啟: [root@localhost ~]# systemctl enable docker Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /etc/systemd/system/docker.service.
確認(rèn)下是否可以查看到 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é)果可以看出,當(dāng)前我們安裝的Docker 版本為1.13。 Docker 環(huán)境部署結(jié)束后,我們需要pull下ownload 的鏡像,在docker pull 之前我們需要先登錄下目標(biāo)hub: [root@localhost ~]# docker login -u 賬號(hào) -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 ~]#
運(yùn)行owncloud容器: [root@localhost ~]# docker run --name owncloud –p 80:80 -d hub.c.163.com/library/owncloud:latest a4e48b60d0eb3b233000c70d35bc602f1233bc37a9dac9252a3e0ffeddf4de29
容器名稱owncloud,并將容器中的80端口映射到虛擬機(jī)的80端口,這樣我們?cè)L問虛擬機(jī)的80端口時(shí)即可訪問到容器的80端口,即owncloud。 查看owncloud 容器是否已經(jīng)在后臺(tái)運(yùn)行起來: [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 中注冊(cè)信息、配置信息等需要寫入mysql,因此下面我們需要部署一下mysql 數(shù)據(jù)庫(kù)服務(wù),本文中我們將mysql部署到虛擬機(jī)上。 建議安裝mysql5.7 或者更高的版本,否則在設(shè)置錄owncloud時(shí)會(huì)報(bào)錯(cuò): 
具體過程如下: 首先需要先卸載掉CentOS7.x上自帶的mariadb數(shù)據(jù)庫(kù),刪除mariadb 數(shù)據(jù)庫(kù)殘留的數(shù)據(jù)庫(kù)文件: [root@localhost ~]# rm -rf /var/lib/mysql*
下載mysql yum 源安裝文件: [root@localhost ~]# wget -i -c http://dev./get/mysql57-community-release-el7-10.noarch.rpm --2019-02-25 20:57:41-- http://dev./get/mysql57-community-release-el7-10.noarch.rpm Resolving dev. (dev.)... 137.254.60.11 Connecting to dev. (dev.)|137.254.60.11|:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://dev./get/mysql57-community-release-el7-10.noarch.rpm [following] --2019-02-25 20:57:41-- https://dev./get/mysql57-community-release-el7-10.noarch.rpm Connecting to dev. (dev.)|137.254.60.11|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://repo.//mysql57-community-release-el7-10.noarch.rpm [following] --2019-02-25 20:57:52-- https://repo.//mysql57-community-release-el7-10.noarch.rpm Resolving repo. (repo.)... 23.78.217.58 Connecting to repo. (repo.)|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 服務(wù): [[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 ~]#
安裝完成后,需要啟動(dòng)下mysql服務(wù): [root@localhost ~]# systemctl start mysqld
查看mysql 服務(wù)狀態(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./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 ~]#
設(shè)置mysql 開機(jī)自啟: [root@localhost ~]# systemctl enable mysqld
設(shè)置完成后需要為owncloud 設(shè)置一個(gè)數(shù)據(jù)庫(kù)賬號(hào),并新建一個(gè)數(shù)據(jù)庫(kù)owncloud。 查看數(shù)據(jù)庫(kù)原始密碼: [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ù)庫(kù),然后修改初始密碼,修改mysql 賬號(hào)白名單: [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ù)庫(kù)owncloud: mysql> create database owncloud; Query OK, 1 row affected (0.00 sec)
mysql>
以上即配置數(shù)據(jù)庫(kù)的過程。 下面我們通過虛擬機(jī)的IP訪問下owncloud: 
根據(jù)頁(yè)面提示配置信息。 Admin count 根據(jù)自己需要進(jìn)行設(shè)置即可,中間的數(shù)據(jù)存放路徑采用默認(rèn)即可,數(shù)據(jù)庫(kù)此處我們選擇mysql/Mariadb,填寫上文中我們?cè)O(shè)置的mysql的賬號(hào)、密碼、數(shù)據(jù)庫(kù),host填寫虛擬機(jī)IP 即可。 此過程需要約1分鐘,初始化成功后會(huì)自動(dòng)跳轉(zhuǎn)到登錄界面: 
查看數(shù)據(jù)庫(kù),此時(shí)可看到庫(kù)owncloud中已經(jīng)新建了很多表,且表oc_accounts中已經(jīng)寫入了我們剛剛注冊(cè)的賬號(hào)信息: 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: 
作者簡(jiǎn)介:阿木,目前就職于國(guó)內(nèi)某知名互聯(lián)網(wǎng)公司,擔(dān)任云計(jì)算技術(shù)部高級(jí)工程師,近3年云計(jì)算從業(yè)經(jīng)驗(yàn),愛讀書、愛寫作、愛技術(shù)。
|