def run():
    dbcfgs = json.loads(dbcfgs_json)

    if not os.path.exists(dbcfgs['hbase_lib_path']):
        err('Cannot find HBase lib folder')
    if not os.path.exists(dbcfgs['java_home']):
        err('Cannot find Java, please set the JAVA_HOME on the new nodes to: %s'
            % dbcfgs['java_home'])

    home_dir = get_default_home()
    if dbcfgs.has_key('home_dir'):
        home_dir = dbcfgs['home_dir']

    traf_user = dbcfgs['traf_user']
    traf_home = dbcfgs['traf_home']
    traf_user_dir = '%s/%s' % (home_dir, traf_user)

    traf_ver = dbcfgs['traf_version']
    #    scratch_locs = dbcfgs['scratch_locs'].split(',')

    SUDOER_CFG = """
## Allow trafodion id to run commands needed for backup and restore
%%%s ALL =(hbase) NOPASSWD: %s/bin/hbase"
""" % (traf_user, DEF_HBASE_HOME)

    ### add trafodion user ###
    # create trafodion user and group
    if cmd_output('getent passwd %s' % traf_user):
        print 'user [%s] exists' % traf_user
        # trafodion user exists, set actual trafodion group
        traf_group = cmd_output('id -ng %s' % traf_user)
    else:
        # default trafodion group
        traf_group = traf_user
        if not cmd_output('getent group %s' % traf_group):
            run_cmd('groupadd %s' % traf_group)
        traf_shadow = dbcfgs['traf_shadow']
        print 'Adding user [%s]' % traf_user
        run_cmd(
            'useradd --shell /bin/bash -m %s -g %s --home %s --password "%s"' %
            (traf_user, traf_group, traf_user_dir, traf_shadow))
        print 'Added user [%s]' % traf_user

    if not os.path.exists(traf_user_dir):
        run_cmd('mkdir -p %s' % traf_user_dir)
        run_cmd('chmod 700 %s' % traf_user_dir)

    ### untar the copied trafoion binaries ###
    TRAF_PKG_FILE = '/tmp/traf_bin.tar.gz'
    run_cmd('mkdir -p %s' % traf_home)
    run_cmd('mkdir -p /etc/trafodion')
    run_cmd('tar xf %s -C %s' % (TRAF_PKG_FILE, traf_home))

    run_cmd('mv -f /tmp/trafodion_config %s' % TRAF_CFG_FILE)
    run_cmd('cp -rf /tmp/.ssh %s/..' % traf_home)
    run_cmd('mv -f /tmp/hbase-trx-* %s' % dbcfgs['hbase_lib_path'])
    run_cmd('mv -f /tmp/trafodion-utility-* %s' % dbcfgs['hbase_lib_path'])

    ### copy trafodion bashrc ###
    bashrc_template = '%s/sysinstall/home/trafodion/.bashrc' % traf_home
    bashrc_file = '%s/%s/.bashrc' % (home_dir, traf_user)
    # backup orig bashrc
    if os.path.exists(bashrc_file):
        run_cmd('cp -f %s %s.bak' % (bashrc_file, bashrc_file))
    run_cmd('cp -f %s %s' % (bashrc_template, bashrc_file))

    # set permission
    run_cmd('chmod 700 %s/../.ssh' % traf_home)
    cmd_output('chmod 600 %s/../.ssh/{id_rsa,config,authorized_keys}' %
               traf_home)
    run_cmd('chmod 777 %s' % TRAF_CFG_FILE)
    run_cmd('chown -R %s:%s /etc/trafodion' % (traf_user, traf_group))
    run_cmd('chmod +r %s/{hbase-trx-*,trafodion-utility-*}' %
            dbcfgs['hbase_lib_path'])
    run_cmd('chown -R %s:%s %s' % (traf_user, traf_group, traf_user_dir))

    ### modify CLUSTERNAME ###
    mod_file(TRAF_CFG_FILE,
             {'CLUSTERNAME=.*': 'CLUSTERNAME=%s' % socket.gethostname()})

    ### kernel settings ###
    run_cmd('echo "kernel.pid_max=65535" >> /etc/sysctl.conf')
    run_cmd('echo "kernel.msgmnb=65536" >> /etc/sysctl.conf')
    run_cmd('echo "kernel.msgmax=65536" >> /etc/sysctl.conf')
    run_cmd('/sbin/sysctl -p /etc/sysctl.conf 2>&1 > /dev/null')

    ### copy init script ###
    init_script = '%s/sysinstall/etc/init.d/trafodion' % traf_home
    if os.path.exists(init_script):
        run_cmd('cp -rf %s /etc/init.d/' % init_script)
        run_cmd('chkconfig --add trafodion')
        run_cmd('chkconfig --level 06 trafodion on')

    ### create and set permission for scratch file dir ###
