天天看點

Centos7搭建owncloud私有雲盤二. 安裝并配置Nginx和php-fpm三. 安裝并配置MariaDB 或 mysql四. 配置owncloud生成自簽名SSL證書五. 下載下傳并安裝owncloud六. 配置Nginx虛拟主機七. 安裝owncloud

[[email protected] ~]# cat /etc/redhat-release 

CentOS Linux release 7.1.1503 (Core)

二. 安裝并配置Nginx和php-fpm

[[email protected] ~]# yum -y install epel-release

[[email protected] ~]# yum -y install nginx

添加一個yum源來安裝php-fpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安裝相關元件

yum -y install php72w-fpm php72w-cli php72w-gd php72w-mcrypt php72w-mysql php72w-pear php72w-xml php72w-mbstring php72w-pdo php72w-json php72w-pecl-apcu php72w-pecl-apcu-devel

完成後,檢查一下php-fpm是否已正常安裝

[[email protected] ~]# php -v

PHP 7.2.16 (cli) (built: Mar 10 2019 21:22:49) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies配置php-fpm

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

.....

user = nginx                          //将使用者群組都改為nginx

group = nginx

.....

listen = 127.0.0.1:9000                            //php-fpm所監聽的端口為9000

......

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/

啟動Nginx和php-fpm服務,并添加開機啟動

systemctl start php-fpm

systemctl start nginx

systemctl enable php-fpm

systemctl enable nginx

三. 安裝并配置MariaDB 或 mysql

使用MaraiDB作為owncloud資料庫。yum安裝MaraiDB服務

yum -y install mariadb mariadb-server

啟動MariaDB服務并添加開機啟動

systemctl start mariadb

systemctl enable mariadb

注意: 確定本地登陸資料庫的相關帳号及權限都OK。

Mysql需要設定為mixed模式:

set global binlog_format=mixed;

資料庫初始化設定。包括設定root使用者密碼,權限等。

mysql_secure_installatio

······

Set root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y

 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y

 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] y

 - Dropping test database...

 ... Success!

 - Removing privileges on test database...

 ... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

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!

資料庫預設無密碼,根據實際情況确認參數設定

下面建立資料庫:

Mysql -uroot -p

MariaDB [(none)]> create database owncloud          

MariaDB [(none)]> grant all privileges on owncloud.* to [email protected] identified by '123456';

MariaDB [(none)]> flush privileges;

四. 配置owncloud生成自簽名SSL證書

先為SSL證書建立一個新的檔案夾:

cd /etc/nginx/cert/

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

.....

Country Name (2 letter code) [XX]:cn                           //國家

State or Province Name (full name) []:sichuan                      //省份

Locality Name (eg, city) [Default City]:chengdu                      //地區名字

Organization Name (eg, company) [Default Company Ltd]:lxplwh                    //公司名

Organizational Unit Name (eg, section) []:Technology                    //部門

Common Name (eg, your name or your server's hostname) []:danteit                //CA主機名

Email Address []:[email protected]                                                 

然後将證書檔案的權限設定為660

chmod 700 /etc/nginx/cert

chmod 600 /etc/nginx/cert/*

五. 下載下傳并安裝owncloud

wget https://download.owncloud.org/community/owncloud-10.1.1.zip

unzip owncloud-10.1.1.zi

mv owncloud /usr/share/nginx/html/

并為owncloud建立data目錄,将owncloud的使用者群組修改為nginx

mkdir -p owncloud/data/

chown nginx:nginx -R owncloud/

六. 配置Nginx虛拟主機

[[email protected] ~]# vim /etc/nginx/nginx.conf

#user nobody;

worker_processes 1;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

upstream php-handler {

server 127.0.0.1:9000;

}

server {

listen 80;

server_name owncloud.danteit.com;

return 301 https://$server_name$request_uri;

}

server {

listen 443 ssl;

server_name owncloud.danteit.com;

ssl_certificate /etc/nginx/cert/owncloud.crt;

ssl_certificate_key /etc/nginx/cert/owncloud.key;

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;

root /usr/share/nginx/html/owncloud/;

location = /robots.txt {

allow all;

log_not_found off;

access_log off;

}

location = /.well-known/carddav {

return 301 $scheme://$host/remote.php/dav;

}

location = /.well-known/caldav {

return 301 $scheme://$host/remote.php/dav;

}

client_max_body_size 512M;

fastcgi_buffers 64 4K;

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

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;

}

location ~* \.(?:css|js)$ {

try_files $uri /index.php$uri$is_args$args;

add_header Cache-Control "public, max-age=7200";

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;

access_log off;

}

location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {

try_files $uri /index.php$uri$is_args$args;

access_log off;

}

}

確定沒有問題後重新開機Nginx服務

[[email protected] ~]# nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

[[email protected] ~]# systemctl restart nginx

七. 安裝owncloud

解析上面nginx中配置的域名owncloud.danteit.com,邦定hosts. 通路http://owncloud.danteit.com進行owncloud界面安裝.

Centos7搭建owncloud私有雲盤二. 安裝并配置Nginx和php-fpm三. 安裝并配置MariaDB 或 mysql四. 配置owncloud生成自簽名SSL證書五. 下載下傳并安裝owncloud六. 配置Nginx虛拟主機七. 安裝owncloud

設定帳号密碼,以及資料庫的連接配接資訊。如果不報錯,即可安裝完成,進入。

到此安裝完成。

繼續閱讀