百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术资源 > 正文

构建个人私有云盘:简单步骤一键打造云端存储

off999 2025-01-08 16:30 22 浏览 0 评论

云盘背景介绍

云盘的出现满足了人们对数据存储、备份、访问和共享的多种需求,提供了方便、灵活和安全的解决方案。这些服务已成为个人和企业日常生活中不可或缺的一部分。

ownCloud 简介

ownCloud 是一款用于数据同步和文件共享的开源服务器软件,它提供了易用的浏览器端,可以很方便的搭建个人和企业云盘。ownCloud 可以安装在 Linux 或 Windows 服务器上,配置简单并提供完备的文档。除浏览器端外,它还支持 Windows、MacOS、Linux、Android 和 iOS 客户端。 本文将详细描述如何在 CentOS 7 服务器上安装和配置 ownCloud 10.13,展示如何使用 Nginx 和 PHP 7(FPM)以及 MySQL 来配置 ownCloud。

核心特性:

  • 支持 Android、iOS 和桌面端访问文件。
  • 支持 Dropbox、S3 和 Google Docs 等外部存储。
  • 提供历史版本支持,可以恢复意外删除的文件。

安装前提

  • 1 台 CentOS 7 云服务器
  • 1 个具有 root 权限的账号

运行 ownCloud 的内存要求很低,但官方要求至少 128MB 内存,建议 512MB 内存。由于我们搭建的私人云盘,512MB 内存能支持 10 用户并发,已足够我们使用。

安装和配置 MySQL

首先,下载 MySQL rpm 包,使用本地安装方式下载安装包及依赖包:

yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm 

然后,安装 mysql-community-server 软件包,启动 MySQL 并找到随机密码:

# 安装 MySQL
yum install mysql-community-server

# 启动 MySQL
systemctl start mysqld

# 查找安装时生成的随机密码
[root@ownCloud ~]# grep -i password /var/log/mysqld.log
2023-09-03T07:04:16.666834Z 1 [Note] A temporary password is generated for root@localhost: aiwfrtTl7-=2

接着,我们使用随机密码登录 MySQL,创建 ownCloud 库和 ownCloud 用户并做好授权:

# 创建 ownCloud 库
mysql> CREATE DATABASE owncloud DEFAULT CHARACTER SET utf8mb4;

# 新建 ownCloud 用户
mysql> CREATE USER owncloud@'%' IDENTIFIED BY 'owncloud';

# 授权
mysql> grant all privileges on owncloud.* to owncloud@'%' identified by 'owncloud';

# 刷新授权
mysql> flush privileges;

安装和配置 PHP7(FPM)

  1. 添加 php7-fpm 库

网上有很多 PHP7 库,我们这里使用 webtatic 库:

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
  1. 安装 php7-fpm 和 ownCloud 依赖的软件包

接着我们安装 php7-fpm 和一些用于 ownCloud 安装的依赖软件包:

yum -y install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-intl php-pecl-zip

