Ceph和Owncloud部署与使用

Ceph和Owncloud部署与使用

1.部署ceph集群

(1)虚拟机基础配置

在VMware中设置VMnet1的网络为仅主机模式,网段设置为203.0.113.0;VMnet8设置为NAT模式,网段设置为10.0.0.0,如图7-11所示。

图7-11 虚拟机配置

(2)集群网络配置

在三台虚拟机ceph-1、ceph-2、ceph-3上部署Ceph集群,三台虚拟机的IP地址为:10.0.0.101、10.0.0.102、10.0.0.103,子网掩码为255.255.255.0,默认网关为10.0.0.2,DNS服务器为10.0.0.2。

(3)配置client虚拟机

在VMware中创建一台虚拟机,操作系统为CentOS-7-x86_64-DVD-1908,硬盘大小为20G,如图7-12所示。

图7-12 client虚拟机设置

(4)client网络配置

为虚拟机配置主机名:client。配置IP地址:10.0.0.100,子网掩码为255.255.255.0,默认网关为10.0.0.2,DNS服务器为10.0.0.2,使虚拟机可以访问Internet。

2.配置Ceph对象存储

(1)部署Ceph RGW

在ceph-1节点部署Ceph

RGW。

[root@ceph-1 ~]# cd /opt/osd

[root@ceph-1 osd]# ceph-deploy rgwcreate ceph-1

……

(2)编辑pool文件

[root@ceph-1 osd]# vi /root/pool

.rgw

.rgw.root

.rgw.control

.rgw.gc

.rgw.buckets

.rgw.buckets.index

.rgw.buckets.extra

.log

.intent-log

.usage

.users

.users.email

.users.swift

.users.uid

(3)创建脚本

编辑创建和配置pool的脚本文件。

[root@ceph-1 osd]# vi/root/create_pool.sh

#!/bin/bash


PG_NUM=8

PGP_NUM=8

SIZE=3


for i in `cat /root/pool`

        do

        ceph osd pool create $i $PG_NUM

        ceph osd pool set $i size $SIZE

        done


for i in `cat /root/pool`

        do

        ceph osd pool set $i pgp_num $PGP_NUM

        done

(4)运行脚本

运行脚本文件,创建对象存储所使用的所有pool。

[root@ceph-1 osd]# chmod +x/root/create_pool.sh

[root@ceph-1 osd]#/root/create_pool.sh

pool '.rgw' created

set pool 5 size to 3

pool '.rgw.root' already exists

set pool 1 size to 3

pool '.rgw.control' created

set pool 6 size to 3

pool '.rgw.gc' created

set pool 7 size to 3

pool '.rgw.buckets' created

set pool 8 size to 3

pool '.rgw.buckets.index' created

set pool 9 size to 3

pool '.rgw.buckets.extra' created

set pool 10 size to 3

pool '.log' created

set pool 11 size to 3

pool '.intent-log' created

set pool 12 size to 3

pool '.usage' created

set pool 13 size to 3

pool '.users' created

set pool 14 size to 3

pool '.users.email' created

set pool 15 size to 3

pool '.users.swift' created

set pool 16 size to 3

pool '.users.uid' created

set pool 17 size to 3

set pool 5 pgp_num to 8

set pool 1 pgp_num to 8

set pool 6 pgp_num to 8

set pool 7 pgp_num to 8

set pool 8 pgp_num to 8

set pool 9 pgp_num to 8

set pool 10 pgp_num to 8

set pool 11 pgp_num to 8

set pool 12 pgp_num to 8

set pool 13 pgp_num to 8

set pool 14 pgp_num to 8

set pool 15 pgp_num to 8

set pool 16 pgp_num to 8

set pool 17 pgp_num to 8

(5)测试访问集群

在ceph-1节点测试是否能访问Ceph集群,测试成功会出现HEALTH_OK的字样。

[root@ceph-1 osd]# cp/var/lib/ceph/radosgw/ceph-rgw.ceph-1/keyring/etc/ceph/ceph.client.rgw.ceph-1.keyring

