如何部署CentOS 8.x nextCloud?

Cloud storage

1 理论基础

1.1 项目简介

Nextcloud是一款开源免费的私有云存储网盘项目,可以让你快速便捷地搭建一套属于自己或团队的云同步网盘,从而实现跨平台跨设备文件同步、共享、版本控制、团队协作等功能。它的客户端覆盖了Windows、Mac、Android、iOS、Linux 等各种平台,也提供了网页端以及 WebDAV接口,所以你几乎可以在各种设备上方便地访问你的云盘。

1.2 服务器端环境

2 最佳实践

2.1 运行环境

2.1.1 运行环境信息

ipaddress = 10.168.0.80
OS = CentOS 8.2 x86_64

2.1.2 LAMP环境搭建

Apache+PHP(编译安装)

如何编译安装Apache+PHP7.4.3?


MariaDB安装

如何基于CentOS 8.x安装MariaDB?

2.2 安装前的准备

2.2.1 修改目录访问权限

vim /etc/httpd/httpd.conf

修改如下行:

<Directory />
    AllowOverride none
    #Require all denied
</Directory>

另外,也可以使用以下命令配置,

sed -i '/AllowOverride none/{:a;n;s/Require all denied/\#Require all denied/g;}' /etc/httpd/httpd.conf

重启服务使配置生效

systemctl restart httpd.service

2.2.2 下载源码包

cd ~
wget https://download.nextcloud.com/server/releases/nextcloud-20.0.1.tar.bz2

2.2.3 解压源码包

cd ~
tar -xf nextcloud-20.0.1.tar.bz2

2.2.4 安装编译所需的软件包

dnf install -y autoconf

2.3 部署nextcloud

2.3.1 配置源码包

cd ~
mv nextcloud /var/www/
chown -R apache:apache /var/www/nextcloud
chmod -R 755 /var/www/nextcloud

2.3.2 配置apache

vim /etc/httpd/conf.d/nextcloud.conf

配置如下:

<VirtualHost *:80>
  DocumentRoot /var/www/nextcloud/
  ServerName  nextcloud.cmdschool.org

  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^nextcloud\.com\.org$
  RewriteRule ^/?(.*)$ https://nextcloud.cmdschool.org/$1 [L,R]
</VirtualHost>

<VirtualHost *:443>
  DocumentRoot /var/www/nextcloud/
  ServerName  nextcloud.cmdschool.org

  SSLEngine on
  SSLProtocol all -SSLv2
  SSLCipherSuite DEFAULT:!EXP:!SSLv2:!DES:!IDEA:!SEED:+3DES
  SSLCertificateFile /etc/httpd/2_nextcloud.cmdschool.org.crt
  SSLCertificateKeyFile /etc/httpd/3_nextcloud.cmdschool.org.key
  SSLCertificateChainFile /etc/httpd/1_root_bundle.crt

  Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"
</VirtualHost>

<Directory /var/www/nextcloud/>
  Require all granted
  AllowOverride All
  Options FollowSymLinks MultiViews

  <IfModule mod_dav.c>
    Dav off
  </IfModule>
</Directory>

根据以上配置,你需要使用以下命令开启重写功能,

sed -i "s/\#LoadModule rewrite\_module modules\/mod\_rewrite\.so/LoadModule rewrite\_module modules\/mod\_rewrite.so/g" /etc/httpd/httpd.conf

另外,你还需要准备以下Apache SSL所需的证书,
如果没有证书,请从腾讯云申请免费证书,
https://cloud.tencent.com/product/ssl
注:以上申请后使用Apache证书即可并保存到目录“/etc/httpd/”
然后,我们建议你使用如下命令检查当前的配置是否有语法错误,

httpd -t

2.3.3 重启Apache服务

systemctl restart httpd.service

2.4 安装所需的模块

2.4.1 获取需要的模块

通过访问连接的方式获取欠缺的模块信息,详细请参考下图,
https://nextcloud.cmdschool.org

另外,临时性的名称解析你可以按下键盘的【Win+R】键,然后输入如下命令,

notepad \Windows\System32\drivers\etc\hosts

然后加入如下配置,

10.168.0.80 nextcloud.cmdschool.org

2.4.2 编译安装模块zip

cd ~/php-7.4.3/ext/zip
phpize
./configure
make
make install

