owncloud私有云搭建

post thumb
OwnCloud
作者 Louis 发表于 2018年10月20日

owncloud的功能

  • 存储:图片,文档,视频,通讯录以及其他等等
  • 客户端支持:Android,IOS,MaxOS,Windows,Web,Linux
  • 分享:可以直接共享直接链接给授权过的同事
  • 在线看视频,文档,音乐。
  • 可以自行修改功能(作为开发者)

系统安装环境

CPU model            : Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz
Number of cores      : 2
CPU frequency        : 2500.028 MHz
Total amount of ram  : 16042 MB
Total amount of swap : 4096 MB
System uptime        : 0days, 0:7:13
Load average         : 0.00, 0.08, 0.06
OS                   : CentOS 7.5.1804
Arch                 : x86_64 (64 Bit)
Kernel               : 3.10.0-862.14.4.el7.x86_64
Hostname             : **********
IPv4 address         : **********

安装预览

nginx: nginx-1.15.5
nginx Location: /usr/local/nginx   /etc/nginx/

MariaDB: mariadb-10.2.18
MariaDB Location: /usr/local/mariadb
MariaDB Data Location: /data/mysql
MariaDB Root Password: *************

PHP: php-7.2.11
PHP Location: /usr/local/php
PHP Additional Modules:
redis.io
intl.so

mysql二进制安装

$ wget http://mirrors.aliyun.com/mariadb//mariadb-10.2.18/bintar-linux-glibc_214-x86_64/mariadb-10.2.18-linux-glibc_214-x86_64.tar.gz
$ tar xf mariadb-10.2.18-linux-glibc_214-x86_64.tar.gz -C /usrlocal/
$ mv  /usr/local/mariadb-10.2.15-linux-x86_64 /usr/local/mariadb
$ chown -R mysql:mysql /usr/local/mariadb  /data/mysql
$ /usr/local/mariadb/scripts/mysql_install_db --basedir=/usr/local/mariadb} --datadir=/data/mysql --user=mysql
$ vim /etc/my.conf
[mysql]

# CLIENT #
port                           = 3306
socket                         = /tmp/mysql.sock

[mysqld]
# GENERAL #
port                           = 3306
user                           = mysql
default-storage-engine         = InnoDB
socket                         = /tmp/mysql.sock
pid-file                       = /data/mysql/mysql.pid
skip-name-resolve
skip-external-locking

# INNODB #
innodb-log-files-in-group      = 2
innodb-log-file-size           = 256M
innodb-flush-log-at-trx-commit = 2
innodb-file-per-table          = 1
innodb-buffer-pool-size        = 2G

# CACHES AND LIMITS #
tmp-table-size                 = 32M
max-heap-table-size            = 32M
max-connections                = 4000
thread-cache-size              = 50
open-files-limit               = 4096
table-open-cache               = 1600

# SAFETY #
max-allowed-packet             = 16M
max-connect-errors             = 1000000

# DATA STORAGE #
datadir                        = /data/mysql

# LOGGING #
log-error                      = /data/mysql/mysql-error.log
log-bin			               = /data/mysql/mysql-bin
max_binlog_size			       = 1073741824
binlog-format		           = row

文件软连接及启动脚本
$ ln -s /usr/local/mariadb/bin/mysql /usr/bin/mysql
$ ln -s /usr/local/mariadb/bin/mysqldump /usr/bin/mysqldump
$ ln -s /usr/local/mariadb/bin/mysqladmin /usr/bin/mysqladmin
$ cp -f /usr/local/mariadb/support-files/mysql.server /etc/init.d/mysqld
$ sed -i "s:^basedir=.*:basedir=/usr/local/mariadb:g" /etc/init.d/mysqld
$ sed -i "s:^datadir=.*:datadir=/data/mysql:g" /etc/init.d/mysqld

创建owncloud用户

