银天科技设计出品
扫描关注银天科技微信公众账号

广州网站建设

广州网站建设提醒你:想拥有自己的私有云吗?

银天科技2018-03-16站长实战

有没有发现我们的iCloud已经转回中国公司代理?有没有发现我们的iCloud空间只有寥寥5G空间?如果我你不想用其他平台的云空间,那么下面这篇文章很适合你。

接下来广州网站建设为你分享Linux下搭建自己的私有云。

一、安装几个环境。命令如下:

①yum -y install epel-release && rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm && yum -y update

②yum -y install nginx mariadb-server redis lbzip2 php71w-common php71w-fpm php71w-gd php71w-mysql php71w-mbstring php71w-intl php71w-mcrypt php71w-pecl-imagick php71w-xml php71w-pecl-redis samba-client

二、下载和安装owncloud

curl -O https://download.owncloud.org/community/owncloud-10.0.3.tar.bz2 && tar -xf ./owncloud-10.0.3.tar.bz2 && rm -rf ./owncloud-10.0.3.tar.bz2 && mv owncloud /usr/share/nginx/ && chown -R nginx:nginx /usr/share/nginx/owncloud && find /usr/share/nginx/owncloud -type d -exec chmod 755 {} \; && find /usr/share/nginx/owncloud -type f -exec chmod 644 {} \;

三、建立owncloud目录

mkdir /var/lib/owncloud && chown nginx:nginx /var/lib/owncloud

四、配置数据库

①启动服务

systemctl start mariadb

②初始化设置

mysql_secure_installation

注意下图这个地方默认是没有密码的直接回车跳过

这里是设置密码,为了更加安全肯定要设置密码

其他的全部y 直接完成即可。

五、为owncloud创建数据库

①进入数据库

mysql -u root -p

Enter password: #输入密码按回车

②创建用户

CREATE USER 'owncloud'@'localhost' IDENTIFIED BY 'owncloud';

③建立owncloud数据库

CREATE DATABASE owncloud;

④授予读写权限

GRANT ALL PRIVILEGES ON owncloud.* TO 'owncloud'@'localhost' IDENTIFIED BY 'owncloud';

⑤刷新一下权限

FLUSH PRIVILEGES;

配置完了之后输入exit退出。

六、配置Nginx

①创建owncloud配置文件

vi /etc/nginx/conf.d/owncloud.conf

②按i编辑,复制代码如下:

upstream php-handler {

server unix:/run/php-fpm/owncloud.sock;

}

server {

listen 80;

server_name cloud.example.com; # cloud.gzytsoft.com 改为您的域名

location /.well-known/acme-challenge/ {

root /usr/share/nginx/owncloud;

}

location / {

return 301 https://$server_name$request_uri;

}

}

server {

listen 443 ssl http2;

server_name cloud.example.com; # cloud.gzytsoft.com 改为您的域名

ssl_certificate /etc/pki/tls/owncloud.pem; # 域名证书文件位置,需要修改

ssl_certificate_key /etc/pki/tls/private/owncloud_key.pem; # 域名证书私钥文件位置,需要修改

ssl_session_timeout 5m;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

ssl_ciphers "-ALL:EECDH+AES256:EDH+AES256:AES256-SHA:EECDH+AES:EDH+AES:!ADH:!NULL:!aNULL:!eNULL:!EXPORT:!LOW:!MD5:!3DES:!PSK:!SRP:!DSS:!AESGCM:!RC4";

ssl_dhparam /etc/pki/tls/certs/dh4096.pem;

ssl_prefer_server_ciphers on;

keepalive_timeout 70;

ssl_stapling on;

ssl_stapling_verify on;

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;

root /usr/share/nginx/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 16G;

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)/ {

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;

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_param HTTPS on;

fastcgi_param modHeadersAvailable true;

fastcgi_param front_controller_active true;

fastcgi_read_timeout 180;

fastcgi_pass php-handler;

fastcgi_intercept_errors on;

fastcgi_request_buffering off;

}

location ~ ^/(?:updater|ocs-provider)(?:$|/) {

try_files $uri $uri/ =404;

index index.php;

}

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

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

add_header Cache-Control "max-age=15778463";

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|map)$ {

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

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

access_log off;

}

}

按ESC 然后wq退出。

我没安装中文字体所以看不到中文不好意思

③生成Nginx需要的DH文件

openssl dhparam -out /etc/pki/tls/certs/dh4096.pem 4096

七、PHP-FPM的配置

①vi /etc/php-fpm.d/owncloud.conf

代码如下,编辑保存方法同上。

[owncloud]

user = nginx

group = nginx

listen = /run/php-fpm/owncloud.sock

listen.owner = nginx

listen.group = nginx

listen.mode = 0600

pm = dynamic

pm.max_children = 50

pm.start_servers = 5

pm.min_spare_servers = 5

pm.max_spare_servers = 35

slowlog = /var/log/php-fpm/owncloud-slow.log

php_admin_value[error_log] = /var/log/php-fpm/owncloud-error.log

php_admin_flag[log_errors] = on

php_value[memory_limit] = 512M

php_value[session.save_handler] = files

php_value[session.save_path] = /var/lib/php/session

php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache

php_value[upload_max_filesize] = 16G

php_value[post_max_size] = 16G

php_value[max_input_time] = 3600

php_value[max_execution_time] = 3600

php_value[date.timezone] = Asia/Shanghai

env[HOSTNAME] = $HOSTNAME

env[PATH] = /usr/local/bin:/usr/bin:/bin

env[TMP] = /tmp

env[TMPDIR] = /tmp

env[TEMP] = /tmp

②建立PHP通讯目录

mkdir -p /var/lib/php/session && chown -R nginx:nginx /var/lib/php/session

八、启动服务并加入开机启动

systemctl start nginx php-fpm redis

systemctl enable nginx php-fpm mariadb redis

九、配置owncloud

访问域名,出现图形化界面,填写账号、密码、数据库资料等等。那就OK了。

当你看到这么友好的界面是不是有点小激动呢?赶紧动手试试吧。喜欢小编记得点下小关注哦。

文章关键词