[root@ceph-1 osd]# ceph -s -k/var/lib/ceph/radosgw/ceph-rgw.ceph-1/keyring --name client.rgw.ceph-1

 cluster:

   id:     68ecba50-862d-482e-afe2-f95961ec3323

   health: HEALTH_OK


 services:

   mon: 3 daemons, quorum ceph-1,ceph-2,ceph-3 (age 21m)

   mgr: ceph-1(active, since 21m)

   osd: 3 osds: 3 up (since 21m), 3 in (since 7d)

   rgw: 1 daemon active (ceph-1)


  data:

   pools:   17 pools, 136 pgs

   objects: 187 objects, 1.2 KiB

   usage:   3.0 GiB used, 294 GiB /297 GiB avail

pgs:     136 active+clean

3.使用S3

API访问Ceph对象存储

(1)创建用户

在ceph-1节点创建radosgw用户。

[root@ceph-1 osd]# radosgw-adminuser create --uid=radosgw --display-name="radosgw"

{

   "user_id": "radosgw",

   "display_name": "radosgw",

   "email": "",

   "suspended": 0,

   "max_buckets": 1000,

   "subusers": [],

   "keys": [

        {

            "user":"radosgw",

            "access_key": "TMDWQAB2U9LDTHGID8UG",

            "secret_key":"2z7cuRMxDzIZcOfycLR9eZs4dHF6N33gMVTd6ICp"

        }

   ],

   "swift_keys": [],

   "caps": [],

   "op_mask": "read, write, delete",

   "default_placement": "",

   "default_storage_class": "",

   "placement_tags": [],

   "bucket_quota": {

        "enabled": false,

        "check_on_raw": false,

        "max_size": -1,

        "max_size_kb": 0,

        "max_objects": -1

   },

   "user_quota": {

        "enabled": false,

        "check_on_raw": false,

       "max_size": -1,

        "max_size_kb": 0,

        "max_objects": -1

   },

   "temp_url_keys": [],

   "type": "rgw",

   "mfa_ids": []

}

(2)安装bind服务

在client节点安装bind服务。

[root@client ~]# mkdir /opt/bak

[root@client ~]# cd/etc/yum.repos.d

[root@client yum.repos.d]# mv */opt/bak

将CentOS7-Base-163.repo通过SFTP复制到client节点的/etc/yum.repos.d目录中。

[root@client yum.repos.d]# ls

CentOS7-Base-163.repo

[root@client yum.repos.d]# yumclean all

[root@client yum.repos.d]# yummakecache

[root@client yum.repos.d]# yum -y installbind

(3)编辑bind主配置文件

[root@client ~]# vi /etc/named.conf

修改以下配置:

listen-on port 53 {127.0.0.1;10.0.0.100; };

allow-query     { localhost;10.0.0.0/24; };

添加以下配置:

zone "lab.net" IN {

        type master;

        file "db.lab.net";

        allow-update { none; };

};

(4)编辑域lab.net的区域配置文件

[root@client ~]# vi/var/named/db.lab.net

@ 86400 IN SOA lab.net.root.lab.net. (

        20191120

        10800

        3600

        3600000

        86400 )

@ 86400 IN NS lab.net.

@ 86400 IN A 10.0.0.101

* 86400 IN CNAME @

(5)检查配置文件

[root@client ~]# named-checkconf/etc/named.conf

[root@client ~]# named-checkzonelab.net /var/named/db.lab.net

zone lab.net/IN: loaded serial20191120

OK

(6)启动bind服务

[root@client ~]# systemctl startnamed

[root@client ~]# systemctl enable named

Created symlink from/etc/systemd/system/multi-user.target.wants/named.service to/usr/lib/systemd/system/named.service.

(7)配置DNS服务

编辑网卡配置文件,将DNS服务器指向client自己的IP地址。

[root@client ~]# vi/etc/sysconfig/network-scripts/ifcfg-ens32

DNS1=10.0.0.100

(8)定义DNS地址

编辑/etc/resolv.conf,将DNS服务器指向client自己的IP地址。

[root@client ~]# vi/etc/resolv.conf

nameserver 10.0.0.100

(9)安装nslookup

安装nslookup,测试DNS配置

[root@client ~]# yum -y installbind-utils

[root@client ~]# nslookup

> ceph-1.lab.net

Server:         10.0.0.100

Address:        10.0.0.100#53


ceph-1.lab.net  canonical name = lab.net.

Name:   lab.net

Address: 10.0.0.101

> exit

(10)安装s3cmd

访问https://s3tools.org/download,下载s3cmd的2.0.2版本。

[root@client ~]# ls