$ /etc/init.d/mysqld start
$ mysql -u root -p
MariaDB [(none)] > create database owncloud;
MariaDB [(none)] > GRANT ALL ON owncloud.* TO ocuser@localhost IDENTIFIED BY 'owncloud';
MariaDB [(none)] > flush privileges;
MariaDB [(none)] > exit

PHP编译安装

  1. 编译安装libconv
$ wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
$ tar -zxvf libiconv-1.15.tar.gz
$ cd libiconv-1.15
$ ./configure --prefix=/usr/local/libiconv
$ make
$ make install
$ libtool --finish /usr/local/libiconv/lib
  1. 编译安装php7.2.11
$ yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
$ wget http://101.96.10.64/cn2.php.net/distributions/php-7.2.11.tar.gz
$ tar xf  php-7.2.11.tar.gz && cd php-7.2.11
$ ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv=/usr/local/libiconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache
$ make -j 2 && make install   #2核编译。
$ cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
$ cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
$ cp php.ini-production /usr/local/php/etc/php.ini
$ cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
$ /etc/init.d/php-fpm start
  1. 编译安装redis.io,intl.io
#redis.io
$ wget http://pecl.php.net/get/redis-4.0.2.tgz
$ tar xf redis-4.0.2.tgz 
$ cd redis-4.0.2
$ find / -name php-config
$ ./configure --with-php-config=/usr/local/php/bin/php-config
$ make && make install
$ vim /usr/local/php/etc/php.ini
extentions=redis.io
extension = "redis.so"

#icu编译安装
$ mkdir /usr/local/icu
$ wget http://download.icu-project.org/files/icu4c/52.1/icu4c-52_1-src.tgz
$ tar xf icu4c-52_1-src.tgz
$ cd icu
$ ls
$ cd source/
$ ./configure --prefix=/usr/local/icu
$ make -j 2 && make install

#intl安装
$ cd /data/downloads/php-7.2.11/ext/intl
$ phpize 
$ ./configure  --enable-intl --with-icu-dir=/usr/local/icu/ --with-php-config=/usr/local/php/bin/php-config
$ make -j 2 && make install
$ cd /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/
$ vim /usr/local/php/etc/php.ini
extension = "intl.so"

nginx 编译安装及配置

编译安装

$ tar -zxvf nginx-1.15.5.tar.gz 
$ cd nginx-1.15.5
$ ./configure  --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx
$ useradd -s /sbin/nologin -g nginx -r nginx
$ make && make install

主配置配置文件编写

$ vim /etc/nginx.conf
#user  nobody;
worker_processes  8;

