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 []:danteit@163.com                                                 

    

然后将证书文件的权限设置为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 

 

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

到此安装完成。

 


猜你喜欢

转载自blog.51cto.com/13945620/2389162