若提示 “失败的软件包是:mysql-community-libs-compat-5.7.43-1.el7.x86_64”,请使用rpm --import [https://repo.mysql.com/RPM-GPG-KEY-mysql-2022](https://repo.mysql.com/RPM-GPG-KEY-mysql-2022)命令解决。

检查 PHP 版本确保安装成功:

[root@owncloud tmp]# php -v
PHP 7.4.33 (cli) (built: Aug  1 2023 09:00:17) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
  1. 配置 php7-fpm

我们将配置 php-fpm 与 nginx 一块运行。php7-fpm 将在 nginx 用户下运行,并监听 9000 端口。 使用 vim 编辑默认的 php7-fpm 配置:

vim /etc/php-fpm.d/www.conf

在第 24 行和第 26 行中,将 user 和 group 更改为 nginx。

user = nginx
group = nginx

查看第 38 行,确保 php-fpm 在 9000 端口运行。

listen = 127.0.0.1:9000

取消第 396-400 行的注释,开启 php-fpm 系统环境变量。

env[HOSTNAME] = $HOSTNAME 
env[PATH] = /usr/local/bin:/usr/bin:/bin 
env[TMP] = /tmp 
env[TMPDIR] = /tmp 
env[TEMP] = /tmp

保存文件并退出编辑器。接下来,在 /var/lib/ 目录中为 session 创建一个新目录,并将目录所有者更改为 nginx 用户。

mkdir -p /var/lib/php/session 
chown nginx:nginx -R /var/lib/php/session/
  1. 启动 php-fpm

启动 php-fpm,然后将其添加到开机自启动。

systemctl start php-fpm
 
systemctl enable php-fpm

至此,php7-fpm 配置已完成。

安装和配置 Nginx

  1. 添加 Nginx 官方 yum 库

添加 Nginx 官方 yum 源 /etc/yum.repos.d/nginx.repo 文件中添加以下内容,设置 nginx yum 源:

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
  1. 安装 Nginx
yum install -y nginx
  1. 启动并设置开机启动
systemctl start nginx
 
systemctl enable nginx

安装 ownCloud

  1. 下载 ownCloud

我们使用 wget 命令下载 ownCloud,因此需要先安装 wget 包。另外,我们还需要安装 unzip 包用于解压缩 zip 文件。

yum -y install wget unzip

进入 /tmp 目录并使用 wget 从 ownCloud 站点下载最新稳定的 ownCloud 10.13 压缩包:

cd /tmp
wget --no-check-certificate https://download.owncloud.com/server/stable/owncloud-10.13.0.zip

解压 owncloud-10.13.0.zip 文件并将其移动到 /usr/share/nginx/html/ 目录:

unzip owncloud-10.13.0.zip
mv owncloud/ /usr/share/nginx/html/

接下来,转到 nginx Web 根目录并为 owncloud 创建一个新的 data 目录。

cd /usr/share/nginx/html/ 
mkdir -p owncloud/data/

将 owncloud 目录的所有者更改为 nginx 用户和组。

chown nginx:nginx -R owncloud/
  1. 配置 OwnCloud

1). 生成自签名 SSL 证书

我们将在的 https 连接下运行 owncloud。您可以使用免费的 SSL 证书,例如 let's encrypt。在本文中,我将使用 OpenSSL 命令创建我自己的 SSL 证书文件。为 SSL 文件创建一个新目录:

mkdir -p /etc/nginx/cert/

然后使用下面的 OpenSSL 命令生成新的 SSL 证书文件:

openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/owncloud.crt -keyout /etc/nginx/cert/owncloud.key

按照 OpenSSL 命令的要求输入 SSL 证书的详细信息。然后用 chmod 命令将所有证书文件的权限改为 600。

