How to configure cluster access in ceph
This article introduces how to configure cluster access in ceph. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
1. The configuration file / etc/ceph/ceph.conf is as follows
[global]
Auth cluster required = cephx
Auth service required = cephx
Auth client required = cephx
; keyring = / etc/ceph/keyring
Ax open files = 131072
Log file = / var/log/ceph/$name.log
Pid file = / var/run/ceph/$name.pid
Osd pool default size = 2
Osd pool default min_size = 1
[mon]
Mon data = / data/$name
; keyring = / data/mon.0/keyring
[mon.0]
Host = ceph-one
Mon addr = 192.168.122.1 pur6789
; [mds]
; [mds.0]
; host = ceph-one
[osd]
Osd data = / data/$name
Osd journal = / data/$name/journal
Osd journal size = 1000
Osd mkfs type = xfs
Devs = / dev/ceph/$name
Osd crush update on start = 0
; keyring = / etc/ceph/keyring
[osd.0]
Host = ceph-one
[osd.1]
Host = ceph-two
[osd.2]
Host = ceph-three
[osd.3]
Host = ceph-four
[osd.4]
Host = ceph-five
[osd.5]
Host = ceph-six
As shown above, all three items in auth cluster required=cepghx are configured as cephx options, and all are configured as none without permission verification.
2. Generate keyring file
Ceph-authtool-create-keyring / data/mon.0/ceph.mon.keyring-gen-key-n mon. -- cap mon 'allow *'
The above command generates the keyring file in / data/mon.0/ceph.mon.keyring. If you do not configure monitor, use the default keyring file / data/mon.0/keyring, where / data/mon.0 is the mon data configuration directory of ceph.conf
Ceph auth get-or-create osd.0 mon 'allow rwx' osd' allow *'- o / data/osd.0/keyring
The above command generates the keyring of osd
Ceph auth get-or-create client.admin mds' allow' osd 'allow *' mon 'allow *' > / etc/ceph/ceph.client.admin.keyring
The above command generates the keyring of client.admin, which should be the access command of rados.
3. Rados uses keyring to access code examples
# include
# include
# include
Rados_t cluster; / / declare cluster handle
Rados_ioctx_t io
Char * poolname = "data"
Char cluster_name [] = "ceph"
Char user_name [] = "client.admin"; / / user name
Uint64_t flags
Char xattr [] = "en_US"
Int err
Char * buf, * st
Size_t buflen, stlen
Char * cmd [2]
Cmd [1] = NULL
Err = rados_create2 (& cluster, cluster_name, user_name, flags); / / create cluster handle
Char fsid [50] = {0}
If (err < 0)
{
Fprintf (stderr, "% s: Couldn't create the cluster handle!% s\ n", argv [0], strerror (- err))
Exit (EXIT_FAILURE)
}
Else
{
Printf ("\ nCreated a cluster handle.\ n")
}
/ / read the configuration file and complete the cluster handle
Err = rados_conf_set (cluster, "mon_host", "127.0.0.1")
Err = rados_conf_set (cluster, "key", "AQDhSK9UeA+nOhAAhA7s2GLdU8seDVMBqK+iwg==")
/ / err = rados_conf_read_file (cluster, "/ etc/ceph/ceph.conf")
If (err < 0)
{
Fprintf (stderr, "% s: cannot read config file:% s\ n", argv [0], strerror (- err))
Exit (EXIT_FAILURE)
}
Else
{
Printf ("\ nRead the config file.\ n")
}
Err = rados_connect (cluster)
Notice the two lines of rados_conf_set code, which I used to compile the command line with ceph_test.c
Gcc ceph_test.c-o ceph_test-lrados
So much for sharing about how to configure cluster access rights in ceph. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.