如果你遇到以下错误提示,

configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:

可按照如下方法解决依赖关系,

dnf install -y libzip-devel

2.4.3 编译安装模块mbstring

cd ~/php-7.4.3/ext/mbstring
phpize
./configure
make
make install

如果你遇到以下错误提示,

configure: error: Package requirements (oniguruma) were not met:

可按照如下方法解决依赖关系,

如何编译安装oniguruma?

2.4.4 编译安装模块gd

cd ~/php-7.4.3/ext/gd/
phpize
./configure \
	--enable-shared \
	--disable-static \
	--enable-gd \
	--with-external-gd \
	--with-webp \
	--with-jpeg \
	--with-xpm \
	--with-freetype \
	--with-gnu-ld
make
make install

如果你遇到以下错误提示,

configure: error: Package requirements (gdlib >= 2.1.0) were not met:

可按照如下方法解决依赖关系,

dnf install -y gd-devel

如果你遇到以下错误提示,

configure: error: Package requirements (libpng) were not met:

可按照如下方法解决依赖关系,

dnf install -y libpng-devel

如果你遇到以下错误提示,

configure: error: Package requirements (libjpeg) were not met:

可按照如下方法解决依赖关系,

dnf install -y libjpeg-turbo-devel

如果你遇到以下错误提示,

configure: error: Package requirements (libwebp) were not met:

可按照如下方法解决依赖关系,

dnf install -y libwebp-devel

如果你遇到以下错误提示,

configure: error: Package requirements (libpng) were not met:

可按照如下方法解决依赖关系,

dnf install -y libpng-devel

2.4.5 编译安装模块zlib

cd ~/php-7.4.3/ext/zlib
cp config0.m4 config.m4
phpize
./configure
make
make install

2.4.6 编译安装模块curl

cd ~/php-7.4.3/ext/curl
phpize
./configure
make
make install

如果你遇到以下错误提示,

configure: error: Package requirements (libcurl >= 7.15.5) were not met:

可按照如下方法解决依赖关系,

 dnf install -y libcurl-devel

2.4.7 编译安装模块openssl

cd ~/php-7.4.3/ext/openssl/
cp config0.m4 config.m4
phpize
./configure
make
make install

2.4.8 编译安装模块ldap(可选)

cd ~/php-7.4.3/ext/ldap/
phpize
./configure
make
make install

如果你遇到以下错误提示,

configure: error: Cannot find ldap.h

可按照如下方法解决依赖关系,

dnf install -y openldap-devel

如果你遇到以下错误提示,

configure: error: Cannot find ldap libraries in /usr/lib.

可按照如下方法解决依赖关系,

ln -s /usr/lib64/libldap.so /usr/lib/

2.4.9 编译安装模块intl(可选)

cd ~/php-7.4.3/ext/intl/
phpize
./configure
make
make install

如果你遇到以下错误提示,

configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:

可按照如下方法解决依赖关系,

dnf install -y libicu-devel

2.4.10 编译安装模块pcntl(可选)

cd ~/php-7.4.3/ext/pcntl/
phpize
./configure
make
make install

2.4.11 编译安装模块bcmath(可选)

cd ~/php-7.4.3/ext/bcmath/
cp config0.m4 config.m4
phpize
./configure
make
make install

2.4.12 编译安装模块gmp(可选)

cd ~/php-7.4.3/ext/gmp/
phpize
./configure
make
make install

如果你遇到以下错误提示,

configure: error: GNU MP Library version 4.2 or greater required.

可按照如下方法解决依赖关系,

dnf install -y gmp-devel

2.4.13 编译安装模块imagick(可选)

cd ~
wget https://pecl.php.net/get/imagick-3.4.3.tgz
tar -xf imagick-3.4.3.tgz
cd ~/imagick-3.4.3/
phpize
./configure
make
make install

如果你遇到以下错误提示,

configure: error: not found. Please provide a path to MagickWand-config or Wand-config program.

可按照如下方法解决依赖关系,

dnf install -y epel-release
dnf config-manager --set-enabled PowerTools
dnf install -y ImageMagick-devel

2.4.14 编译安装模块opcache(可选)

cd ~/php-7.4.3/ext/opcache/
phpize
./configure
make
make install