chmod 600 /etc/nginx/cert/*

2). 在 Nginx 中配置 ownCloud 虚拟主机

1.下载 ownCloud 步骤中,我们下载了 ownCloud 源代码并将其配置为在 Nginx Web 服务器下运行。但我们仍然需要为 ownCloud 配置虚拟主机。 在 /etc/nginx/conf.d/ 目录中创建一个新的虚拟主机配置文件 owncloud.conf:

cd /etc/nginx/conf.d/ 
vim owncloud.conf

添加以下虚拟主机配置:

upstream php-handler {
    server 127.0.0.1:9000;
    #server unix:/var/run/php5-fpm.sock;
}
 
server {
    listen 80;
    server_name data.owncloud.co;
    # enforce https
    return 301 https://$server_name$request_uri;
}
 
server {
    listen 443 ssl;
    server_name data.owncloud.co;
 
    ssl_certificate /etc/nginx/cert/owncloud.crt;
    ssl_certificate_key /etc/nginx/cert/owncloud.key;
 
    # Add headers to serve security related headers
    # Before enabling Strict-Transport-Security headers please read into this topic first.
    add_header Strict-Transport-Security "max-age=15552000; includeSubDomains";
    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;
    add_header X-Download-Options noopen;
    add_header X-Permitted-Cross-Domain-Policies none;
 
    # Path to the root of your installation
    root /usr/share/nginx/html/owncloud/;
 
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
 
    # The following 2 rules are only needed for the user_webfinger app.
    # Uncomment it if you're planning to use this app.
    #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
    #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
 
    location = /.well-known/carddav {
        return 301 $scheme://$host/remote.php/dav;
    }
    location = /.well-known/caldav {
        return 301 $scheme://$host/remote.php/dav;
    }
 
    location /.well-known/acme-challenge { }
 
    # set max upload size
    client_max_body_size 512M;
    fastcgi_buffers 64 4K;
 
    # Disable gzip to avoid the removal of the ETag header
    gzip off;
 
    # Uncomment if your server is build with the ngx_pagespeed module
    # This module is currently not supported.
    #pagespeed off;
 
    error_page 403 /core/templates/403.php;
    error_page 404 /core/templates/404.php;
 
    location / {
        rewrite ^ /index.php$uri;
    }
 
    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
        return 404;
    }
    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
        return 404;
    }
 
    location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS on;
        fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
        fastcgi_param front_controller_active true;
        fastcgi_pass php-handler;
        fastcgi_intercept_errors on;
        fastcgi_request_buffering off;
    }
 
    location ~ ^/(?:updater|ocs-provider)(?:$|/) {
        try_files $uri $uri/ =404;
        index index.php;
    }
 
    # Adding the cache control header for js and css files
    # Make sure it is BELOW the PHP block
    location ~* \.(?:css|js)$ {
        try_files $uri /index.php$uri$is_args$args;
        add_header Cache-Control "public, max-age=7200";
        # Add headers to serve security related headers (It is intended to have those duplicated to the ones above)
        # Before enabling Strict-Transport-Security headers please read into this topic first.
        #add_header Strict-Transport-Security "max-age=15552000; includeSubDomains";
        add_header X-Content-Type-Options nosniff;
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Robots-Tag none;
        add_header X-Download-Options noopen;
        add_header X-Permitted-Cross-Domain-Policies none;
        # Optional: Don't log access to assets
        access_log off;
    }
 
    location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
        try_files $uri /index.php$uri$is_args$args;
        # Optional: Don't log access to other assets
        access_log off;
    }
}

保存文件并退出编辑器。

最后,测试 nginx 配置无误,然后重新启动 nginx。

# 验证 nginx 配置是否有误
nginx -t

# 重新启动 nginx
systemctl restart nginx

配置 SELinux 和 firewalld

我们将使 SELinux 保持在强制模式下,因此我们需要 SELinux 管理工具包来配置它。使用 yum 命令安装 SELinux 管理工具:

yum -y install policycoreutils-python

然后以 root 身份执行以下命令,以允许 ownCloud 在 SELinux 下运行。请记住更改 ownCloud 目录,以防您使用不同的目录进行 ownCloud 安装:

semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/owncloud/data(/.*)?' 
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/owncloud/config(/.*)?' 
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/owncloud/apps(/.*)?' 
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/owncloud/assets(/.*)?' 
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/owncloud/.htaccess' 
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/owncloud/.user.ini' 

restorecon -Rv '/usr/share/nginx/html/owncloud/'

接下来,启动 firewalld 服务并打开 owncloud 的 HTTP 和 HTTPS 端口。

# 启动 firewalld 服务
systemctl start firewalld

# 开启 firewalld 服务自启动
systemctl enable firewalld

使用 firewall-cmd 命令打开 HTTP 和 HTTPS 端口,然后重新加载防火墙使之立即生效。

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

至此,服务器配置部分已完成。

ownCloud 安装向导

现在,打开浏览器并输入 ownCloud 公网IP,我的IP是:xxx.xxx.xxx.xxx,您将被重定向到安全的 HTTPS 连接。设置管理员的用户名和密码,然后输入数据库信息并单击完成设置,等待 OwnCloud 安装完成。

至此,Owncloud 已在 CentOS 7 服务器上成功安装 Nginx、php7-fpm 和 MySQL。

若提示 php zip 模块没有安装或者 intl 模块没有安装,请运行 yum -y install php-intl php-pecl-zip 命令安装


相关推荐

2025十佳笔记本排行(2021年十大最佳笔记本)

2021年,笔记本电脑用什么CPU最好用?当然是艾灸系列最新12代的CPU最好用,也需要根据他的具体配置搭配什么样的主板和显卡,按成熟度来说,还是选择次心大的笔记本CPU比较好,因为硬件搭配也是202...

老式台式机怎么装m2固态硬盘
  • 老式台式机怎么装m2固态硬盘
  • 老式台式机怎么装m2固态硬盘
  • 老式台式机怎么装m2固态硬盘
  • 老式台式机怎么装m2固态硬盘
手机谷歌浏览器(手机谷歌浏览器怎么关闭无痕模式)

使用手机chrome方法:1、打开手机上的谷歌浏览器2、点击打开后,找到右上角的三个小点,点开它,会看到“设置”3、点开设置,然后会出现“搜索引擎”4、点开“搜索引擎”然后选择“搜狗”。5、然后一步步...

千兆网对路由器有要求吗(千兆路由器对无线有用吗)

回答:虽然不是必须,但是建议采用千兆路由器。只有使用千兆路由器,才能达到1000M光纤的最高网速。当使用旧的百兆路由器情况下,千兆带宽只能达到百兆网速。不能充分利用带宽,这样对您的千兆互联网光纤带宽...

win7重装系统方法(win7系统重装详细步骤)

步骤1、打开云骑士装机大师,点击一键装机下的【立即重装】,检测完毕后点击【下一步】;步骤2、选择windows7下的旗舰版32位,点击【下一步】,自行选择或取消推荐的软件,点击【下一步】;步骤3、备份...

电脑桌面啥都没有了怎么回事

1、如果我们桌面上什么东西都没有,可以先打开任务管理器,然后顶级左上方的文件,随后新建任务,在打开的界面中输入explorer,点击确认之后,等个几秒钟左右就可以看见桌面上的图标了。  2、另一个方法...

如何将电脑恢复出厂设置win7

1.首先我们打开电脑找到“计算机”点击打开。2.进入页面然后我们点击“Windows7(C:)”打开C盘。3.我们在C盘界面找到Windows7并点击打开。4.进入到Win7文件夹中找到并双击“Sys...

u盘存在但是读不出来(u盘显示有内容但读不出来怎么办)

u盘能识别,不能读取可能是你关闭了u盘自动读取,取消后即可。步骤:1、在电脑桌面右键点击“计算机”,在出现的菜单中选择“管理”选项2、在弹出的计算机管理窗口,依次打开“计算机管理-服务和应用程序-服务...

win8家庭中文版下载(windows家庭中文版下载)

可以按照以下步骤在Win8上下载和安装Word:1.通过微软官网下载购买,或者通过MicrosoftStore应用商店进行购买和下载。2.下载完成后,打开文件夹,双击setup进行安装。3.安...

教大家强制退出苹果id账号(教大家强制退出苹果id账号ipad)

1.首先将手机强制关机,并在电脑端安装iTunes并打开。2.用数据线将手机与电脑连接起来,长按手机电源键。3.当出现苹果标志时不要松开电源键,接着按Home键。4.直到屏幕黑屏,松开电源键。5.继续...

惠普官网驱动下载官网(惠普驱动官方)

在惠普官网下载系统驱动方法如下访问HP官网:www.hp.com找到支持与驱动页面(通常在顶部导航栏的支持或下载中)输入你的HP产品的序列号或选择产品类型和型号选择你的操作系统,然后下载相关的驱动。安...

电脑公司取名字大全(电脑行业公司取名)

动感网络IT狂人行鱼雷IT网PC宝宝网外有鱼超导技术网PC技术网加点分吧,不然想不出太多,呵呵绿苑计算机协会绿色代表生命,有起航的意义,苑是一个范畴,有地域的意思,是给你们一片天地的意思...

系统一键重装win7(win7一键重装系统win10)
  • 系统一键重装win7(win7一键重装系统win10)
  • 系统一键重装win7(win7一键重装系统win10)
  • 系统一键重装win7(win7一键重装系统win10)
  • 系统一键重装win7(win7一键重装系统win10)
如何卸载显卡驱动(主板驱动)
  • 如何卸载显卡驱动(主板驱动)
  • 如何卸载显卡驱动(主板驱动)
  • 如何卸载显卡驱动(主板驱动)
  • 如何卸载显卡驱动(主板驱动)
wifi怎么设置网速快(手机测wifi网速怎么测)

wifi加速设置方法步骤如下。1设置网速:浏览器中输入终端地址,输入账号和密码。找到连接设备数目并进行更改,找到信道宽度,选择更快的网速。2提高WiFi网速:进入设置中心,点击WLAN选项。点击高级设...

取消回复欢迎 发表评论: