1. 程式人生 > >Centos7 搭建開源個人網盤Nextcloud與常用外掛

Centos7 搭建開源個人網盤Nextcloud與常用外掛

    檔案伺服器,是一個公司最常用的服務應用,每個公司企業基本都有自己的檔案伺服器實,現儲存分享,上傳下載檔案文件等功能,常見的檔案伺服器就是ftp伺服器,但是ftp伺服器的功能實在有限,且對於普通使用者使用入手難度較大,又缺乏介面,對於公司的普通使用者來說,確實不是一個好的檔案伺服器。一般ftp也只是使用者伺服器,網站應用等方面。

    在目前的公司企業環境中,企業網盤則是一個更好的檔案伺服器替代方案。百度雲盤,相信大家基本都有用過吧,友好的介面互動,網頁端,客戶端都有,不需要任何命令,實現上傳下載,分享等諸多功能。但是這種雲盤畢竟不是自己的,很多公司對於將機密檔案放在上面心存疑惑,且時不時的網盤關閉熱潮也讓人擔心。既然如此,為何不搭建自己的網盤呢,於是就有了nextcloud。

    對於私人網盤,市面上已經有很多的產品,很多開源半開源的雲盤系統。其中最出名的就是 seafile和owncloud/nextcloud。seafile是國人開發的,分塊處理,斷點上傳,速度比後者要快。有社群版和企業版。社群版免費,但是功能有限,企業版要收費,功能更強大。但是社群版的功能,老實說只能滿足個人使用,無法滿足企業使用。而企業版要收費,費用根據公司人數不同,還需要發郵件詢問。

    像我著這種窮人,窮公司,人數不多,又不像花錢的,那麼nextcloud就是最好的選擇,nextcloud是owncloud的一個分支,由原創始人團隊維護,是在owncloud被別的公司收購後,由創始人團隊創立的新分支。就像 mysql和mariadb。nextcloud完全開源,功能強大,是外國人開發維護的。具體的與seafile等的對比,這裡不詳細說明了,有興趣的百度就好。下面記錄一下在centos7 伺服器上搭建nextcloud的具體過程。

環境: centos7 

nextcloud: 13.0.2 

selinux 關閉

1. nextcloud是php專案,這裡我使用nginx,官方文件是用apache的,有一點點具別。但不大。在下載nextcloud之前,先安裝nginx和php

# 先刪除系統可能自帶的PHP和nginx,用來面命令查詢是否有安裝
$ rpm -qa |grep php
$ rpm -qa |grep nginx

# 安裝yum的epel源
$ yum -y install epel-release

# 安裝nginx
$ yum install -y nginx

# 安裝php的源
$ rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

# 安裝php已經會用到擴充套件
$ yum install -y php70w-devel php70w-pear php70w-pecl php70w-gd php70w-opcache php70w-cli php70w-pdo php70w-process php70w-pecl-apcu php70w-mcrypt php70w-mysql php70w-fpm php70w-pecl-memcached php70w-common php70w-xml php70w-mbstring php70w-pecl-igbinary
# 檢查是否安裝成功 $ nginx -v nginx version: nginx/1.12.2 $ php -v PHP 7.0.30 (cli) (built: Apr 28 2018 08:14:08) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies     with Zend OPcache v7.0.30, Copyright (c) 1999-2017, by Zend Technologies

2. nextcloud 還需要資料庫,這裡我使用的mysql,mysql提前安裝好或使用已有的資料庫伺服器,具體安裝安裝方式可參考我另一篇博文: 《CentOS7.2 安裝mysql,並配置自動啟動和遠端訪問》。在mysql種建立一個新的databse用於nextcloud使用.

# 在裝有mysql的伺服器上執行
$ mysql -u root -p
> create database nextcloud_db;
# 授權給自定義使用者,這裡以使用者名稱:nextclouduser,密碼:nextcloudpasswd,代替。
> grant all privileges on nextcloud_db.* to [email protected] identified by 'nextcloudpasswd';
> flush privileges;

3.  為nextcloud 生成自簽名ssl證書