anaconda-ks.cfg  s3cmd-2.0.2.zip

[root@client ~]# yum -y installunzip python-dateutil

[root@client ~]# unzips3cmd-2.0.2.zip

……

(11)配置s3cmd

[root@client ~]# cd s3cmd-2.0.2

[root@client s3cmd-2.0.2]# ./s3cmd--configure


Enter new values or accept defaultsin brackets with Enter.

Refer to user manual for detaileddescription of all options.


Access key and Secret key are youridentifiers for Amazon S3. Leave them empty for using the env variables.

Access Key: TMDWQAB2U9LDTHGID8UG

Secret Key:2z7cuRMxDzIZcOfycLR9eZs4dHF6N33gMVTd6ICp

Default Region [US]:


Use "s3.amazonaws.com"for S3 Endpoint and not modify it to the target Amazon S3.

S3 Endpoint [s3.amazonaws.com]:ceph-1.lab.net:7480


Use"%(bucket)s.s3.amazonaws.com" to the target Amazon S3."%(bucket)s" and "%(location)s" vars can be used

if the target S3 system supportsdns based buckets.

DNS-style bucket+hostname:porttemplate for accessing a bucket [%(bucket)s.s3.amazonaws.com]:%(bucket).ceph-1.lab.net:7480


Encryption password is used toprotect your files from reading

by unauthorized persons while intransfer to S3

Encryption password:

Path to GPG program [/usr/bin/gpg]:


When using secure HTTPS protocolall communication with Amazon S3

servers is protected from 3rd partyeavesdropping. This method is

slower than plain HTTP, and canonly be proxied with Python 2.7 or newer

Use HTTPS protocol [Yes]: no


On some networks all internetaccess must go through a HTTP proxy.

Try setting it here if you can'tconnect to S3 directly

HTTP Proxy server name:


New settings:

 Access Key: TMDWQAB2U9LDTHGID8UG

 Secret Key: 2z7cuRMxDzIZcOfycLR9eZs4dHF6N33gMVTd6ICp

 Default Region: US

 S3 Endpoint: ceph-1.lab.net:7480

 DNS-style bucket+hostname:port template for accessing a bucket:%(bucket).ceph-1.lab.net:7480

 Encryption password:

 Path to GPG program: /usr/bin/gpg

 Use HTTPS protocol: False

 HTTP Proxy server name:

 HTTP Proxy server port: 0


Test access with suppliedcredentials? [Y/n] n


Save settings? [y/N] y

Configuration saved to'/root/.s3cfg'

(12)显示存储桶

使用命令可以查看S3的存储桶,此处因为还没有使用命令创建,所以结果为空。

[root@client s3cmd-2.0.2]# ./s3cmdls

(13)创建存储桶

在client节点可以使用命令创建存储桶bucket

[root@client s3cmd-2.0.2]# ./s3cmdmb s3://bucket

Bucket 's3://bucket/' created

[root@client s3cmd-2.0.2]# ./s3cmdls

2019-11-23 07:45  s3://bucket

(14)上传文件

将/etc/named.conf和/var/named/db.lab.net上传到存储桶bucket中

[root@client s3cmd-2.0.2]# ./s3cmdput /etc/named.conf s3://bucket

WARNING: Module python-magic is notavailable. Guessing MIME types based on file extensions.

upload: '/etc/named.conf' ->'s3://bucket/named.conf'  [1 of 1]

 1933 of 1933  100% in    1s  1317.89 B/s done

[root@client s3cmd-2.0.2]# ./s3cmdput /var/named/db.lab.net s3://bucket

WARNING: Module python-magic is notavailable. Guessing MIME types based on file extensions.

upload: '/var/named/db.lab.net'-> 's3://bucket/db.lab.net'  [1 of 1]

 182 of 182  100% in    0s     2.78 kB/s done

4.部署LAMP环境

(1)安装最新源

在client节点安装epel和webtatic软件源,防止后面出现丢包。

[root@client ~]# rpm -Uvhhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

[root@client ~]# rpm -Uvhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm

[root@client ~]# yum makecache

(2)安装LAMP

在client节点需要安装Owncloud所需的LAMP环境软件包。

[root@client ~]# yum -y install httpd php72wmariadb-server php72w-mysql php72w-gd php72w-xml php72w-intl php72w-mbstring

(3)启动数据库

