方案前文:創建一個家庭私有云盤方案系列教程+N2n+Nextcloudjavascript
前一篇:家庭私有云盤系列教程-創建公網服務器實現外網訪問php
在安裝NextCloud以前,咱們須要將物理硬盤掛載到linux上,供使Nextcloud存儲數據。若是是物理機是linux,會更方便一些。css
新硬盤直接進行分區掛載就行,這裏對已經在window上分區過,甚至已經有文件的物理硬盤進行掛載說明。html
查看硬盤號順序。java
使用cmd運行命令> Diskpartmysql
接着輸入 List disklinux
如圖所示,若是咱們掛載第一塊硬盤,便是磁盤0。nginx
這裏的狀態是脫機的,若是是聯機的,須要將其更改成脫機,只容許一個系統將其掛載讀寫,那便是nas-linux。web
更改硬盤爲脫機狀態後,windows物理機將沒法訪問到磁盤。ajax
這裏示例更改方法,恢復同樣,右鍵將其更改成 聯機 便可。須要在centos上將其卸載掉,不然會產生衝突。
虛擬機右鍵設置
選擇第三個,使用物理磁盤。
這裏的設備便是剛纔cmd列出來的順序,莫要搞錯。並且必定要是脫機狀態,不然這裏會報佔用錯誤。
單選項,1.使用整塊硬盤,2.使用單個分區。選擇第二項,單個分區。
勾選本身的分區,若是隻有一個分區,那就勾選一個,而後繼續下一步。
完成後,單擊OK保存退出。
查看磁盤狀況
fdisk -l
由此看到,咱們這塊硬盤有兩塊硬盤,一塊128M的小分區(Microsoft Reserved Partition),剩下的纔是咱們的主要數據分區。這是由於咱們是在windows上使用GPT模式分區硬盤產生的。
這裏也看不清具體的分區格式,須要使用parted -l 查看,遇到提示,輸入OK回車便可。
這裏能夠清楚地看到兩個分區,第一個是沒有文件系統類別的,而第二個是ntfs。咱們只須要掛載第二個便可,第一個掛載不上去。
編號1即 /dev/sda1
編號2即 /dev/sda2
折騰了半夜,沒有將ntfs-3g編譯安裝成功,最終放棄,選擇了yum方式安裝。簡單幹脆。
#增長阿里雲epel源 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo #安裝 yum install -y ntfs-3g
mount -t ntfs -o iocharset=cp936 /dev/sda2 /mnt/hd1
爲避免windows上文件名亂碼,這裏指定磁盤字符,-o iocharset=cp936
注意:cp936是指簡體中文,cp950是指繁體中文。
umount /dev/sda2
vi /etc/fstab
#追加內容 /dev/sda2 /mnt/hd1 ntfs defaults,iocharset=cp936,rw 0 0
除此以外,自動掛載能夠經過開機啓動腳本實現。
在 /etc/rc.d/rc.local 文件尾部增長掛載分區mount命令便可。
安裝部署環境,PHP、Mariadb、Nginx
yum install -y libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel mkdir /usr/local/php/ cd /usr/local/php/ wget http://cn2.php.net/distributions/php-7.2.2.tar.gz -O php-7.2.2.tar.gz tar -xzf php-7.2.2.tar.gz -C ./ cd php-7.2.2 ./configure --prefix=/usr/local/php/php7.2.2/\ --with-config-file-path=/usr/local/php/php7.2.2/\ --with-libdir=lib64\ --enable-fpm\ --with-fpm-user=php-fpm\ --with-fpm-group=www\ --enable-mysqlnd\ --with-mysql=mysqlnd\ --with-mysqli=mysqlnd\ --with-pdo-mysql=mysqlnd\ --enable-opcache\ --enable-pcntl\ --enable-mbstring\ --enable-soap\ --enable-zip\ --enable-calendar\ --enable-bcmath\ --enable-exif\ --enable-ftp\ --enable-intl\ --with-openssl\ --with-zlib\ --with-curl\ --with-gd\ --with-zlib-dir=/usr/lib\ --with-png-dir=/usr/lib\ --with-jpeg-dir=/usr/lib\ --with-gettext\ --with-mhash\ --with-ldap make && make install
建立配置文件
cd /usr/local/php/php-7.2.2/ cp php.ini-development /usr/local/php/php7.2.2/php.ini cp /usr/local/php/php7.2.2/etc/php-fpm.conf.default /usr/local/php/php7.2.2/etc/php-fpm.conf #複製php-fpm管理器腳本 cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm vi /usr/local/php/php7.2.2/php.ini #修改 cgi.fix_pathinfo=0 cd /usr/local/php/php7.2.2/etc/php-fpm.d cp www.conf.default www.conf
關閉selinux
vi /etc/selinux/config #將SELINUX=enforcing改成SELINUX=disabled,保存後退出 SELINUX=disabled #執行生效 getenforce
經過php-fpm腳本,啓動php服務(中止、重啓、重載)。
service php-fpm start service php-fpm restart service php-fpm stop service php-fpm reload
建立網站目錄
#建立網站目錄及網站產生的日誌存放目錄 mkdir /mnt/web/cloud/wwwroot -p mkdir /mnt/web/cloud/log -p #建立nginx加載的虛擬主機配置存放目錄 mkdir /usr/local/nginx/vhost #建立默認文件 echo "<?php phpinfo();?>" > /mnt/web/cloud/wwwroot/index.php echo "hi example.com" > /mnt/web/cloud/wwwroot/index.html #設置權限 chown -R php-fpm:www /mnt/web chmod -R 775 /mnt/web
此前nginx已經安裝了, 這裏只須要配置下便可。
vi /usr/local/nginx/nginx.conf
在 http 段尾部增長
include /usr/local/nginx/vhost/*.conf;
新增一個虛擬主機配置
vi /usr/local/nginx/vhost/cloud.conf
如下內容摘自官方文檔部門,爲HTTP訪問。爲避免HTTPS測試麻煩,若是後期須要部署HTTPS,參照官方配置便可。另外,配置HTTPS須要在公網入口配置,這臺機器能夠保持當前配置。
查看官方Nginx部署配置,點擊這裏。
upstream php-handler { server 127.0.0.1:9000; #server unix:/var/run/php5-fpm.sock; } log_format cloud.log.format '$remote_addr - $remote_user [$time_local] $request' '$status $body_bytes_sent $http_referer ' '$http_user_agent $http_x_forwarded_for'; server { listen 80; server_name cloud.cn.n2n.ee; index index.html index.htm index.php; root /mnt/web/cloud/wwwroot; # 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;"; # # WARNING: Only add the preload option once you read about # the consequences in https://hstspreload.org/. This option # will add the domain to a hardcoded list that is shipped # in all major browsers and getting removed from this list # could take several months. add_header X-Content-Type-Options nosniff; 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; 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 512M; fastcgi_buffers 64 4K; # Enable gzip but do not remove ETag headers 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; 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/.+)\.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; #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|woff|svg|gif)$ { try_files $uri /index.php$uri$is_args$args; add_header Cache-Control "public, max-age=15778463"; # 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;"; # # WARNING: Only add the preload option once you read about # the consequences in https://hstspreload.org/. This option # will add the domain to a hardcoded list that is shipped # in all major browsers and getting removed from this list # could take several months. add_header X-Content-Type-Options nosniff; 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 ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ { try_files $uri /index.php$uri$is_args$args; # Optional: Don't log access to other assets access_log off; } access_log /mnt/web/cloud/log/access.log cloud.log.format; error_log /mnt/web/cloud/log/error.log; }
運行nginx
/usr/local/nginx/nginx
嘗試訪問,http://公網IP:10252/index.php,成功便可!
避免麻煩,直接使用yum安裝,並啓動設置自動運行。
yum -y install mariadb mariadb-server systemctl start mariadb systemctl enable mariadb
初始化數據庫
>mysql_secure_installation Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! Remove anonymous users? [Y/n] y ... Success! Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
開放root遠程權限,方便操做,不須要的能夠忽略。
mysql -u root -p MariaDB [mysql]> update mysql.user set host='%' where user='root' and host='localhost'; MariaDB [mysql]> flush privileges;
爲NextCloud建立一個用戶名及所屬數據庫。
CREATE DATABASE IF NOT EXISTS db_cloud DEFAULT CHARSET utf8 COLLATE utf8_bin; CREATE USER 'user_cloud'@'%' IDENTIFIED BY 'vuu01z4ztsdl0rmu'; GRANT SELECT, INSERT, UPDATE, REFERENCES, DELETE, CREATE, DROP, ALTER, INDEX, TRIGGER, CREATE VIEW, SHOW VIEW, EXECUTE, ALTER ROUTINE, CREATE ROUTINE, CREATE TEMPORARY TABLES, LOCK TABLES, EVENT ON `db\_cloud`.* TO 'user_cloud'@'%'; GRANT GRANT OPTION ON `db\_cloud`.* TO 'user_cloud'@'%';
獲取最新 nextcloud
https://download.nextcloud.com/server/releases/
下載並解壓到網站目錄
cd /mnt/web/cloud/wwwroot/ wget https://download.nextcloud.com/server/releases/nextcloud-13.0.0.tar.bz2 tar -xjf nextcloud-13.0.0.tar.bz2 rm -f index.html rm -f index.php mv nextcloud/* ./ rm -rf nextcloud chown -R php-fpm:www /mnt/web chmod -R 775 /mnt/web
至此,nextcloud基本就能使用了,至於後臺的提醒錯誤,能夠參照錯誤後面的連接去解決。
nextcloud項目的優化配置也能夠參照官方的文檔。
做爲一個擴展插件,能夠在後臺應用中 搜索 External storage support,而後啓用便可。
目錄名稱便是在文件管理界面展現的目錄名,配置便是linux的目錄路徑,設置完畢後,保存便可。
另外設置下目錄的權限,就能夠正常使用了。
chown -R php-fpm:www /mnt/hd1 chmod -R 775 /mnt/hd1
(完)