#    for loc in scratch_locs:
#        # don't set permission for HOME folder
#        if not os.path.exists(loc):
#            run_cmd('mkdir -p %s' % loc)
#        if home_dir not in loc:
#            run_cmd('chmod 777 %s' % loc)

    if dbcfgs['enable_ha'] == 'true':
        # set trafodion sudoer file for specific cmds
        SUDOER_CFG += """
## Trafodion Floating IP commands
Cmnd_Alias IP = /sbin/ip
Cmnd_Alias ARP = /sbin/arping

## Allow Trafodion id to run commands needed to configure floating IP
%%%s ALL = NOPASSWD: IP, ARP
""" % traf_user

    ### write trafodion sudoer file ###
    with open(TRAF_SUDOER_FILE, 'w') as f:
        f.write(SUDOER_CFG)

    # set ulimits for trafodion user
    ulimits_file = '/etc/security/limits.d/%s.conf' % traf_user
    ulimits_config = '''
# Trafodion settings
%s   soft   core unlimited
%s   hard   core unlimited
%s   soft   memlock unlimited
%s   hard   memlock unlimited
%s   soft   nofile 32768
%s   hard   nofile 65536
%s   soft   nproc 100000
%s   hard   nproc 100000
''' % ((traf_user, ) * 8)

    write_file(ulimits_file, ulimits_config)
