NextCloud 私有云网盘搭建

NextCloud私有网盘部署

1、NextCloud简介

  • 关于NextCloud

    NextCloud是一个开源的私有云盘存储项目,可以快速的搭建一套属于自己的网盘平台。也可以给自己的团队使用。除了网盘以外,还提供各种插件的扩展功能,上传下载速度取决于你服务器的带宽。比某盘高到不知道哪里去了

  • 关于环境

    需要服务器提供LNMP或者LAMP环境。安装方法的话,可以把NextCloud简单理解为一个别人写好的网站。我们只需要放在服务器上即可。

  • 关于离线下载

    网盘基本上都有离线下载功能,NextCloud的离线下载用的是Aria2。

2、NextCloud部署配置

2.1 LAMP的搭建

这个地方可以自己手动搭建也可以使用一些一键脚本或者面板来搭建。通过手动搭建可以更好地了解整个过程。所以以下过程全都是手动搭建。

  • 首先配置源(根据系统配置,这里是centos7),安装一下wget下载工具
[root@Cloud ~]# mount /dev/sr0 /mnt
[root@Cloud ~]# mv /etc/yum.repos.d/* /tmp/
[root@Cloud ~]# vi /etc/yum.repos.d/local.repo
[local]
name=centos
baseurl=file:///mnt
gpgcheck=0
enabled=1

[root@Cloud ~]# yum clean all && yum install -y wget
输出内容就省略了。这样一来我们就可以用wget找网络上的资源了。

然后安装一下zip 这个安装nextcloud的时候要用到
[root@Cloud ~]#yum install -y zip unzip

Apache安装配置

  • 通过yum安装apache
[root@Cloud ~]# yum install -y httpd
省略部分输出
[root@Cloud ~]# systemctl start httpd && systemctl enable httpd 
开启apache服务并开机自启
然后我们可以验证一下
[root@Cloud ~]# ss -tnl | grep 80
LISTEN     0      128         :::80                      :::* 
防火墙记得关掉
[root@Cloud ~]# systemctl stop firewalld
[root@Cloud ~]# systemctl disable firewalld

SELinux关掉(也可以配置一下安全上下文 但是太麻烦了直接关掉看效果。后期再改都可以)
[root@Cloud ~]# setenforce 0
[root@Cloud ~]# vi /etc/sysconfig/selinux 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled #这里设置成disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are pro
tected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

之后通过自己的ip访问应该会有个默认的测试页面。这里就不展示了 到此为止LAMP中的L和A我们就搞定了。

Mariadb安装配置

  • 通过yum安装Mariadb
[root@Cloud ~]#yum install mariadb mariadb-server mariadb-devel -y
省略部分输出

设置开机自启,启动服务
[root@Cloud ~]# systemctl start mariadb && systemctl enable mariadb

验证一下
[root@Cloud ~]# ss -tnl | grep 3306
LISTEN     0      50           *:3306                     *:*  

之后初始化一下数据库 每一步我都会给注释的。
[root@Cloud ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):  #这里直接回车 因为初始数据库没有密码
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y #这里问你要不要设置一个root密码。这个密码记好 后面要用到的
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  #问你要不要去掉匿名用户 建议选择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] n  #要不要禁止root远程登录 我这里没有禁止
 ... skipping.

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 #要不要刷新一下授权表。这里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! 

弹出Thanks for using MariaDB之后我们就可以使用了

[root@Cloud ~]# mysql -uroot -p刚才设置的密码 
#-p后面的就是你们的密码 不要输入中文“刚才设置的密码”之后就是数据库的操作了。

MariaDB [(none)]> show databases; #先看一下数据库里面有啥
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

#创建一个数据库叫nextcloud_db 默认字符集使用utf8。如果不带这个的话可能会乱码。mysql默认字符集是latin1.不支持中文
MariaDB [(none)]> create database nextcloud_db default charset=utf8;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| nextcloud_db       |
| performance_schema |
+--------------------+
#再看一下数据库 发现多了个nextcloud_db

#给root所有权限使用这个数据库 密码是:123456
MariaDB [(none)]> grant all privileges on nextcloud_db.* to root@'%' identified by '123456';

MariaDB [(none)]> flush privileges;
#刷一下授权

这样数据库的搭建就完成了。最后就剩下php 我们的环境就搭好了

PHP安装配置

nextcloud搭建需要php7.2以上的版本。而如果用本地的 yum安装版本过低不符合搭建的要求。所以这个地方得用一下网络源。或者你选择使用源码安装也可以,但是没必要。这里直接找一个fedora的源去安装7.2的php

  • 首先增加一个源
[root@Cloud ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
#省略部分输出

[root@Cloud ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
#省略部分输出
  • 接下来安装一下php7.2
[root@Cloud ~]# yum install -y php72w php72w-devel php72w-pear php72w-pecl php72w-gd php72w-opcache php72w-cli php72w-pdo php72w-process php72w-pecl-apcu php72w-mcrypt php72w-mysql php72w-fpm php72w-pecl-redis php72w-common php72w-xml php72w-mbstring php72w-pecl-igbinary php72w-intl php72w-pecl-imagick
#省略部分输出

安装好以后改一下apache的配置文件
[root@Cloud ~]# vi /etc/httpd/conf/httpd.conf 
#省略部分输出
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php #加上这一行

[root@Cloud html]# chown -R apache.apache /var/www/html #将这个默认目录的权限给apache

#写一个php测试页面然后重启httpd服务
[root@Cloud ~]# vi /var/www/html/test.php
<?php
phpinfo();
?>

[root@Cloud html]# systemctl restart httpd

之后通过http://服务器的ip/test.php可以看到一个php的测试页面说明配置php环境成功

2.2 nextcloud安装

从官网下载nextcloud。

[root@Cloud html]# wget https://download.nextcloud.com/server/releases/nextcloud-18.0.0.zip
#省略部分输出

然后使用unzip解压 
[root@Cloud html]# unzip nextcloud-18.0.0.zip
#省略部分输出

之后将这个文件夹整个移动到/var/www/html中
[root@Cloud html]# mv nextcloud /var/www/html

编写一个/var/www/html/nextcloud/config/config.php文件,修改一下数据库对应选项
[root@Cloud nextcloud]#vi /var/www/html/nextcloud/config/config.php 
<?php
$CONFIG = array (
  'instanceid' => 'oc0tplp89d0x',
  'passwordsalt' => 'totCDGnfkMaK2up5DRbu2fXLdS7tsU',
  'secret' => 'QcZ6cI370VrscFPg/WJiWzjxFivtltGCOdhuprNu2y9fKh7a',
  'trusted_domains' =>
  array (
    0 => '192.168.2.9',    #此处为自己IP地址
  ),
  'datadirectory' => '/var/www/html/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '18.0.0.10',
  'overwrite.cli.url' => 'http://192.168.2.9/nextcloud',  #此处为自己IP地址
  'dbname' => 'nextcloud_db',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'root',
  'dbpassword' => '123456',
);

最后给一下权限
[root@Cloud html]# chown -R apache.apache /var/www/html/nextcloud 

然后就可以通过http://服务器ip/nextcloud/index.php 来访问了,最后可以通过端口映射来将服务映射出去 到此基本安装就告一段落了

当然 如果映射出去了 从外网访问可能会弹出从不受信任的域名访问。这个时候需要更改一下配置文件

 [root@Cloud nextcloud]#vi /var/www/html/nextcloud/config/config.php 
 array (
    0 => '192.168.2.9',
    1 => '你的公网ip'
  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值