ceph-deploy new

来源:互联网 发布:做假化验单的软件 编辑:程序博客网 时间:2024/06/07 00:21
ceph-deploy new 命令用于开始部署新的集群,使用的例子如下:ceph-deploy new host-225 host-227 host-229执行成功后该目录下会增加三个文件[root@dn-5-221 ceph]# lltotal 12-rw-r--r-- 1 root root  276 Jun 26 22:01 ceph.conf-rw-r--r-- 1 root root 3142 Jun 26 22:01 ceph.log-rw------- 1 root root   73 Jun 26 22:01 ceph.mon.keyring这个命令的入口在E:\ceph-deploy-master\ceph-deploy-master\ceph_deploy\new.py 中的@priority(10)def make(parser):    """    Start deploying a new cluster, and write a CLUSTER.conf and keyring for it.    """    parser.add_argument(        'mon',        metavar='MON',        nargs='+',        help='initial monitor hostname, fqdn, or hostname:fqdn pair',        type=arg_validators.Hostname(),        )    parser.add_argument(        '--no-ssh-copykey',        dest='ssh_copykey',        action='store_false',        default=True,        help='do not attempt to copy SSH keys',    )    parser.add_argument(        '--fsid',        dest='fsid',        help='provide an alternate FSID for ceph.conf generation',    )    parser.add_argument(        '--cluster-network',        help='specify the (internal) cluster network',        type=arg_validators.Subnet(),    )    parser.add_argument(        '--public-network',        help='specify the public network for a cluster',        type=arg_validators.Subnet(),    )可以看到make函数只是帮new函数准备参数,最终执行new函数    parser.set_defaults(        func=new,        )可以看到new 命令支持no-ssh-copykey/fsid/cluster-network/public-network等参数。def new(args):    if args.ceph_conf:        raise RuntimeError('will not create a Ceph conf file if attemtping to re-use with `--ceph-conf` flag')    LOG.debug('Creating new cluster named %s', args.cluster)//在ceph.conf 中添加global section    cfg = conf.ceph.CephConf()    cfg.add_section('global')//在ceph.conf 中的global section 添加fsid。一般情况fsid等于uuid.uuid4()    fsid = args.fsid or uuid.uuid4()    cfg.set('global', 'fsid', str(fsid))    # if networks were passed in, lets set them in the    # global section    if args.public_network:        cfg.set('global', 'public network', str(args.public_network))    if args.cluster_network:        cfg.set('global', 'cluster network', str(args.cluster_network))// mon 节点    mon_initial_members = []// mon 主机    mon_host = []//遍历host    for (name, host) in mon_hosts(args.mon):        # Try to ensure we can ssh in properly before anything else//免密码登录,必须copy ssh keys        if args.ssh_copykey:            ssh_copy_keys(host, args.username)        # Now get the non-local IPs from the remote node//得到远程主机的ip,并连接到远程主机        distro = hosts.get(host, username=args.username)        remote_ips = net.ip_addresses(distro.conn)        # custom cluster names on sysvinit hosts won't work        if distro.init == 'sysvinit' and args.cluster != 'ceph':            LOG.error('custom cluster names are not supported on sysvinit hosts')            raise exc.ClusterNameError(                'host %s does not support custom cluster names' % host            )        distro.conn.exit()        # Validate subnets if we received any        if args.public_network or args.cluster_network:// 校验IP 地址            validate_host_ip(remote_ips, [args.public_network, args.cluster_network])        # Pick the IP that matches the public cluster (if we were told to do        # so) otherwise pick the first, non-local IP        LOG.debug('Resolving host %s', host)        if args.public_network:            ip = get_public_network_ip(remote_ips, args.public_network)        else:            ip = net.get_nonlocal_ip(host)        LOG.debug('Monitor %s at %s', name, ip)        mon_initial_members.append(name)        try:            socket.inet_pton(socket.AF_INET6, ip)            mon_host.append("[" + ip + "]")            LOG.info('Monitors are IPv6, binding Messenger traffic on IPv6')            cfg.set('global', 'ms bind ipv6', 'true')        except socket.error:            mon_host.append(ip)    LOG.debug('Monitor initial members are %s', mon_initial_members)    LOG.debug('Monitor addrs are %s', mon_host)//在ceph.conf 中的global section 添加mon_initial_members    cfg.set('global', 'mon initial members', ', '.join(mon_initial_members))    # no spaces here, see http://tracker.newdream.net/issues/3145//在ceph.conf 中的global section 添加mon_host    cfg.set('global', 'mon host', ','.join(mon_host))    # override undesirable defaults, needed until bobtail//在ceph.conf 中的global section 添加auth cluster required/auth service required/auth client required    # http://tracker.ceph.com/issues/6788    cfg.set('global', 'auth cluster required', 'cephx')    cfg.set('global', 'auth service required', 'cephx')    cfg.set('global', 'auth client required', 'cephx')    path = '{name}.conf'.format(        name=args.cluster,        )//生成ceph.mon.keyring 文件    new_mon_keyring(args)    LOG.debug('Writing initial config to %s...', path)    tmp = '%s.tmp' % path    with open(tmp, 'w') as f:// 保存ceph 配置文件,并重名为path,实际运行这里的path就是ceph.conf        cfg.write(f)    try:        os.rename(tmp, path)    except OSError as e:        if e.errno == errno.EEXIST:            raise exc.ClusterExistsError(path)        else:            raisedef new_mon_keyring(args):    LOG.debug('Creating a random mon key...')// 生成auth key的字符串    mon_keyring = '[mon.]\nkey = %s\ncaps mon = allow *\n' % generate_auth_key()    keypath = '{name}.mon.keyring'.format(        name=args.cluster,        )    oldmask = os.umask(0o77)    LOG.debug('Writing monitor keyring to %s...', keypath)    try:        tmp = '%s.tmp' % keypath//保存auth key 文件,并重名了,实际运行结果为ceph.mon.keyring        with open(tmp, 'w', 0o600) as f:            f.write(mon_keyring)        try:            os.rename(tmp, keypath)        except OSError as e:            if e.errno == errno.EEXIST:                raise exc.ClusterExistsError(keypath)            else:                raise    finally:        os.umask(oldmask)