在搭建Owncloud网盘服务的时候,需要用到数据库,在上一步已经安装了数据库,此处需要启用MariaDB数据库服务。

[root@client ~]# systemctl start mariadb

[root@client ~]# systemctl enable mariadb

(4)启动Apache服务

启动和启用Apache HTTPD Web服务

[root@client ~]# systemctl start httpd

[root@client ~]# systemctl enable httpd

(5)关闭防火墙

[root@client ~]# systemctl stop firewalld

[root@client ~]# systemctl disable firewalld

(6)关闭SElinux

将SELinux模式设置为permissive,并检查是否设置完成

[root@client ~]# setenforce 0

[root@client ~]# vi /etc/selinux/config

SELINUX=permissive

5.配置Owncloud

(1)上传Owncloud压缩包

将OwnCloudTarball_10_0_9.zip通过SFTP传输到client节点的/root目录,并查看。

(2)解压Owncloud

有些centos系统需要自己安装unzip解压文件,此处如果出现无法解压时需看清报错信息。

[root@client ~]# unzipOwnCloudTarball_10_0_9.zip

(3)更新web文件

将Owncloud文件复制到Web服务器默认网站的主目录中,此处使用cp -rf命令是将当前目录下所有文件复制过去。

[root@client ~]# cd owncloud-10.0.9

[root@client owncloud-10.0.9]# cp -rf */var/www/html

(4)设置目录权限

[root@client owncloud-10.0.9]# cd/var/www/html

[root@client html]# chmod -R 777 config

[root@client html]# mkdir data

[root@client html]# chown -R apache:apachedata

(5)设置数据库密码

此处设置MariaDB数据库root用户的密码为123456,后面网盘服务连接数据库时需要设置同样密码,不然无法提供后端存储服务,会导致安装失败。

[root@client html]# mysqladmin -u rootpassword '123456'

(6)创建owncloud数据库

登录MariaDB数据库服务器并创建owncloud数据库,作为后端的数据存储。

[root@client html]# mysql -uroot -p123456

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 3

Server version: 5.5.64-MariaDB MariaDB Server


Copyright (c) 2000, 2018, Oracle, MariaDBCorporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.


MariaDB [(none)]> CREATE DATABASEowncloud;

Query OK, 1 row affected (0.00 sec)


MariaDB [(none)]> exit

Bye

(7)初始化owncloud网页

在初始化owncloud的页面中会让我们进行一些设置,比如用户、密码和数据库等。选数据库的时候千万要注意几点:

[if !supportLists]n  [endif]首先数据库类型要选择mysql/mariadb,如果选的是sqlite的话,性能会不太好,后面在owncloud的设置页面中也会有提示。到那时想改就比较麻烦了。

[if !supportLists]n  [endif]然后就是如果你的服务器原先就创建过用户和密码,那在选择好数据库类型后,下面的用户和密码就是你之前的用户名和密码

使用浏览器访问client节点的IP地址,创建管理员账号admin,为admin用户设置密码,配置数据库使用MySQL/MariaDB,如图7-13所示。

图7-13 owncloud初始化界面

(8)安装owncloud

输入数据库用户名root、密码123456、数据库名owncloud,单击安装完成,如图7-14所示。

图7-14 owncloud安装

(9)登陆owncloud

使用admin用户登录Owncloud,如图7-15所示。

图7-15 owncloud登陆

如果登录出现错误,在client节点输入以下命令,设置php文件的权限为可读可写可执行。

# chmod -R 777 /var/lib/php/session

(10)配置外部存储

单击页面右上角的adminà设置à管理à存储,单击启用Enable external storage。输入目录名称为s3,选择外部存储为Amazon S3,输入存储桶为bucket、主机名为ceph-1.lab.net、端口号为7480、区域为US,启用Path Style,输入Access Key和Secret Key。当看到前面出现绿色圆圈时,表示外部存储配置成功,如图7-16所示。

图7-16 配置外部存储

(11)查看S3目录

通过主界面可以看到之前创建的s3目录,如图7-17所示

图7-17 S3外部存储

(12)网盘测试

此时双击s3可以进入s3目录,并且可以看到之前实验使用s3cmd上传的文件,也可以在Web界面上传文件或下载文件,还原了平时所使用网盘的功能,如图7-18所示。

图7-18 网盘测试

你可能感兴趣的:(Ceph和Owncloud部署与使用)