error_log  /var/log/nginx/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include	mime.types;
    server_tokens off;
    default_type  application/octet-stream;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    client_max_body_size 4m;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
    gzip on;
    gzip_min_length 10k;
    gzip_buffers 4 48k;
    gzip_http_version 1.0;
    gzip_comp_level 6;
    gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary off;
    gzip_disable "MSIE [1-6]\.";

    include /etc/nginx/conf.d/*.conf;
}

程序目录**

  • MariaDB 安装目录: /usr/local/mariadb
  • MariaDB 数据库目录:/data/mysql(默认,安装时可更改路径)
  • PHP 安装目录: /usr/local/php
  • Nginx 安装目录: /usr/local/nginx

命令一览

  • MySQL 或 MariaDB 或 Percona 命令
/etc/init.d/mysqld (start|stop|restart|status)
  • php命令
/etc/init.d/php-fpm (start|stop|restart|status)
  • nginx 命令
nginx -s reload
  • Redis 命令(可选安装)
/etc/init.d/redis-server (start|stop|restart|status)

网站根目录

默认的网站根目录: /data/www/default

安装owncloud

1.下载项目并解压

wget https://download.owncloud.org/community/owncloud-10.0.10.tar.bz2
tar xf owncloud-10.0.10.tar.bz2  && cd owncloud && rm -fr /data/www/default/* && cp -ar * /data/www/default 

2.修改项目端口

$ vim /etc/nginx/conf.d/owncloud-officer.conf
upstream php-handler {
    server 127.0.0.1:9000;
    # Depending on your used PHP version
    #server unix:/var/run/php5-fpm.sock;
    #server unix:/var/run/php7-fpm.sock;
}


server {
    listen 12312;
    server_name cloud.example.com;

    keepalive_timeout    70;

    # 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 /data/www/default/;

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

    # set max upload size
    client_max_body_size 512M;
    fastcgi_buffers 8 4K;                     # Please see note 1
    fastcgi_ignore_headers X-Accel-Buffering; # Please see note 2

    # Disable gzip to avoid the removal of the ETag header
    # Enabling gzip would also make your server vulnerable to BREACH
    # if no additional measures are done. See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=773332
    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 SCRIPT_NAME $fastcgi_script_name; # necessary for owncloud to detect the contextroot https://github.com/owncloud/core/blob/v10.0.0/lib/private/AppFramework/Http/Request.php#L603
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
        fastcgi_param front_controller_active true;
        fastcgi_read_timeout 180; # increase default timeout e.g. for long running carddav/ caldav syncs with 1000+ entries
        fastcgi_pass php-handler;
        fastcgi_intercept_errors on;
        fastcgi_request_buffering off; #Available since NGINX 1.7.11
    }

    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 "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=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|map)$ {
        add_header Cache-Control "public, max-age=7200";
        try_files $uri /index.php$uri$is_args$args;
        # Optional: Don't log access to other assets
        access_log off;
    }
}

服务器配置完成后,启动nginx,便可以在网页浏览器里面访问owncloud。输入ip和端口即可 一旦 URL 加载完毕,我们将呈现上述页面。这里,我们将创建管理员用户同时提供数据库信息。当所有信息提供完毕,点击“Finish setup”。 我们将被重定向到登录页面,在这里,我们需要输入先前创建的凭据: 一旦创建错误,可以删除/data/www/default/config.php文件,重新刷新页面,可以重新配置管理员。

这里提供我的一份配置

$ cat ~/owncloud/config.php
<?php
$CONFIG = array (
  'instanceid' => 'oc9wp89saij8',
  'passwordsalt' => '2k4ULPneBUz7kUvz3wOH7uNpYwWiGx',
  'secret' => '97FrWKoVBzNIb3uir89QEEEnKt7IwG4B+Q+Ye2HlYrtda3OZ',
  'trusted_domains' => 
  array (
    0 => 'ip:port',  #自己的ip和端口
  ),
  'datadirectory' => '/data/www/default/owncloud/data',
  'overwrite.cli.url' => 'http://ip:port', #自己的ip和端口
  'dbtype' => 'mysql',
  'version' => '10.0.10.4',
  'dbname' => 'owncloud',
  'dbhost' => 'localhost',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'ocuser',
  'dbpassword' => 'owncloud',
  'logtimezone' => 'UTC',
  'installed' => true,
  'files_external_allow_create_new_local' => 'true',
  'accounts.enable_medial_search' => true,
  'user.search_min_length' => 2,
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => 'localhost',
    'port' => 6379,
    'timeout' => 0.0,
    'password' => 'owncloud',
  ),
  'memcache.locking' => '\\OC\\Memcache\\Redis',
);

APACHE报错学习

1.如果你打开页面看到如下错误:

“PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.”这可能是由缓存/加速器造成的,例如 Zend OPcache 或 eAccelerator。打开你的打开php.ini文件,找到:[opcache],设置为:opcache.enable=0 和 opcache.enable_cli=0。

2.修改配置文件

vim /usr/local/php/etc/php.d/opcache.ini

[opcache]
zend_extension=/usr/local/php/ext/opcache.so
opcache.enable=0
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.save_comments=0
opcache.fast_shutdown=1
opcache.enable_cli=0
;opcache.optimization_level=0

3.输入命令重启php

Apache 命令

/etc/init.d/httpd (start|stop|restart|status)
上一篇
Health Foods