Ejemplo n.º 2
0
def run():
    dbcfgs = json.loads(dbcfgs_json)

    home_dir = get_default_home()
    if dbcfgs.has_key('home_dir'):
        home_dir = dbcfgs['home_dir']

    traf_user = dbcfgs['traf_user']
    traf_dirname = dbcfgs['traf_dirname']
    traf_home = '%s/%s/%s' % (home_dir, traf_user, traf_dirname)

    traf_ver = dbcfgs['traf_version']
    distro = dbcfgs['distro']
    traf_lib_path = traf_home + '/export/lib'
    scratch_locs = dbcfgs['scratch_locs'].split(',')

    SUDOER_CFG = """
## Allow trafodion id to run commands needed for backup and restore
%%%s ALL =(hbase) NOPASSWD: %s/bin/hbase"
""" % (traf_user, DEF_HBASE_HOME)

    ### kernel settings ###
    run_cmd('sysctl -w kernel.pid_max=65535 2>&1 > /dev/null')
    run_cmd('echo "kernel.pid_max=65535" >> /etc/sysctl.conf')

    ### copy trafodion bashrc ###
    bashrc_template = '%s/sysinstall/home/trafodion/.bashrc' % traf_home
    bashrc_file = '%s/%s/.bashrc' % (home_dir, traf_user)
    # backup orig bashrc
    if os.path.exists(bashrc_file):
        run_cmd('cp -f %s %s.bak' % (bashrc_file, bashrc_file))
    run_cmd('cp -f %s %s' % (bashrc_template, bashrc_file))
    run_cmd('chown -R %s:%s %s*' % (traf_user, traf_user, bashrc_file))

    ### copy init script ###
    init_script = '%s/sysinstall/etc/init.d/trafodion' % traf_home
    if os.path.exists(init_script):
        run_cmd('cp -rf %s /etc/init.d/' % init_script)
        run_cmd('chkconfig --add trafodion')
        run_cmd('chkconfig --level 06 trafodion on')

    ### create and set permission for scratch file dir ###
    for loc in scratch_locs:
        # expand any shell variables
        locpath = cmd_output('source %s ; echo %s' % (TRAF_CFG_FILE,loc))
        if not os.path.exists(locpath):
            run_cmd('mkdir -p %s' % locpath)
            run_cmd('chown %s %s' % (traf_user,locpath))

    ### copy jar files ###
    hbase_lib_path = dbcfgs['hbase_lib_path']
    if 'APACHE' in distro:
        distro += dbcfgs['hbase_ver']

    distro, v1, v2 = re.search(r'(\w+)-*(\d)\.(\d)', distro).groups()
    if distro == 'CDH':
        if v2 == '6': v2 = '5'
        if v2 == '8': v2 = '7'
    elif distro == 'HDP':
        if v2 == '4': v2 = '3'

    hbase_trx_jar = 'hbase-trx-%s%s_%s-%s.jar' % (distro.lower(), v1, v2, traf_ver)
    traf_hbase_trx_path = '%s/%s' % (traf_lib_path, hbase_trx_jar)
    hbase_trx_path = '%s/%s' % (hbase_lib_path, hbase_trx_jar)
    if not os.path.exists(traf_hbase_trx_path):
        err('Cannot find HBase trx jar \'%s\' for your Hadoop distribution' % hbase_trx_jar)

    # reinstall mode, check if existing trx jar doesn't match the new trx jar file
    if dbcfgs.has_key('reinstall') and dbcfgs['reinstall'].upper() == 'Y':
        if not os.path.exists(hbase_trx_path):
            err('The trx jar \'%s\' doesn\'t exist in hbase lib path, cannot do reinstall, please do regular install' % hbase_trx_jar)
    else:
        # remove old trx and trafodion-utility jar files
        run_cmd('rm -rf %s/{hbase-trx-*,trafodion-utility-*}' % hbase_lib_path)

        # copy new ones
        run_cmd('cp %s %s' % (traf_hbase_trx_path, hbase_lib_path))
        run_cmd('cp %s/trafodion-utility-* %s' % (traf_lib_path, hbase_lib_path))

    # set permission
    run_cmd('chmod +r %s/{hbase-trx-*,trafodion-utility-*}' % hbase_lib_path)

    if dbcfgs['dcs_ha'] == 'Y':
        # set trafodion sudoer file for specific cmds
        SUDOER_CFG += """
## Trafodion Floating IP commands
Cmnd_Alias IP = /sbin/ip
Cmnd_Alias ARP = /sbin/arping

## Allow Trafodion id to run commands needed to configure floating IP
%%%s ALL = NOPASSWD: IP, ARP
""" % traf_user

    ### write trafodion sudoer file ###
    with open(TRAF_SUDOER_FILE, 'w') as f:
        f.write(SUDOER_CFG)
