微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Centos7搭建owncloud私有云盘

一 . 部署环境的系统是Centos7版本

[root@owncloud ~]# cat /etc/redhat-release 
CentOS Linux release 7.1.1503 (Core)

二. 安装并配置NginxPHP-fpm

[root@owncloud ~]# yum -y install epel-release

[root@owncloud ~]# 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是否已正常安装

[root@owncloud ~]# 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/

    

启动NginxPHP-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 owncloud@localhost 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 []:dante[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虚拟主机

 

[root@owncloud ~]# 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服务

[root@owncloud ~]# Nginx -t
Nginx: the configuration file /etc/Nginx/Nginx.conf Syntax is ok
Nginx: configuration file /etc/Nginx/Nginx.conf test is successful

[root@owncloud ~]# systemctl restart Nginx

 

七. 安装owncloud

解析上面Nginx中配置的域名owncloud.danteit.com,邦定hosts. 访问http://owncloud.danteit.com进行owncloud界面安装.

图片1.png

 

 

设置帐号密码,以及数据库的连接信息。如果不报错,即可安装完成,进入。

到此安装完成。

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