Exemple #1
0
def install_mysql(root_pass):
    """
    Install the mysql through yum and config the mysql for cloudera manager
    @return:
    """
    logInfo("install the mysql through the yum", color='green')
    os.system('yum -y install mysql-server')

    logInfo("install the mysql-connector-java ", color='green')
    os.system('yum -y install mysql-connector-java')

    #create dir
    os.system("mkdir %s" % MYSQL_DATA_DIR)
    os.system("mkdir %s" % MYSQL_BINLOG_DIR)
    os.system("chown mysql:mysql %s" % MYSQL_BINLOG_DIR)

    logInfo("config the mysql for cloudera manager", color='green')

    binlog_conf = ""
    try:
        if is_os_gt5():
            binlog_conf = "binlog_format           = mixed"
        else:
            binlog_conf = ""
    except:
        pass

    mysql_conf = """
[mysqld]
transaction-isolation=READ-COMMITTED
datadir=%s
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
# symbolic-links=0

key_buffer              = 16M
key_buffer_size         = 32M
max_allowed_packet      = 16M
thread_stack            = 256K
thread_cache_size       = 64
query_cache_limit       = 8M
query_cache_size        = 64M
query_cache_type        = 1
# Important: see Configuring the Databases and Setting max_connections
max_connections         = 200

# log-bin should be on a disk with enough free space
log-bin=%s/mysql_binary_log
# For MySQL version 5.1.8 or later. Comment out binlog_format for older versions.

%s

read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 8M

# InnoDB settings
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit  = 2
innodb_log_buffer_size          = 64M
innodb_buffer_pool_size         = 1G
innodb_thread_concurrency       = 8
innodb_flush_method             = O_DIRECT
innodb_log_file_size = 512M

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
    """ % (MYSQL_DATA_DIR, MYSQL_BINLOG_DIR, binlog_conf)

    os.system("mv /etc/my.cnf /etc/my.cnf.bak")
    try:
        f = file('/etc/my.cnf', 'w')
        f.write(mysql_conf)
        f.close()
    except Exception, ex:
        logInfo("When config the mysql config file failed. and install will exit.", color='red')

        install.rollback_to_innit(root_pass)
        sys.exit(-1)
Exemple #2
0
            sftp = get_sftp(h, ssh_port, username, root_pass)
            # if target exists then remove it first
            try:
                sftp.remove(target)
            except:
                pass
                # upload the file
            sftp.put(source, target)
            sftp.close()

            ssh = ssh_connect(h, ssh_port, username, root_pass, timeout_=30)
            try:
                ssh.exec_command('mkdir /usr/java')
                ssh.exec_command('rm -rf /usr/java/%s' % jdk_unpack_name)
            except:
                pass
            stdin, stdout, stderr = ssh.exec_command('tar zxf %s -C /usr/java' % (target,))
            for o in stdout.readlines():
                pass

            ssh.exec_command('chmod 755 /usr/java/%s/bin/*' % (jdk_unpack_name,))
            ssh.close()
        except Exception, ex:
            err_hosts.append(h)
            logInfo("Upload the file: %s to %s as %s failed. info is: %s " % (source, h, target, ex.message,),
                    color='red')

    if len(err_hosts) != 0:
        logInfo("Dispatch the JDK in %s hosts failed, %s " % (err_hosts, EXIT_MSG,), color='red')
        install.rollback_to_innit(root_pass)
        sys.exit(-1)