Ejemplo n.º 3
0
def run():
    dbcfgs = json.loads(dbcfgs_json)

    home_dir = get_default_home()
    if dbcfgs.has_key('home_dir'):
        home_dir = dbcfgs['home_dir']

    traf_user = dbcfgs['traf_user']
    traf_dirname = dbcfgs['traf_dirname']
    traf_home = '%s/%s/%s' % (home_dir, traf_user, traf_dirname)

    traf_ver = dbcfgs['traf_version']
    distro = dbcfgs['distro']
    traf_lib_path = traf_home + '/export/lib'
    scratch_locs = dbcfgs['scratch_locs'].split(',')

    SUDOER_CFG = """
## Allow trafodion id to run commands needed for backup and restore
%%%s ALL =(hbase) NOPASSWD: %s/bin/hbase"
""" % (traf_user, DEF_HBASE_HOME)

    ### kernel settings ###
    run_cmd('sysctl -w kernel.pid_max=65535 2>&1 > /dev/null')
    run_cmd('echo "kernel.pid_max=65535" >> /etc/sysctl.conf')

    ### copy trafodion bashrc ###
    bashrc_template = '%s/sysinstall/home/trafodion/.bashrc' % traf_home
    bashrc_file = '%s/%s/.bashrc' % (home_dir, traf_user)
    # backup orig bashrc
    if os.path.exists(bashrc_file):
        run_cmd('cp -f %s %s.bak' % (bashrc_file, bashrc_file))
    run_cmd('cp -f %s %s' % (bashrc_template, bashrc_file))
    run_cmd('chown -R %s:%s %s*' % (traf_user, traf_user, bashrc_file))

    ### copy init script ###
    init_script = '%s/sysinstall/etc/init.d/trafodion' % traf_home
    if os.path.exists(init_script):
        run_cmd('cp -rf %s /etc/init.d/' % init_script)
        run_cmd('chkconfig --add trafodion')
        run_cmd('chkconfig --level 06 trafodion on')

    ### create and set permission for scratch file dir ###
    for loc in scratch_locs:
        # expand any shell variables
        locpath = cmd_output('source %s ; echo %s' % (TRAF_CFG_FILE, loc))
        if not os.path.exists(locpath):
            run_cmd('mkdir -p %s' % locpath)
            run_cmd('chown %s %s' % (traf_user, locpath))

    ### copy jar files ###
    hbase_lib_path = dbcfgs['hbase_lib_path']
    if 'APACHE' in distro:
        distro += dbcfgs['hbase_ver']

    distro, v1, v2 = re.search(r'(\w+)-*(\d)\.(\d)', distro).groups()
    if distro == 'CDH':
        if v2 == '6': v2 = '5'
        if v2 == '8': v2 = '7'
    elif distro == 'HDP':
        if v2 == '4': v2 = '3'

    hbase_trx_jar = 'hbase-trx-%s%s_%s-%s.jar' % (distro.lower(), v1, v2,
                                                  traf_ver)
    traf_hbase_trx_path = '%s/%s' % (traf_lib_path, hbase_trx_jar)
    hbase_trx_path = '%s/%s' % (hbase_lib_path, hbase_trx_jar)
    if not os.path.exists(traf_hbase_trx_path):
        err('Cannot find HBase trx jar \'%s\' for your Hadoop distribution' %
            hbase_trx_jar)

    # reinstall mode, check if existing trx jar doesn't match the new trx jar file
    if dbcfgs.has_key('reinstall') and dbcfgs['reinstall'].upper() == 'Y':
        if not os.path.exists(hbase_trx_path):
            err('The trx jar \'%s\' doesn\'t exist in hbase lib path, cannot do reinstall, please do regular install'
                % hbase_trx_jar)
    else:
        # remove old trx and trafodion-utility jar files
        run_cmd('rm -rf %s/{hbase-trx-*,trafodion-utility-*}' % hbase_lib_path)

        # copy new ones
        run_cmd('cp %s %s' % (traf_hbase_trx_path, hbase_lib_path))
        run_cmd('cp %s/trafodion-utility-* %s' %
                (traf_lib_path, hbase_lib_path))

    # set permission
    run_cmd('chmod +r %s/{hbase-trx-*,trafodion-utility-*}' % hbase_lib_path)

    if dbcfgs['dcs_ha'] == 'Y':
        # set trafodion sudoer file for specific cmds
        SUDOER_CFG += """
## Trafodion Floating IP commands
Cmnd_Alias IP = /sbin/ip
Cmnd_Alias ARP = /sbin/arping

## Allow Trafodion id to run commands needed to configure floating IP
%%%s ALL = NOPASSWD: IP, ARP
""" % traf_user

    ### write trafodion sudoer file ###
    with open(TRAF_SUDOER_FILE, 'w') as f:
        f.write(SUDOER_CFG)