$ cd /etc/nginx/cert/    # 沒有則建立此資料夾
$ openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/nextcloud.crt -keyout /etc/nginx/cert/nextcloud.key
# 會出現下面的選項需要填寫,可以隨便填。
Country Name (2 letter code) [XX]:cn                                           //國家
State or Province Name (full name) []:guangdong                                  //省份
Locality Name (eg, city) [Default City]:guangzhou                               //地區名字
Organization Name (eg, company) [Default Company Ltd]:Amos                     //公司名
Organizational Unit Name (eg, section) []:Technology                           //部門
Common Name (eg, your name or your server's hostname) []:Amos                 //CA主機名
Email Address []:[email protected]                                                        //Email地址

# 修改證書和資料夾許可權
$ chmod 600 /etc/nginx/cert/*
$ chmod 700 /etc/nginx/cert

4. 下載nextcloud,並配置php和nginx

# 下載nextcloud,官網地址為: https://nextcloud.com/install/#instructions-server
$ cd /usr/local/src
$ yum install -y wget unzip
$ wget https://download.nextcloud.com/server/releases/nextcloud-13.0.2.zip    # 下載
$ unzip nextcloud-13.0.2.zip    # 解壓
$ mv nextcloud /usr/share/nginx/html/    # 移動到指定資料夾內
$ cd /usr/share/nginx/html/nextcloud     # 進行nextcloud 目錄中
$ mkdir data    # 建立資料資料夾
$ chown nginx:nginx -R nextcloud/    # 將nextcloud檔案授權給nginx

# 配置php-fpm
$ vim /etc/php-fpm.d/www.conf
-----------------------------------------------------------------------------------------
user = nginx                                   //將使用者和組都改為nginx
group = nginx
listen = 127.0.0.1:9000
env[HOSTNAME] = $HOSTNAME                     //將以下幾行,去掉註釋
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
------------------------------------------------------------------------------------------

# 為php建立session資料夾
$ mkdir -p /var/lib/php/session
$ chown nginx:nginx -R /var/lib/php/session/

# 配置nginx
$ cd /etc/nginx/conf.d/
$ vim nextcloud.conf
-------------------------------------------------------------------------------------------
upstream php-handler {
    server 127.0.0.1:9000;
    #server unix:/var/run/php5-fpm.sock;
}


server {
    listen 80;
    server_name localhost;
    # enforce https
    rewrite ^(.*)$ https://$host$1 permanent;
}


server {
    listen 443 ssl;
    server_name localhost;

    ssl_certificate /etc/nginx/cert/nextcloud.crt;
    ssl_certificate_key /etc/nginx/cert/nextcloud.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=15768000;
    includeSubDomains; preload;";
    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/nextcloud/;


    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;
    }


    # set max upload size
    client_max_body_size 10240M;    # 上傳檔案最大限制,php.ini中也要修改,最後優化時會提及。
    fastcgi_buffers 64 4K;

    # Disable gzip to avoid the removal of the ETag header
    gzip on;
    gzip_vary on;
    gzip_comp_level 4;
    gzip_min_length 256;
    gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
    gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;


    # 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)/ {
        deny all;
    }
    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
        deny all;
    }

    location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS on;
        #Avoid sending the security headers twice
        fastcgi_param modHeadersAvailable true;
        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/ =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=15768000;includeSubDomains; preload;";
        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原配置中80埠的配置刪除
$ vim /etc/nginx/nginx.conf
--------------------------------------------------------
server {          # 將80埠的server整個刪除,應該我們在上面nextcloud.conf中已經配置了,這裡不刪除的話會導致衝突不生效。
    listen 80;
...
  }
--------------------------------------------------------

5. 啟動nginx和php-fpm

$ nginx -t    # 檢查nginx配置是否正確,出現下面輸入則正確。
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

# 啟動並設為開機啟動 nginx,php-fpm
$ systemctl start nginx
$ systemctl enable nginx
$ systemctl start php-fpm
$ systemctl enable php-fpm

# 配置防火牆,開放http和https的埠。
$ firewall-cmd --add-port=80/tcp --permanent
$ firewall-cmd --add-port=443/tcp --permanent
$ firewall-cmd --reload

PS: 這裡我的selinux是關閉的,如果selinux沒有關閉,則執行下面命令關閉selinux
$ setenforce 0    # 關閉selinux
$ vim /etc/selinux/config    # 修改配置,永久關閉。
------------------------------------------------------
SELINUX=disabled
------------------------------------------------------

6. 訪問網頁介面,完成安裝。訪問搭建nextcloud伺服器的ip地址。(如果有域名就訪問域名)


    按照實際情況進行配置,配置完成後,點選安裝完成。上圖中mysql的主機名,使用上面我們自己的資料庫伺服器地址和埠

7.  效能優化,進入主介面後,右上角自己頭像,點選設定,基本設定:

第一項就有 安全及設定警告,這裡會有配置錯誤提示,優化提示等。根據提示進行優化:

① 修改php.ini 檔案,新增如下配置:

$ vim /etc/php.ini
------------------------------------------------------------------------
[PHP]    # 在[PHP] 以下新增如下配置
opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1
...
upload_max_filesize = 10240M    # 上傳檔案最大大小,可以自定義修改,預設為512M
------------------------------------------------------------------------

$ vim /etc/nginx/nginx.d/nextcloud.conf

② 設定快取後端,可以使用redis,memcache。單機或叢集模式都可以。不同的配置方式可以參考官方文件。

這裡我直接單機安裝並配置使用memcache。

$ yum install -y memcache
$ vim /etc/sysconfig/memcached
------------------------------------------------------------------------
PORT="11211"    # 埠
USER="memcached"    # 使用者
MAXCONN="1024"    # 最大連結數
CACHESIZE="2048"    # 最大記憶體,單位M
OPTIONS=""
-----------------------------------------------------------------------

# 修改nextcloud的config配置檔案,新增memcached快取配置
$ vim /usr/share/nginx/html/nextcloud/config/config.php
-----------------------------------------------------------------------
'memcache.local' => '\OC\Memcache\APCu',
  'memcache.distributed' => '\OC\Memcache\Memcached',
  'memcached_servers' => array(
   array('localhost', 11211),
     ),
-----------------------------------------------------------------------

③ 重啟nginx和php-fpm,是配置生效

$ systemctl start memcached
$ systemctl enable memcached
$ systemctl restart nginx
$ systemctl restart php-fpm

④ 設定後臺任務,cron執行。


$ vim /etc/crontab    # 修改cron配置檔案,新增如下配置
---------------------------------------------------------------------------------------
*/15 * * * * -u nginx /usr/bin/php -f /usr/share/nginx/html/nextcloud/cron.php
---------------------------------------------------------------------------------------

8. 配置郵件伺服器

在設定 --> 其他設定 中,配置smtp伺服器。並進行測試,收到郵件則為OK。


9. 到此,nextcloud已經安裝完成。除此之外,nextcloud還有很多常用外掛,用於拓展功能,包括官方的或個人的,點選右上角個人頭像-->應用


    在這裡可以直接點選安裝啟動應用。非常方便。本身安裝時便會自帶有一些應用,這裡推薦幾個需要手動安裝的常用應用:

①Announcement center  管理員可以發公告

②Circles 圈子,每個人都可以建立加入圈子,實現圈子的檔案共享

③Group folders 組資料夾

④File access control 檔案訪問控制

⑤Impersonate 管理員可以模擬使用者,可以以使用者登陸到他們的網盤,可以看到個人使用者的檔案,這個有點不太隱私。

。。。

    當然,還有很多有趣的應用,等你自己去發現。

OK,到此,nextcloud的搭建已經完成。自己去不斷使用,不斷探索功能吧。

PS:在設定中還會一直有一些報錯,雖然按照要求進行配置了,卻還是報錯,這就在暫且忽略掉吧

相關推薦

Centos7 搭建開源個人Nextcloud常用外掛

    檔案伺服器,是一個公司最常用的服務應用,每個公司企業基本都有自己的檔案伺服器實,現儲存分享,上傳下載檔案文件等功能,常見的檔案伺服器就是ftp伺服器,但是ftp伺服器的功能實在有限,且對於普通使用者使用入手難度較大,又缺乏介面,對於公司的普通使用者來說,確實不是一個好

在華為公有雲服務器上搭建seafile個人

華為雲 最近買了一臺華為ECS雲服務器,系統為centos7 64位,1核心1G內存,40G硬盤,1M帶寬,配置了雲監控,報警和基本DDos防禦。雖然配置不高,拿來學習是可以的。但是我想充分利用上雲服務器,所以想搭載一個個人網盤,保存個人資料。 開源而且免費的網盤,有seafile,服務器端有li

Centos7搭建個人

centos7搭建個人網盤使用yum安裝python及mysql:yum install python python-setuptoolspython-imaging python-ldap python-memcached MySQL-python mariadb mariadb-server啟動Maria

Linux下使用nextcloud搭建個人

服務 設置 執行 選擇 volumes mage 大量 ali 目錄 市面上有那麽多的網盤服務提供商,為什麽還要自己搭建網盤呢?主要有以下原因: 免費的網盤都有種種限制,要麽不限速容量小(onedriver,google driver),要麽容量大限速(百度雲) 付費網盤

一鍵式搭建私人絡硬個人,百度——owncloud安裝指南

百度網盤 網絡硬盤 個人網盤 微軟雲 虛擬機 一鍵式搭建私人網絡硬盤、個人網盤,百度網盤——owncloud安裝指南在微軟雲計算上,我們可以創建VM虛擬機部署“owncloud”網絡硬盤。搭建一個owncloud個人網盤。使用owncloud不僅安全,而且還可以在線播放,離線下載,功能相當

搭建私人絡硬個人,百度——Seafile安裝部署指南

個人網盤 百度網盤 網絡硬盤 微軟雲 虛擬機 搭建私人網絡硬盤、個人網盤,百度網盤——Seafile安裝部署指南在微軟雲計算上,我們可以創建VM虛擬機部署“Seafile”網絡硬盤。Seafile 是一個開源的文件雲存儲平臺,解決文件集中存儲、同步、多平臺訪問的問,允許用戶創建“群組”,在

onedrive搭建個人

緣由: 一直在使用百度網盤,但是下載速度非常慢。那我們可不可以自己搭建一個個人的網盤,可以線上看視訊,不限速。 首先要有一個5T的onedrive賬號 一般我們註冊的OneDrive只有5G。要想有5T的話,要有一個教育郵箱。 如

File Browser 記憶體小的VPS搭建個人的首選方案

目前網上比較流行私有云搭建方案基本都是用 NextCloud 或 SeaFile,不過這兩種方案安裝配置起來有些麻煩。經過不斷尋找,我發現了一款名為 File Browser 的開源軟體。 特點 佔用記

簡單!安全加密!如何搭建個人-BitTorrent Sync

BitTorrent Sync 是 BitTorrent Labs 推出的實驗性專案,可以在多臺電腦間進行點對點自動分享/同步檔案,也可作為分散式網盤,相當於一個私人性質的 Dropbox 誕生,只需要持續開啟一臺電腦。支援Mac OS X (10.6 or later)/

打造個人專屬nextCloud

第一步:開通雲伺服器   進入https://ecs-buy.aliyun.com/#/prepay我們就可以選擇購買 ECS 產品了,根據產品購買頁面我們一步一步講。一、計費方式:   包年包

基於CentOS搭建個人

1. 安裝 Seafile 安裝依賴環境 使用 yum 安裝 Python 及 MySQL: yum install python python-setuptools python-imaging python-ldap python-memcached

個人搭建過程--資料來自騰訊雲實驗室

一、域名 註冊域名 解析域名 二、安裝Seafile 安裝依賴包 yum install python python-setuptools python-imaging python-ldap python-memcached MySQL-python mariadb ma

利用樹莓派和閒置硬碟,搭建起家中的個人

因為給個人膝上型電腦升級,替換下來了一塊2.5寸的1T機械硬碟,想著閒置也是閒置,不如用來搞一個nas玩玩,可以存放一些個人檔案和電影大片,共享給家中的所有人,接下來就跟隨我的腳步,一起來看看如何實現吧 #### 1.前期準備 - 樹莓派(刷好官方系統,具體教程請見百度) - 閒置硬碟(可以是2.5寸

VPS教程:搭建個人教程—kodexplorer

kodexplorer網盤系統。Kodexplorer,也叫芒果雲、可道雲、kodcloud,總之名字改了不少。但其本身作為一個網盤檔案系統,還是有很多可圈可點的地方。 seafile、h5ai、kodexplorer 三者的特點優劣勢分析比較,參考[《VPS 搭個人網盤,seafile、kodexplor

搭建 Seafile 專屬

permanent 防火墻 secure 參數 wall mysql- mar 騰訊雲 zone 準備域名 任務時間:15min ~ 20min 域名註冊 如果您還沒有域名,可以在騰訊雲上選購,過程可以參考下面的視頻。 視頻 - 在騰訊雲上購買域名 域名解析 域名購

私有nextcloud 12的問題處理及優化

nextcloud問題1:如果你在管理界面看到如下提示No memory cache has been configured. To enhance your performance please configure a memcache if available.答:需要我們安裝緩存了,如果你之前是按照我的

基於CentOS 7.2個人的實現

x86 nis nvi abort restart lease network wget risa 首先使用YUM安裝依賴環境:[root@sishen ~]#yum install python python-setuptools python-imaging pytho

分享一個開源下載工具BaiduPCS-Go

eid 下載工具 使用命令 遇到 功能 保存文件 命令的使用 語言 點擊 大家在使用網盤的時候,一定忍受不了限速下載的速度。今天給大家分享一個開源的網盤下載項目BaiduPCS-Go。Go語言編寫,仿 Linux shell 文件處理命令的百度網盤命令行客戶端。多平臺支持,

如何基於滴滴雲構建更私密的企業/個人空間Seafile

Seafile 介紹 Seafile 是一個開源的檔案雲端儲存平臺,解決檔案集中儲存、同步、多平臺訪問的問題,注重安全和效能。 Seafile 通過“資料庫”來分類管理檔案,每個資料庫可單獨同步,使用者可加密資料庫, 且密碼不會儲存在伺服器端,所以即使是伺服器管理員也無權訪問你的檔案

協作為王,企業VS個人

跟100個企業管理者提到企業網盤,其中99個都會產生這樣的疑問:企業網盤和個人網盤有哪些區別? 我們看到大量案例正在發生,很多正在使用個人網盤的團隊已經過渡至企業網盤產品,個人網盤已無法滿足日常的辦公需求。 企業網盤和個人網盤的基本功能都是儲存、共享,差異在於協作功能實現的細節上。下面,本文將重點介紹