目 录CONTENT

文章目录

Centos7挂载NFS服务器硬盘搭建owncloud网盘

geekrabbit
2022-03-28 / 0 评论 / 5 点赞 / 1,055 阅读 / 3,520 字 / 正在检测是否收录...
温馨提示:
创作不易,转载请注明出处

image.png

什么是NFS服务器
NFS服务器可以让PC将网络中的NFS服务器共享的目录挂载到本地端的文件系统中,而在本地端的系统中来看,那个远程主机的目录就好像是自己的一个磁盘分区一样,在使用上相当便利;

owncloud是什么
ownCloud 是一个来自 KDE 社区开发的免费软件,提供私人的 Web 服务。当前主要功能包括文件管理(内建文件分享)、音乐、日历、联系人等等,可在PC和服务器上运行。

实验环境

  1. 两台centos7服务器,
  2. IP: 192.168.44.129 搭建owncloud
  3. IP: 192.168.44.130 搭建nfs

实验步骤

实验拓扑图

sa.png

配置nfs服务器

修改主机名

[root@localhost ~]# hostnamectl set-hostname nfs-server.com

NFS搭虚拟机的防火墙

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# systemctl disable firewalld

[root@localhost ~]# vi /etc/sysconfig/selinux

SELINUX=enforcing 改为 SELINUX=disabled 

[root@localhost ~]# setenforce 0

创建共享目录并赋予其他人写的权限

[root@localhost ~]# mkdir /nfs
[root@localhost ~]# touch /nfs/1.html
[root@localhost ~]# ls /nfs/
[root@localhost ~]# 1.html
[root@localhost ~]# ls -ld /nfs/
[root@localhost ~]# chmod -R 777 /nfs/

安装nfs软件 nfs-utils rpcbind

[root@localhost ~]# yum install -y nfs-utils rpcbind

修改配置文件/etc/exports

[root@localhost ~]# vim /etc/exports

/nfs 192.168.44.129(rw,no_root_squash,sync)

注:ip地址为owncloud机器的ip地址,非本机!
image.png

启动nfs服务并设置为开机自动启动服务

[root@localhost ~]# systemctl start nfs-server

[root@localhost ~]# systemctl enable nfs-server

查看nfs进程

[root@localhost ~]# ps -elf | grep nfs

image

配置owncloud服务器

修改主机名

[root@localhost ~]# hostnamectl set-hostname owncloud.com

安装nfs文件系统

[root@localhost ~]# yum install -y nfs-utils

永久挂载共享目录

[root@localhost ~]# vim /etc/fstab

192.168.44.130:/nfs       /mnt    nfs     defaults        0 0

mount -a     //挂载

查看共享目录挂在情况

[root@owncloud ~]# df -hT | grep nfs
192.168.1.10:/nfs       nfs4       17G  1.9G   16G  11% /mnt

验证共享文件是否成功

[root@localhost ~]# ls /mnt/

1.html

安装http、mariadb服务

[root@localhost ~]# yum install -y httpd mariadb-server mariadb

启动httpd、mariadb服务,并设置成开机自启

[root@owncloud ~]# systemctl start httpd
[root@owncloud ~]# systemctl enable httpd
[root@owncloud ~]# systemctl start mariadb
[root@owncloud ~]# systemctl enable mariadb

验证http服务和mariadb服务是否启动成功

192.168.44.129

将owncloud包拖拽到 owncloud虚拟机中的/mnt目录下

[root@owncloud mnt]# unzip owncloud-complete-20210326.zip
修改/mnt目录下的所有文件的属主和属组为apache
[root@owncloud ~]# chown -R apache:apache /mnt/

更新yum源

[root@owncloud ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm

[root@owncloud ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安装php软件包

[root@owncloud ~]# yum install -y php72w php72w-opcache php72w-xml php72w-gd php72w-devel php72w-mysql php72w-intl php72w-mbstring

创建http虚拟主机

[root@owncloud ~]# vim /etc/httpd/conf.d/owncloud.conf

<VirtualHost 192.168.44.129:80>
        ServerName owncloud.linux.com 
        DocumentRoot /mnt/owncloud 
        ErrorLog /var/log/httpd/vedio_error.log 
        CustomLog /var/log/httpd/vedio_access.log combined 
</VirtualHost>

<Directory "/mnt">
        Require all granted 
</Directory>

image.png

检查http虚拟主机语法是否正确

[root@owncloud ~]# httpd -t
Syntax OK

重新启动httpd服务

[root@owncloud ~]# systemctl restart httpd

进入数据库

[root@owncloud ~]# mysql -uroot -p

创建owncloud库
MariaDB [(none)]> create database owncloud;
Query OK, 1 row affected (0.00 sec)

nfs服务器授权用户可以登录服务器

MariaDB [owncloud]> grant all on owncloud.* to own@192.168.1.10 identified by '123';

Query OK, 0 rows affected (0.00 sec)
刷新授权表
MariaDB [owncloud]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

退出数据库
MariaDB [owncloud]> exit
Bye

验证nfs-server 是否可以登录数据库

测试owncloud是否搭建成功

在浏览器:http://192.168.44.129/index.php

image.png

避坑指南

访问提示 You don't have permission to access
image.png

执行这个

[root@localhost ~]# vim /etc/sysconfig/selinux
 
SELINUX=enforcing 改为 SELINUX=disabled 

[root@localhost ~]# systemctl restart httpd 

[root@localhost ~]# setenforce 0 
5
博主关闭了所有页面的评论