Ejemplo n.º 4
0
def run():
    """ create trafodion user, bashrc, setup passwordless SSH """
    dbcfgs = json.loads(dbcfgs_json)

    distro = dbcfgs['distro']
    if 'CDH' in distro:
        hadoop_type = 'cloudera'
    elif 'HDP' in distro:
        hadoop_type = 'hortonworks'
    elif 'APACHE' in distro:
        hadoop_type = 'apache'

    home_dir = get_default_home()
    # customize trafodion home dir
    if dbcfgs.has_key('home_dir') and dbcfgs['home_dir']:
        home_dir = dbcfgs['home_dir']

    traf_user = dbcfgs['traf_user']
    traf_user_dir = '%s/%s' % (home_dir, traf_user)
    traf_dirname = dbcfgs['traf_dirname']
    traf_home = '%s/%s' % (traf_user_dir, traf_dirname)
    traf_log = dbcfgs['traf_log']
    traf_var = dbcfgs['traf_var']

    hbase_xml_file = dbcfgs['hbase_xml_file']
    auth_key_file = '%s/.ssh/authorized_keys' % traf_user_dir
    ssh_cfg_file = '%s/.ssh/config' % traf_user_dir
    ulimits_file = '/etc/security/limits.d/%s.conf' % traf_user

    # create trafodion user and group
    if cmd_output('getent passwd %s' % traf_user):
        # trafodion user exists, set actual trafodion group
        traf_group = cmd_output('id -ng %s' % traf_user)
    else:
        # default trafodion group
        traf_group = traf_user
        if not cmd_output('getent group %s' % traf_group):
            run_cmd('groupadd %s > /dev/null 2>&1' % traf_group)
        traf_pwd = dbcfgs['traf_pwd']
        run_cmd('useradd --shell /bin/bash -m %s -g %s --home %s --password "$(openssl passwd %s)"' % (traf_user, traf_group, traf_user_dir, traf_pwd))
    # hbase group is generally either hbase or hadoop, depending on distro
    if cmd_output('getent group hbase'):
        cmd_output('/usr/sbin/usermod -a -G hbase %s' % traf_user)
    if cmd_output('getent group hadoop'):
        cmd_output('/usr/sbin/usermod -a -G hadoop %s' % traf_user)
    if cmd_output('getent group hive'):
        cmd_output('/usr/sbin/usermod -a -G hive %s' % traf_user)

    if not os.path.exists(traf_user_dir):
        run_cmd('mkdir -p %s' % traf_user_dir)
        run_cmd('chmod 700 %s' % traf_user_dir)

    # set ssh key
    run_cmd_as_user(traf_user, 'echo -e "y" | ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa')
    # the key is generated in copy_file script running on the installer node
    run_cmd('cp %s{,.pub} %s/.ssh/' % (SSHKEY_FILE, traf_user_dir))

    run_cmd_as_user(traf_user, 'cat ~/.ssh/id_rsa.pub > %s' % auth_key_file)
    run_cmd('chmod 644 %s' % auth_key_file)

    ssh_cfg = 'StrictHostKeyChecking=no\nNoHostAuthenticationForLocalhost=yes\n'
    with open(ssh_cfg_file, 'w') as f:
        f.write(ssh_cfg)
    run_cmd('chmod 600 %s' % ssh_cfg_file)

    run_cmd('chown -R %s:%s %s/.ssh/' % (traf_user, traf_group, traf_user_dir))

    hb = ParseXML(hbase_xml_file)
    zk_nodes = hb.get_property('hbase.zookeeper.quorum')
    zk_port = hb.get_property('hbase.zookeeper.property.clientPort')
    # set trafodion_config
    nodes = dbcfgs['node_list'].split(',')
    trafodion_config = """
export TRAF_HOME="%s"
export TRAF_VAR="%s"
export TRAF_CONF="%s"
export TRAF_LOG="%s"
export JAVA_HOME="%s"
export node_count="%s"
export HADOOP_TYPE="%s"
export ENABLE_HA="%s"
export ZOOKEEPER_NODES="%s"
export ZOOKEEPER_PORT="%s"
export SECURE_HADOOP="%s"
export CLUSTERNAME="%s"
""" % (traf_home, traf_var, TRAF_CFG_DIR, traf_log, dbcfgs['java_home'], str(len(nodes)), hadoop_type, dbcfgs['enable_ha'],
       zk_nodes, zk_port, dbcfgs['secure_hadoop'], socket.gethostname())

    # save additonal configs for elastic
    trafodion_config += """
export hbase_xml_file="%s"
export hbase_lib_path="%s"
export traf_user="******"
export traf_version="%s"
export dcs_cnt_per_node="%s"
""" % (dbcfgs['hbase_xml_file'], dbcfgs['hbase_lib_path'], dbcfgs['traf_user'], dbcfgs['traf_version'], dbcfgs['dcs_cnt_per_node'])

    # save additonal configs for multi instance support
    trafodion_config += """
export TRAF_CLUSTER_NAME="%s"
export TRAF_INSTANCE_NAME="%s"
export TRAF_CLUSTER_ID="%s"
export TRAF_INSTANCE_ID="%s"
export TRAF_ROOT_ZNODE="/%s"
""" % (dbcfgs['cluster_name'], dbcfgs['traf_instance_name'], dbcfgs['traf_cluster_id'], dbcfgs['traf_instance_id'], dbcfgs['traf_user'])

    run_cmd('mkdir -p %s' % TRAF_CFG_DIR)
    write_file(TRAF_CFG_FILE, trafodion_config)

    if 'APACHE' in distro:
        extra_config = """
export HADOOP_PREFIX=%s
export HBASE_HOME=%s
export HIVE_HOME=%s
export PATH=$PATH:$HADOOP_PREFIX/bin:$HADOOP_PREFIX/sbin:$HBASE_HOME/bin
        """ % (dbcfgs['hadoop_home'], dbcfgs['hbase_home'], dbcfgs['hive_home'])
        append_file(TRAFODION_CFG_FILE, extra_config)

    # set permission
    run_cmd('chown -R %s:%s %s*' % (traf_user, traf_group, TRAF_CFG_DIR))

    # set ulimits for trafodion user
    ulimits_config = '''
# Trafodion settings
%s   soft   core unlimited
%s   hard   core unlimited
%s   soft   memlock unlimited
%s   hard   memlock unlimited
%s   soft   nofile 32768
%s   hard   nofile 65536
%s   soft   nproc 100000
%s   hard   nproc 100000
%s   soft nofile 8192
%s   hard nofile 65535
''' % ((traf_user,) * 10)

    write_file(ulimits_file, ulimits_config)

    # change permission for hsperfdata
    if os.path.exists(TRAF_HSPERFDATA_FILE):
        run_cmd('chown -R %s:%s %s' % (traf_user, traf_group, TRAF_HSPERFDATA_FILE))

    # clean up unused key file at the last step
    run_cmd('rm -rf %s{,.pub}' % SSHKEY_FILE)

    print 'Setup trafodion user successfully!'
