CentOS 7上安装搭建ownCloud 9.1.4私有云
介绍
OwnCloud 9.1.4是一种用于文件共享和数据同步的开源软件,在企业部门非常有用,你只需在服务器上安装好 ownCloud,即可通过网络访问和使用属于你自己的私有云了。
本教程是关于在CentOS 7上安装ownCloud,Nginx作为Web服务器。
安装 Nginx 和 PHP
首先,安装Nginx。 这个Web服务器在EPEL存储库中可用,所以只需添加它:
# yum install epel-release
接着:
# yum install nginx
接下来,使用webtatic存储库安装PHP-FPM(FastCGI Process Manager),并添加以下命令:
# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
现在可以使用ownCloud所需的其他软件包来安装PHP:
# yum install php70w-fpm php70w-cli php70w-json php70w-mcrypt php70w-pear php70w-mysql php70w-xml php70w-gd php70w-mbstring php70w-pdo
配置 Nginx的PHP-FPM
通过编辑php7-fpm配置文件完成PHP-FPM配置:
# $EDITOR /etc/php-fpm.d/www.conf
搜索包含“user”和“group”的那一行,并更改为:
user = nginx group = nginx
向下滚动,寻找“listen”行,并将内容更改为:
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
保存并退出。
现在,现在是使用以下命令在/var/lib /中创建一个新文件夹的时候了:
# mkdir -p /var/lib/php/session
将其所有者更改为nginx用户:
# chown nginx:nginx -R /var/lib/php/session/
启动nginx和PHP-FPM:
# sudo systemctl start php-fpm # sudo systemctl start nginx
添加到启动时启动(作为服务器的日常使用所需):
# systemctl enable nginx # systemctl enable php-fpm
安装 MariaDB
MariaDB在CentOS存储库中可用,因此请安装:
# yum install mariadb mariadb-server
配置MariaDB root密码:
# mysql_secure_installation
在此过程中,需要回答以下问题:
Set root password? [Y/n] New password: Re-enter new password: Remove anonymous users? [Y/n] Disallow root login remotely? [Y/n] Remove test database and access to it? [Y/n] Reload privilege tables now? [Y/n]
登录到MariaDB shell,为ownCloud创建一个新的数据库和用户。 在此示例中,my_owncloud_db是数据库名称,ocuser是其用户。 密码是:my_strong_password。
所以执行命令:
# mysql -u root -p
接着:
mysql> CREATE DATABASE my_owncloud_db; mysql> CREATE USER ocuser@localhost IDENTIFIED BY 'my_strong_password'; mysql> GRANT ALL PRIVILEGES ON my_owncloud_db.* to ocuser@localhost IDENTIFIED BY 'my_strong_passowrd'; mysql> FLUSH PRIVILEGES;
生成SSL证书
如果不存在,请为SSL文件创建一个新目录:
# mkdir -p /etc/nginx/cert/
接下来,生成一个新的SSL证书文件:
# openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/owncloud.crt -keyout /etc/nginx/cert/owncloud.key
使用以下命令更改权限:
# chmod 600 /etc/nginx/cert/*
现在 ownCloud
现在 ownCloud:
# wget https://download.owncloud.org/community/owncloud-9.1.4.zip
提取存档并将其移动到/usr/share/nginx/html/
:
# unzip owncloud-9.1.2.zip # mv owncloud/ /usr/share/nginx/html/
转到Nginx根目录; 在那里,为ownCloud创建一个新的数据目录:
# cd /usr/share/nginx/html/ # mkdir -p owncloud/data/
在Nginx中配置虚拟主机
使用以下命令创建虚拟主机配置文件:
# $EDITOR /etc/nginx/conf.d/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 storage.example.com; 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 -t
This should display a “Syntax OK” message.
重启Nginx:
# systemctl restart nginx
总结
服务器端配置完成。最后一件事是使用Web浏览器转到您自己的Cloud服务器URL(本示例中为storage.example.com),并使用图形前端完成配置。通过创建新的管理员帐户,并输入在前面的步骤中创建的数据库凭据来执行此操作。您的云端存储服务现在已准备好用于日常使用!