另外,如果使用该模块,你需要修改如下参数,

vim /etc/php.ini

详细的参数如下,

opcache.enable=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1

另外,你也可以使用如下快速命令设置,

sed -i "s/;opcache.enable=1/opcache.enable=1/g" /etc/php.ini
sed -i "s/;opcache.memory_consumption=128/opcache.memory_consumption=128/g" /etc/php.ini
sed -i "s/;opcache.interned_strings_buffer=8/opcache.interned_strings_buffer=8/g" /etc/php.ini
sed -i "s/;opcache.max_accelerated_files=10000/opcache.max_accelerated_files=10000/g" /etc/php.ini
sed -i "s/;opcache.save_comments=1/opcache.save_comments=1/g" /etc/php.ini
sed -i "s/;opcache.revalidate_freq=2/opcache.revalidate_freq=1/g" /etc/php.ini

2.4.15 编译安装模块exif(可选)

cd ~/php-7.4.3/ext/exif/
phpize
phpize
./configure
make
make install

2.4.16 编译安装模块ftp(可选)

cd ~/php-7.4.3/ext/ftp/
phpize
./configure
make
make install

2.4.17 编译安装模块smbclient(可选)

cd ~
wget https://pecl.php.net/get/smbclient-1.0.6.tgz
tar -xf smbclient-1.0.6.tgz
cd ~/smbclient-1.0.6/
phpize
./configure
make
make install

2.4.18 动态加载模块

echo 'extension=zip.so' >> /etc/php.ini
echo 'extension=mbstring.so' >> /etc/php.ini
echo 'extension=gd.so' >> /etc/php.ini
echo 'extension=zlib.so' >> /etc/php.ini
echo 'extension=curl.so' >> /etc/php.ini
echo 'extension=openssl.so' >> /etc/php.ini
echo 'extension=ldap.so' >> /etc/php.ini
echo 'extension=intl.so' >> /etc/php.ini
echo 'extension=pcntl.so' >> /etc/php.ini
echo 'extension=bcmath.so' >> /etc/php.ini
echo 'extension=gmp.so' >> /etc/php.ini
echo 'extension=imagick.so' >> /etc/php.ini
echo 'zend_extension=opcache.so' >> /etc/php.ini
echo 'extension=exif.so' >> /etc/php.ini
echo 'extension=ftp.so' >> /etc/php.ini
echo 'extension=smbclient.so' >> /etc/php.ini

2.4.17 优化相关参数

vim /etc/php.ini

修改如下参数,

memory_limit = 512M
post_max_size = 1024M
upload_max_filesize = 1024M
date.timezone = Asia/Shanghai

另外,也可使用以下快速命令处理,

sed -i "s/memory_limit = 128M/memory_limit = 512M/g" /etc/php.ini
sed -i "s/post_max_size = 8M/post_max_size = 1024M/g" /etc/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 1024M/g" /etc/php.ini

2.4.18 重启服务使配置生效

systemctl restart httpd.service

2.5 配置数据库连接

2.5.1 创建数据库

mysql -uroot -p

输入如下配置:

create database if not exists nextcloud;
grant all privileges on nextcloud.* TO 'nextcloud'@'localhost' IDENTIFIED BY 'nextcloudpwd';
flush privileges;

2.5.1 连接数据库

通过访问连接可发现所有模块安装好后即可进行数据库连接等操作,详细请参考下图,
https://nextcloud.cmdschool.org

注:
– 如果无法连接请将“localhost”改为“127.0.0.1”
– 界面操作不再详述,请自行摸索

2.6 启用nextCloud的缓存加速

如何配置nextcloud集成redis与apcu?

参阅文档:
==============
https://docs.nextcloud.com/

没有评论

发表评论

Cloud storage
如何解决NextCloud no app in context警告?

1 前言 一个问题,一篇文章,一出故事。 笔者今天NextCloud配置2FA登录异常,2FA可见如 …

Cloud storage
如何解决NextCloud CSRF check failed?

1 前言 一个问题,一篇文章,一出故事。 用户访问一个分享的链接并输入校验密码, https://n …

Cloud storage
如何配置NextCloud首次登录文件?

1 前言 一个问题,一篇文章,一出故事。 笔者生产环境有一个云盘NextCloud,详细请参阅以下章 …