Ejemplo n.º 5
0
def run():
    """ create trafodion user, bashrc, setup passwordless SSH """
    dbcfgs = json.loads(dbcfgs_json)

    distro = dbcfgs['distro']
    if 'CDH' in distro:
        hadoop_type = 'cloudera'
    elif 'HDP' in distro:
        hadoop_type = 'hortonworks'
    elif 'APACHE' in distro:
        hadoop_type = 'apache'

    home_dir = get_default_home()
    # customize trafodion home dir
    if dbcfgs.has_key('home_dir') and dbcfgs['home_dir']:
        home_dir = dbcfgs['home_dir']

    traf_user = dbcfgs['traf_user']
    traf_user_dir = '%s/%s' % (home_dir, traf_user)
    traf_dirname = dbcfgs['traf_dirname']
    traf_home = '%s/%s' % (traf_user_dir, traf_dirname)

    hbase_xml_file = dbcfgs['hbase_xml_file']
    auth_key_file = '%s/.ssh/authorized_keys' % traf_user_dir
    ssh_cfg_file = '%s/.ssh/config' % traf_user_dir
    ulimits_file = '/etc/security/limits.d/%s.conf' % traf_user

    # create trafodion user and group
    if cmd_output('getent passwd %s' % traf_user):
        # trafodion user exists, set actual trafodion group
        traf_group = cmd_output('id -ng %s' % traf_user)
    else:
        # default trafodion group
        traf_group = traf_user
        if not cmd_output('getent group %s' % traf_group):
            run_cmd('groupadd %s > /dev/null 2>&1' % traf_group)
        traf_pwd = dbcfgs['traf_pwd']
        run_cmd('useradd --shell /bin/bash -m %s -g %s --home %s --password "$(openssl passwd %s)"' % (traf_user, traf_group, traf_user_dir, traf_pwd))
    # hbase group is generally either hbase or hadoop, depending on distro
    if cmd_output('getent group hbase'):
        cmd_output('/usr/sbin/usermod -a -G hbase %s' % traf_user)
    if cmd_output('getent group hadoop'):
        cmd_output('/usr/sbin/usermod -a -G hadoop %s' % traf_user)
    if cmd_output('getent group hive'):
        cmd_output('/usr/sbin/usermod -a -G hive %s' % traf_user)

    if not os.path.exists(traf_user_dir):
        run_cmd('mkdir -p %s' % traf_user_dir)
        run_cmd('chmod 700 %s' % traf_user_dir)

    # set ssh key
    run_cmd_as_user(traf_user, 'echo -e "y" | ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa')
    # the key is generated in copy_file script running on the installer node
    run_cmd('cp %s{,.pub} %s/.ssh/' % (SSHKEY_FILE, traf_user_dir))

    run_cmd_as_user(traf_user, 'cat ~/.ssh/id_rsa.pub > %s' % auth_key_file)
    run_cmd('chmod 644 %s' % auth_key_file)

    ssh_cfg = 'StrictHostKeyChecking=no\nNoHostAuthenticationForLocalhost=yes\n'
    with open(ssh_cfg_file, 'w') as f:
        f.write(ssh_cfg)
    run_cmd('chmod 600 %s' % ssh_cfg_file)

    run_cmd('chown -R %s:%s %s/.ssh/' % (traf_user, traf_group, traf_user_dir))

    hb = ParseXML(hbase_xml_file)
    zk_nodes = hb.get_property('hbase.zookeeper.quorum')
    zk_port = hb.get_property('hbase.zookeeper.property.clientPort')
    # set trafodion_config
    nodes = dbcfgs['node_list'].split(',')
    trafodion_config = """
export TRAF_HOME="%s"
export TRAF_VAR=$TRAF_HOME/tmp
export MY_SQROOT=$TRAF_HOME # for compatibility
export JAVA_HOME="%s"
export node_count="%s"
export HADOOP_TYPE="%s"
export ENABLE_HA="%s"
export ZOOKEEPER_NODES="%s"
export ZOOKEEPER_PORT="%s"
export SECURE_HADOOP="%s"
export CLUSTERNAME="%s"
""" % (traf_home, dbcfgs['java_home'], str(len(nodes)), hadoop_type, dbcfgs['enable_ha'],
       zk_nodes, zk_port, dbcfgs['secure_hadoop'], socket.gethostname())

    # save additonal configs for elastic
    trafodion_config += """
export hbase_xml_file="%s"
export hbase_lib_path="%s"
export traf_user="******"
export traf_version="%s"
export dcs_cnt_per_node="%s"
""" % (dbcfgs['hbase_xml_file'], dbcfgs['hbase_lib_path'], dbcfgs['traf_user'], dbcfgs['traf_version'], dbcfgs['dcs_cnt_per_node'])

    run_cmd('mkdir -p %s' % TRAF_CFG_DIR)
    write_file(TRAF_CFG_FILE, trafodion_config)

    if 'APACHE' in distro:
        extra_config = """
export HADOOP_PREFIX=%s
export HBASE_HOME=%s
export HIVE_HOME=%s
export PATH=$PATH:$HADOOP_PREFIX/bin:$HADOOP_PREFIX/sbin:$HBASE_HOME/bin
        """ % (dbcfgs['hadoop_home'], dbcfgs['hbase_home'], dbcfgs['hive_home'])
        append_file(TRAFODION_CFG_FILE, extra_config)

    # set permission
    run_cmd('chown -R %s:%s %s*' % (traf_user, traf_group, TRAF_CFG_DIR))

    # set ulimits for trafodion user
    ulimits_config = '''
# Trafodion settings
%s   soft   core unlimited
%s   hard   core unlimited
%s   soft   memlock unlimited
%s   hard   memlock unlimited
%s   soft   nofile 32768
%s   hard   nofile 65536
%s   soft   nproc 100000
%s   hard   nproc 100000
%s   soft nofile 8192
%s   hard nofile 65535
''' % ((traf_user,) * 10)

    write_file(ulimits_file, ulimits_config)

    # change permission for hsperfdata
    if os.path.exists(TRAF_HSPERFDATA_FILE):
        run_cmd('chown -R %s:%s %s' % (traf_user, traf_group, TRAF_HSPERFDATA_FILE))

    # clean up unused key file at the last step
    run_cmd('rm -rf %s{,.pub}' % SSHKEY_FILE)

    print 'Setup trafodion user successfully!'