文章

安装GlusterFS(二)-安装heketi

安装GlusterFS(二)-安装heketi

1.安装heketi

参考资料:

https://www.cnblogs.com/netonline/p/10288219.html

1
yum install -y heketi heketi-client

2.配置heketi

修改heketi配置文件:heketi.json

1
[root@heketi ~]# vi /etc/heketi/heketi.json 

注意要先删除下面的#注释内容,heketi才能正常启动!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{
  # 默认端口tcp8080
  "_port_comment": "Heketi Server Port Number",
  "port": "8080",

  # 默认值false,不需要认证
  "_use_auth": "Enable JWT authorization. Please enable for deployment",
  "use_auth": true,

  "_jwt": "Private keys for access",
  "jwt": {
    "_admin": "Admin has access to all APIs",
    "admin": {
      "key": "admin@123"
    },
    "_user": "User only has access to /volumes endpoint",
    "user": {
      "key": "user@123"
    }
  },

  "_glusterfs_comment": "GlusterFS Configuration",
  "glusterfs": {
    "_executor_comment": [
      "Execute plugin. Possible choices: mock, ssh",
      "mock: This setting is used for testing and development.",
      "      It will not send commands to any node.",
      "ssh:  This setting will notify Heketi to ssh to the nodes.",
      "      It will need the values in sshexec to be configured.",
      "kubernetes: Communicate with GlusterFS containers over",
      "            Kubernetes exec api."
],
    # mock:测试环境下创建的volume无法挂载;
    # kubernetes:在GlusterFS由kubernetes创建时采用
    "executor": "ssh",

    "_sshexec_comment": "SSH username and private key file information",
    "sshexec": {
      "keyfile": "/etc/heketi/heketi_key",
      "user": "root",
      "port": "22",
      "fstab": "/etc/fstab"
    },

    "_kubeexec_comment": "Kubernetes configuration",
    "kubeexec": {
      "host" :"https://kubernetes.host:8443",
      "cert" : "/path/to/crt.file",
      "insecure": false,
      "user": "kubernetes username",
      "password": "password for kubernetes user",
      "namespace": "OpenShift project or Kubernetes namespace",
      "fstab": "Optional: Specify fstab file on node.  Default is /etc/fstab"
    },

    "_db_comment": "Database file name",
    "db": "/var/lib/heketi/heketi.db",

    "_loglevel_comment": [
      "Set log level. Choices are:",
      "  none, critical, error, warning, info, debug",
      "Default is warning"
],
    # 默认设置为debug,不设置时的默认值即是warning;
    # 日志信息输出在/var/log/message
    "loglevel" : "warning"
  }
}

3.设置heketi免密访问heketi

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 选择ssh执行器,heketi服务器需要免密登陆GlusterFS集群的各节点;
# -t:秘钥类型;
# -q:安静模式;
# -f:指定生成秘钥的目录与名字,注意与heketi.json的ssh执行器中"keyfile"值一致;
# -N:秘钥密码,””即为空
[root@heketi ~]# ssh-keygen -t rsa -q -f /etc/heketi/heketi_key -N ""

# heketi服务由heketi用户启动,heketi用户需要有新生成key的读赋权,否则服务无法启动
[root@heketi ~]# chown heketi:heketi /etc/heketi/heketi_key

# 分发公钥;
# -i:指定公钥
[root@heketi ~]# ssh-copy-id -i /etc/heketi/heketi_key.pub root@172.21.8.14
[root@heketi ~]# ssh-copy-id -i /etc/heketi/heketi_key.pub root@172.21.8.15
[root@heketi ~]# ssh-copy-id -i /etc/heketi/heketi_key.pub root@172.21.8.16

验证ssh免密访问:

1
2
3
4
ssh xxx -v:debug模式
ssh root@172.21.8.14 -i /etc/heketi/heketi_key
ssh root@172.21.8.15 -i /etc/heketi/heketi_key
ssh root@172.21.8.16 -i /etc/heketi/heketi_key

4.启动heketi

1
2
3
4
5
6
# 通过yum安装heketi,默认的systemd文件有1处错误;
# /usr/lib/systemd/system/heketi.service文件的“-config=/etc/heketi/heketi.json”应该修改为“--config=/etc/heketi/heketi.json”;
# 否则启动时报“Error: unknown shorthand flag: 'c' in -config=/etc/heketi/heketi.json”错,导致服务无法启动
[root@heketi ~]# systemctl enable heketi
[root@heketi ~]# systemctl restart heketi
[root@heketi ~]# systemctl status heketi
1
2
# 验证
[root@heketi ~]# curl http://localhost:8080/hello

5.设置GlusterFS集群

1
2
3
4
5
6
7
8
9
10
11
# 通过topology.json文件定义组建GlusterFS集群;
# topology指定了层级关系:clusters-->nodes-->node/devices-->hostnames/zone;
# node/hostnames字段的manage填写主机ip,指管理通道,在heketi服务器不能通过hostname访问GlusterFS节点时不能填写hostname;
# node/hostnames字段的storage填写主机ip,指存储数据通道,与manage可以不一样;
# node/zone字段指定了node所处的故障域,heketi通过跨故障域创建副本,提高数据高可用性质,如可以通过rack的不同区分zone值,创建跨机架的故障域;
# devices字段指定GlusterFS各节点的盘符(可以是多块盘),必须是未创建文件系统的裸设备

#查看磁盘空间命令:
fdisk -l

[root@heketi ~]# vi /etc/heketi/topology.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{
    "clusters": [
        {
            "nodes": [
                {
                    "node": {
                        "hostnames": {
                            "manage": [
                                "172.21.8.14"
                            ],
                            "storage": [
                                "172.21.8.14"
                            ]
                        },
                        "zone": 1
                    },
                    "devices": [
                        "/dev/vdb"
                    ]
                },
                {
                    "node": {
                        "hostnames": {
                            "manage": [
                                "172.21.8.15"
                            ],
                            "storage": [
                                "172.21.8.15"
                            ]
                        },
                        "zone": 2
                    },
                    "devices": [
                        "/dev/vdb"
                    ]
                },
                {
                    "node": {
                        "hostnames": {
                            "manage": [
                                "172.21.8.16"
                            ],
                            "storage": [
                                "172.21.8.16"
                            ]
                        },
                        "zone": 3
                    },
                    "devices": [
                        "/dev/vdb"
                    ]
                }
            ]
        }
    ]
}
1
2
3
4
5
# GlusterFS集群各节点的glusterd服务已正常启动,但不必组建受信存储池;
# heketi-cli命令行也可手动逐层添加cluster,node,device,volume等;
# “--server http://localhost:8080”:localhost执行heketi-cli时,可不指定;
# “--user admin --secret admin@123”:heketi.json中设置了认证,执行heketi-cli时需要带上认证信息,否则报“Error: Invalid JWT token: Unknown user”错
[root@heketi ~]# heketi-cli --server http://localhost:8080 --user admin --secret admin@123 topology load --json=/etc/heketi/topology.json
1
2
3
4
5
# 查看heketi topology信息,此时volume与brick等未创建;
# 通过“heketi-cli cluster info”可以查看集群相关信息;
# 通过“heketi-cli node info”可以查看节点相关信息;
# 通过“heketi-cli device info”可以查看device相关信息
[root@heketi ~]# heketi-cli --user admin --secret admin@123 topology info
本文由作者按照 CC BY 4.0 进行授权