這篇文章給大家介紹ceph中怎么配置集群訪問權(quán)限,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
創(chuàng)新互聯(lián)主要從事網(wǎng)站制作、成都網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)丹徒,十多年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108
1、配置文件/etc/ceph/ceph.conf如下
[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:6789
;[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
如上所示auth cluster required=cepghx中三項全部配置為cephx選項,如果不做權(quán)限校驗全部配置為none
2、生成keyring文件
ceph-authtool --create-keyring /data/mon.0/ceph.mon.keyring --gen-key -n mon. --cap mon 'allow *'
上面的命令生成keyring文件在/data/mon.0/ceph.mon.keyring,如果不配置monitor使用默認(rèn)keyring文件/data/mon.0/keyring,其中/data/mon.0是ceph.conf的mon data配置目錄
ceph auth get-or-create osd.0 mon 'allow rwx' osd 'allow *' -o /data/osd.0/keyring
上面命令生成osd的keyring
ceph auth get-or-create client.admin mds 'allow' osd 'allow *' mon 'allow *' > /etc/ceph/ceph.client.admin.keyring
上面命令生成client.admin的keyring,應(yīng)該為rados的訪問命令。
3、rados使用keyring訪問代碼示例
#include
#include
#include
rados_t cluster; //聲明 集群句柄
rados_ioctx_t io;
char *poolname = "data";
char cluster_name[] = "ceph";
char user_name[] = "client.admin"; //用戶名
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); //創(chuàng)建集群句柄
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");
}
//讀取配置文件,完成cluster句柄
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);
注意rados_conf_set兩行代碼,我使用的ceph_test.c編譯命令行
gcc ceph_test.c -o ceph_test -lrados
關(guān)于ceph中怎么配置集群訪問權(quán)限就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。