def install_logmgmt(args): ''' Install and configure log management tools on the local host. ''' app.print_verbose("Install LogManagement version: %d" % SCRIPT_VERSION) version_obj = version.Version("InstallLogMgmt", SCRIPT_VERSION) version_obj.check_executed() x("mkdir -p /var/lib/logmgmt") shutil.copy(app.SYCO_PATH + "var/logmgmt/compress_logs.sh", "/var/lib/logmgmt/") x("chmod +x /var/lib/logmgmt/compress_logs.sh") shutil.copy(app.SYCO_PATH + "var/logmgmt/logmgmt_cron", "/etc/cron.daily/") x("chmod +x /etc/cron.daily/logmgmt_cron") logMgmtCron = scOpen("/etc/cron.daily/logmgmt_cron") logMgmtCron.replace("${alert_email}",config.general.get_admin_email()) x("yum -y install php") x("yum -y install php-mysql") x("yum -y install php-gd") x("cd /tmp/; wget http://download.adiscon.com/loganalyzer/loganalyzer-3.5.6.tar.gz") x("cd /tmp; tar xzf loganalyzer-3.5.6.tar.gz") x("cp -rp /tmp/loganalyzer-3.5.6/src /var/www/html/loganalyzer") x("chown -R apache /var/www/html/loganalyzer") shutil.copy(app.SYCO_PATH + "var/logmgmt/config.php", "/var/www/html/loganalyzer/") logConfig = scOpen("/var/www/html/loganalyzer/config.php") logConfig.replace("${mysql_user}","root") logConfig.replace("${mysql_password}",app.get_mysql_root_password()) x("chown -R apache /var/www/html/loganalyzer") x("rm -rf /tmp/loganalyzer*") shutil.copy(app.SYCO_PATH + "var/logmgmt/remove_sql.sh", "/var/lib/logmgmt/") x("chmod +x /var/lib/logmgmt/remove_sql.sh") logSql = scOpen("/var/lib/logmgmt/remove_sql.sh") logSql.replace("${mysql_user}","root") logSql.replace("${mysql_password}",app.get_mysql_root_password()) shutil.copy(app.SYCO_PATH + "var/logmgmt/loganalyzer.conf", "/etc/httpd/conf.d/") htconf = scOpen("/etc/httpd/conf.d/loganalyzer.conf") htconf.replace("${bind_dn}","cn=sssd,%s" % config.general.get_ldap_dn() ) htconf.replace("${bind_password}","%s" % app.get_ldap_sssd_password() ) htconf.replace("${ldap_url}","ldaps://%s:636/%s?uid" % (config.general.get_ldap_hostname(),config.general.get_ldap_dn()) ) x("service httpd restart") version_obj.mark_executed()
def install_logmgmt(args): ''' Install and configure log management tools on the local host. ''' app.print_verbose("Install LogManagement version: %d" % SCRIPT_VERSION) version_obj = version.Version("InstallLogMgmt", SCRIPT_VERSION) version_obj.check_executed() x("mkdir -p /var/lib/logmgmt") shutil.copy(app.SYCO_PATH + "var/logmgmt/compress_logs.sh", "/var/lib/logmgmt/") x("chmod +x /var/lib/logmgmt/compress_logs.sh") shutil.copy(app.SYCO_PATH + "var/logmgmt/logmgmt_cron", "/etc/cron.daily/") x("chmod +x /etc/cron.daily/logmgmt_cron") logMgmtCron = scOpen("/etc/cron.daily/logmgmt_cron") logMgmtCron.replace("${alert_email}", config.general.get_admin_email()) x("yum -y install php") x("yum -y install php-mysql") x("yum -y install php-gd") x("cd /tmp/; wget http://download.adiscon.com/loganalyzer/loganalyzer-3.5.6.tar.gz" ) x("cd /tmp; tar xzf loganalyzer-3.5.6.tar.gz") x("cp -rp /tmp/loganalyzer-3.5.6/src /var/www/html/loganalyzer") x("chown -R apache /var/www/html/loganalyzer") shutil.copy(app.SYCO_PATH + "var/logmgmt/config.php", "/var/www/html/loganalyzer/") logConfig = scOpen("/var/www/html/loganalyzer/config.php") logConfig.replace("${mysql_user}", "root") logConfig.replace("${mysql_password}", app.get_mysql_root_password()) x("chown -R apache /var/www/html/loganalyzer") x("rm -rf /tmp/loganalyzer*") shutil.copy(app.SYCO_PATH + "var/logmgmt/remove_sql.sh", "/var/lib/logmgmt/") x("chmod +x /var/lib/logmgmt/remove_sql.sh") logSql = scOpen("/var/lib/logmgmt/remove_sql.sh") logSql.replace("${mysql_user}", "root") logSql.replace("${mysql_password}", app.get_mysql_root_password()) shutil.copy(app.SYCO_PATH + "var/logmgmt/loganalyzer.conf", "/etc/httpd/conf.d/") htconf = scOpen("/etc/httpd/conf.d/loganalyzer.conf") htconf.replace("${bind_dn}", "cn=sssd,%s" % config.general.get_ldap_dn()) htconf.replace("${bind_password}", "%s" % app.get_ldap_sssd_password()) htconf.replace( "${ldap_url}", "ldaps://%s:636/%s?uid" % (config.general.get_ldap_hostname(), config.general.get_ldap_dn())) x("service httpd restart") version_obj.mark_executed()
def passwords(args): app.print_verbose("Set all passwords used by syco") app.init_all_passwords() print "root: ", app.get_root_password() print "svn: ", app.get_svn_password() print "ldap_admin: ", app.get_ldap_admin_password() print "ldap_sssd: ", app.get_ldap_sssd_password() print "glassfish_master: ", app.get_glassfish_master_password() print "glassfish_admin: ", app.get_glassfish_admin_password() print "glassfish_user: "******"glassfish") print "mysql_root: ", app.get_mysql_root_password() print "mysql_int: ", app.get_mysql_integration_password() print "mysql_stable: ", app.get_mysql_stable_password() print "mysql_uat: ", app.get_mysql_uat_password() print "mysql_prod: ", app.get_mysql_production_password()
def install_mysql_backup(args): """ Create file required to login to mysql without a password. This file is used by mysql-lvm-backup. """ fn = "/root/.my.cnf" contents = """ [client] user=root password="******" """ % (app.get_mysql_root_password()) scOpen(fn).add(contents) x("chown root:root %s" % fn) x("chmod 600 %s" % fn)
def passwords(args): app.print_verbose("Set all passwords used by syco") app.init_all_passwords() print "root: ", app.get_root_password() print "svn: ", app.get_svn_password() print "ldap_admin: ", app.get_ldap_admin_password() print "ldap_sssd: ", app.get_ldap_sssd_password() print "glassfish_master: ", app.get_glassfish_master_password() print "glassfish_admin: ", app.get_glassfish_admin_password() print "glassfish_user: "******"glassfish") print "mysql_root: ", app.get_mysql_root_password() print "mysql_int: ", app.get_mysql_integration_password() print "mysql_stable: ", app.get_mysql_stable_password() print "mysql_uat: ", app.get_mysql_uat_password() print "mysql_prod: ", app.get_mysql_production_password() print "mysql_backup: ", app.get_mysql_backup_password() print "mysql_monitor: ", app.get_mysql_monitor_password() print "switch_icmp: ", app.get_switch_icmp_password()
def mysql_exec(command, with_user=False, host="127.0.0.1"): ''' Execute a MySQL query, through the command line mysql console. todo: Don't send password on command line. ''' command = command.replace('\\', '\\\\') command = command.replace('"', r'\"') cmd="mysql " if (host): cmd+= "-h" + host + " " if (with_user): cmd+='-uroot -p"' + app.get_mysql_root_password() + '" ' return x(cmd + '-e "' + command + '"')
def mysql_exec(command, with_user=False, host="127.0.0.1"): ''' Execute a MySQL query, through the command line mysql console. todo: Don't send password on command line. ''' command = command.replace('\\', '\\\\') command = command.replace('"', r'\"') cmd = "mysql " if (host): cmd += "-h" + host + " " if (with_user): cmd += '-uroot -p"' + app.get_mysql_root_password() + '" ' return x(cmd + '-e "' + command + '"')
def mysql_exec(command, with_user=False, host="127.0.0.1", escape=True): ''' Execute a MySQL query, through the command line mysql console. todo: Don't send password on command line. ''' if escape: command = command.replace('\\', '\\\\') command = command.replace('"', r'\"') cmd="mysql " if (host): cmd+= "-h" + host + " " if (with_user): cmd+='-uroot -p"{0}" '.format(app.get_mysql_root_password()) return x(cmd + '-e "{0}"'.format(command))
def mysql_exec(command, with_user=False, host="127.0.0.1", escape=True): """ Execute a MySQL query, through the command line mysql console. todo: Don't send password on command line. """ if escape: command = command.replace('\\', '\\\\') command = command.replace('"', r'\"') cmd = "mysql " if host: cmd += "-h" + host + " " if with_user: cmd += '-uroot -p"{0}" '.format(app.get_mysql_root_password()) return x(cmd + '-e "{0}"'.format(command))
def install_mysql(args): ''' Install and configure the mysql-server on the local host. ''' app.print_verbose("Install mysql version: %d" % SCRIPT_VERSION) version_obj = version.Version("InstallMysql", SCRIPT_VERSION) version_obj.check_executed() if (len(args) != 3): raise Exception("syco install-mysql [server-id] [innodb-buffer-pool-size]") server_id=args[1] innodb_buffer_pool_size=args[2] # Initialize all passwords used by the script app.init_mysql_passwords() # Install the mysql-server packages. if (not os.access("/usr/bin/mysqld_safe", os.W_OK|os.X_OK)): x("yum -y install mysql-server hdparm") x("/sbin/chkconfig mysqld on ") if (not os.access("/usr/bin/mysqld_safe", os.F_OK)): raise Exception("Couldn't install mysql-server") # Configure iptables iptables.add_mysql_chain() iptables.save() # Disable mysql history logging if (os.access("/root/.mysql_history", os.F_OK)): x("rm /root/.mysql_history") x("ln -s /dev/null /root/.mysql_history") # Used to log slow queries, configed in my.cnf with log-slow-queries= x("touch /var/log/mysqld-slow.log") x("chown mysql:mysql /var/log/mysqld-slow.log") x("chmod 0640 /var/log/mysqld-slow.log") x("chcon system_u:object_r:mysqld_log_t:s0 /var/log/mysqld-slow.log") # Not used at the moment, just preventing mysql to load any modules. if (not os.access("/usr/share/mysql/plugins", os.W_OK|os.X_OK)): os.mkdir("/usr/share/mysql/plugins") os.chmod("/usr/share/mysql/plugins", 0) os.chown("/usr/share/mysql/plugins", 0, 0) # Under Linux, it is advisable to disable the write-back cache. Otherwise data # can get lost when computer get power-failures. Beware that some drives or # disk controllers may be unable to disable the write-back cache. # # TODO: Might need to be done from bios? x("hdparm -W0 /dev/mapper/VolGroup00-var") app.print_verbose("Install /etc/my.cnf") shutil.copy(app.SYCO_PATH + "var/mysql/my.cnf", "/etc/my.cnf") for line in fileinput.FileInput("/etc/my.cnf", inplace=1): line=line.replace("${server-id}", server_id) line=line.replace("${innodb_buffer_pool_size}", innodb_buffer_pool_size) print line, # When the innodb files are configured to be large, it takes some time to # generate the files. app.print_verbose("Increaste timeout for /etc/init.d/mysqld to 120 seconds.") for line in fileinput.FileInput("/etc/init.d/mysqld", inplace=1): line=line.replace("STARTTIMEOUT=30", "STARTTIMEOUT=120") print line, x("service mysqld start") # Secure the mysql installation. mysql_exec("truncate mysql.db") mysql_exec("truncate mysql.user") mysql_exec("GRANT ALL PRIVILEGES ON *.* " + "TO 'root'@'127.0.0.1' " + "IDENTIFIED BY '" + app.get_mysql_root_password() + "', " "'root'@'localhost' " + "IDENTIFIED BY '" + app.get_mysql_root_password() + "', " "'root'@'" + config.general.get_mysql_primary_master_ip() + "' " + "IDENTIFIED BY '" + app.get_mysql_root_password() + "', " "'root'@'" + config.general.get_mysql_secondary_master_ip() + "' " + "IDENTIFIED BY '" + app.get_mysql_root_password() + "' " "WITH GRANT OPTION " ) mysql_exec("DROP DATABASE test;") mysql_exec("SELECT host,user FROM mysql.db;") mysql_exec("SELECT host,user FROM mysql.user;") mysql_exec("RESET MASTER;") mysql_exec("FLUSH PRIVILEGES;") version_obj.mark_executed()
def install_mysql(args): """ Install and configure the mysql-server on the local host. """ app.print_verbose("Install mysql version: %d" % SCRIPT_VERSION) version_obj = version.Version("InstallMysql", SCRIPT_VERSION) version_obj.check_executed() if len(args) != 3: raise Exception( "syco install-mysql [server-id] [innodb-buffer-pool-size]") server_id = args[1] innodb_buffer_pool_size = args[2] # Initialize all passwords used by the script app.init_mysql_passwords() # Install the mysql-server packages. if not os.access("/usr/bin/mysqld_safe", os.W_OK | os.X_OK): x("yum -y install mysql-server hdparm") x("/sbin/chkconfig mysqld on ") if not os.access("/usr/bin/mysqld_safe", os.F_OK): raise Exception("Couldn't install mysql-server") # Configure iptables iptables.add_mysql_chain() iptables.save() # Disable mysql history logging if os.access("/root/.mysql_history", os.F_OK): x("rm /root/.mysql_history") x("ln -s /dev/null /root/.mysql_history") # Used to log slow queries, configured in my.cnf with log-slow-queries= x("touch /var/log/mysqld-slow.log") x("chown mysql:mysql /var/log/mysqld-slow.log") x("chmod 0640 /var/log/mysqld-slow.log") x("chcon system_u:object_r:mysqld_log_t:s0 /var/log/mysqld-slow.log") # Not used at the moment, just preventing mysql to load any modules. if not os.access("/usr/share/mysql/plugins", os.W_OK | os.X_OK): os.mkdir("/usr/share/mysql/plugins") os.chmod("/usr/share/mysql/plugins", 0) os.chown("/usr/share/mysql/plugins", 0, 0) # Under Linux, it is advisable to disable the write-back cache. Otherwise data # can get lost when computer get power-failures. Beware that some drives or # disk controllers may be unable to disable the write-back cache. # app.print_verbose("TODO: Might need to be done from bios?") x("hdparm -W0 /dev/mapper/VolGroup00-var") app.print_verbose("Install /etc/my.cnf") shutil.copy(app.SYCO_PATH + "var/mysql/my.cnf", "/etc/my.cnf") x("chown mysql:mysql /etc/my.cnf") x("chmod 600 /etc/my.cnf") for line in fileinput.FileInput("/etc/my.cnf", inplace=1): line = line.replace("${server-id}", server_id) line = line.replace("${innodb_buffer_pool_size}", innodb_buffer_pool_size) print line, # When the innodb files are configured to be large, it takes some time to # generate the files. app.print_verbose( "Increaste timeout for /etc/init.d/mysqld to 120 seconds.") for line in fileinput.FileInput("/etc/init.d/mysqld", inplace=1): line = line.replace("STARTTIMEOUT=30", "STARTTIMEOUT=120") print line, x("service mysqld start") # Secure the mysql installation. mysql_exec("truncate mysql.db") mysql_exec("truncate mysql.user") current_host_config = config.host(net.get_hostname()) # Used by monitor services (icingas nrpe plugin etc.) mysql_exec("GRANT REPLICATION CLIENT ON *.* " + "TO 'monitor'@'127.0.0.1' IDENTIFIED BY '%s'" % (app.get_mysql_monitor_password())) # Required by nrpe plugins mysql_exec("GRANT SHOW DATABASES ON *.* TO 'monitor'@'127.0.0.1' ") # Used by backup scripts to flush master and check slave status etc. when # doing an lvm backup. mysql_exec("GRANT RELOAD,SUPER,REPLICATION CLIENT ON *.* " + "TO 'backup'@'localhost' IDENTIFIED BY '%s'" % (app.get_mysql_backup_password())) mysql_exec("DROP DATABASE test;") mysql_exec("SELECT host,user FROM mysql.db;") mysql_exec("SELECT host,user FROM mysql.user;") mysql_exec( "GRANT ALL PRIVILEGES ON *.* TO " "'root'@'127.0.0.1' IDENTIFIED BY '%s', " "'root'@'localhost' IDENTIFIED BY '%s', " "'root'@'%s' IDENTIFIED BY '%s'" " WITH GRANT OPTION" % (app.get_mysql_root_password(), app.get_mysql_root_password(), current_host_config.get_front_ip(), app.get_mysql_root_password())) mysql_exec("flush privileges;", ) repl_peer = current_host_config.get_option("repl_peer", 'None') if repl_peer and repl_peer.lower != 'None': mysql_exec("GRANT ALL PRIVILEGES ON *.* TO " "'root'@'%s' IDENTIFIED BY '%s'" " WITH GRANT OPTION" % (repl_peer, app.get_mysql_root_password()), with_user=True) mysql_exec("RESET MASTER;", with_user=True) mysql_exec("FLUSH PRIVILEGES;", with_user=True) version_obj.mark_executed()
def install_mysql(args): ''' Install and configure the mysql-server on the local host. ''' app.print_verbose("Install mysql version: %d" % SCRIPT_VERSION) version_obj = version.Version("InstallMysql", SCRIPT_VERSION) version_obj.check_executed() if (len(args) != 3): raise Exception( "syco install-mysql [server-id] [innodb-buffer-pool-size]") server_id = args[1] innodb_buffer_pool_size = args[2] # Initialize all passwords used by the script app.init_mysql_passwords() # Install the mysql-server packages. if (not os.access("/usr/bin/mysqld_safe", os.W_OK | os.X_OK)): x("yum -y install mysql-server hdparm") x("/sbin/chkconfig mysqld on ") if (not os.access("/usr/bin/mysqld_safe", os.F_OK)): raise Exception("Couldn't install mysql-server") # Configure iptables iptables.add_mysql_chain() iptables.save() # Disable mysql history logging if (os.access("/root/.mysql_history", os.F_OK)): x("rm /root/.mysql_history") x("ln -s /dev/null /root/.mysql_history") # Used to log slow queries, configed in my.cnf with log-slow-queries= x("touch /var/log/mysqld-slow.log") x("chown mysql:mysql /var/log/mysqld-slow.log") x("chmod 0640 /var/log/mysqld-slow.log") x("chcon system_u:object_r:mysqld_log_t:s0 /var/log/mysqld-slow.log") # Not used at the moment, just preventing mysql to load any modules. if (not os.access("/usr/share/mysql/plugins", os.W_OK | os.X_OK)): os.mkdir("/usr/share/mysql/plugins") os.chmod("/usr/share/mysql/plugins", 0) os.chown("/usr/share/mysql/plugins", 0, 0) # Under Linux, it is advisable to disable the write-back cache. Otherwise data # can get lost when computer get power-failures. Beware that some drives or # disk controllers may be unable to disable the write-back cache. # # TODO: Might need to be done from bios? x("hdparm -W0 /dev/mapper/VolGroup00-var") app.print_verbose("Install /etc/my.cnf") shutil.copy(app.SYCO_PATH + "var/mysql/my.cnf", "/etc/my.cnf") for line in fileinput.FileInput("/etc/my.cnf", inplace=1): line = line.replace("${server-id}", server_id) line = line.replace("${innodb_buffer_pool_size}", innodb_buffer_pool_size) print line, # When the innodb files are configured to be large, it takes some time to # generate the files. app.print_verbose( "Increaste timeout for /etc/init.d/mysqld to 120 seconds.") for line in fileinput.FileInput("/etc/init.d/mysqld", inplace=1): line = line.replace("STARTTIMEOUT=30", "STARTTIMEOUT=120") print line, x("service mysqld start") # Secure the mysql installation. mysql_exec("truncate mysql.db") mysql_exec("truncate mysql.user") mysql_exec("GRANT ALL PRIVILEGES ON *.* " + "TO 'root'@'127.0.0.1' " + "IDENTIFIED BY '" + app.get_mysql_root_password() + "', " "'root'@'localhost' " + "IDENTIFIED BY '" + app.get_mysql_root_password() + "', " "'root'@'" + config.general.get_mysql_primary_master_ip() + "' " + "IDENTIFIED BY '" + app.get_mysql_root_password() + "', " "'root'@'" + config.general.get_mysql_secondary_master_ip() + "' " + "IDENTIFIED BY '" + app.get_mysql_root_password() + "' " "WITH GRANT OPTION ") mysql_exec("DROP DATABASE test;") mysql_exec("SELECT host,user FROM mysql.db;") mysql_exec("SELECT host,user FROM mysql.user;") mysql_exec("RESET MASTER;") mysql_exec("FLUSH PRIVILEGES;") version_obj.mark_executed()
def install_mariadb(args): """ Install and configure the MariaDB-server on the local host. """ app.print_verbose("Install MariaDB version: %d" % SCRIPT_VERSION) version_obj = version.Version("InstallMariaDB", SCRIPT_VERSION) version_obj.check_executed() if len(args) != 3: raise Exception( "syco install-mariadb [server-id] [innodb-buffer-pool-size]" ) # Collect command line parameters server_id = args[1] innodb_buffer_pool_size = args[2] # Initialize all passwords used by the script app.get_mysql_root_password() app.get_mysql_monitor_password() app.get_mysql_backup_password() # Install yum packages. x( "curl -x 10.101.10.17:3128 -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | " "bash" ) x("yum -y install MariaDB-server") x("/sbin/chkconfig mysql on") if not os.access("/usr/bin/mysqld_safe", os.F_OK): raise Exception("Couldn't install mariadb-server") # Configure iptables iptables.add_mysql_chain() iptables.save() # Disable mariadb history logging if os.access("/root/.mysql_history", os.F_OK): x("rm /root/.mysql_history") x("ln -s /dev/null /root/.mysql_history") # Used to log slow queries, configured in my.cnf with log-slow-queries= x("touch /var/log/mysqld-slow.log") x("chown mysql:mysql /var/log/mysqld-slow.log") x("chmod 0640 /var/log/mysqld-slow.log") x("chcon system_u:object_r:mysqld_log_t:s0 /var/log/mysqld-slow.log") app.print_verbose("Install /etc/my.cnf") shutil.copy(app.SYCO_PATH + "var/mariadb/my.cnf", "/etc/my.cnf.d/") x("chown root:root /etc/my.cnf.d/my.cnf") x("chmod 644 /etc/my.cnf.d/my.cnf") for line in fileinput.FileInput("/etc/my.cnf.d/my.cnf", inplace=1): line = line.replace("${server-id}", server_id) line = line.replace("${innodb_buffer_pool_size}", innodb_buffer_pool_size) print line, x("service mysql start") # Secure the mysql installation. mysql_exec("truncate mysql.db") mysql_exec("truncate mysql.user") # Used by monitor services (icingas nrpe plugin etc.) mysql_exec( "GRANT REPLICATION CLIENT ON *.* " + "TO 'monitor'@'localhost' IDENTIFIED BY '%s'" % ( app.get_mysql_monitor_password() ) ) # Required by nrpe plugins mysql_exec("GRANT SHOW DATABASES ON *.* TO 'monitor'@'localhost' ") # Used by backup scripts to flush master and check slave status etc. when # doing an lvm backup. mysql_exec( "GRANT RELOAD,SUPER,REPLICATION CLIENT ON *.* " + "TO 'backup'@'localhost' IDENTIFIED BY '%s'" % ( app.get_mysql_backup_password() ) ) mysql_exec("DROP DATABASE test;") mysql_exec( "GRANT ALL PRIVILEGES ON *.* TO " "'root'@'localhost' IDENTIFIED BY '%s' " " WITH GRANT OPTION" % ( app.get_mysql_root_password() ) ) # Setup Replication user current_host_config = config.host(net.get_hostname()) repl_peer = current_host_config.get_option("repl_peer", 'None') if repl_peer and repl_peer.lower != 'none': mysql_exec( "GRANT ALL PRIVILEGES ON *.* TO " "'root'@'%s' IDENTIFIED BY '%s'" " WITH GRANT OPTION" % ( repl_peer, app.get_mysql_root_password() ) ) # Flush all data mysql_exec("RESET MASTER") mysql_exec("flush privileges") # Display current user setttings app.print_verbose("Display mysql.db") mysql_exec("SELECT host, user FROM mysql.db", with_user=True) app.print_verbose("Display mysql.user") mysql_exec("SELECT host, user FROM mysql.user", with_user=True) version_obj.mark_executed()
def install_mysql(args): """ Install and configure the mysql-server on the local host. """ app.print_verbose("Install mysql version: %d" % SCRIPT_VERSION) version_obj = version.Version("InstallMysql", SCRIPT_VERSION) version_obj.check_executed() if len(args) != 3: raise Exception("syco install-mysql [server-id] [innodb-buffer-pool-size]") server_id=args[1] innodb_buffer_pool_size=args[2] # Initialize all passwords used by the script app.init_mysql_passwords() # Install the mysql-server packages. if not os.access("/usr/bin/mysqld_safe", os.W_OK|os.X_OK): x("yum -y install mysql-server hdparm") x("/sbin/chkconfig mysqld on ") if not os.access("/usr/bin/mysqld_safe", os.F_OK): raise Exception("Couldn't install mysql-server") # Configure iptables iptables.add_mysql_chain() iptables.save() # Disable mysql history logging if os.access("/root/.mysql_history", os.F_OK): x("rm /root/.mysql_history") x("ln -s /dev/null /root/.mysql_history") # Used to log slow queries, configured in my.cnf with log-slow-queries= x("touch /var/log/mysqld-slow.log") x("chown mysql:mysql /var/log/mysqld-slow.log") x("chmod 0640 /var/log/mysqld-slow.log") x("chcon system_u:object_r:mysqld_log_t:s0 /var/log/mysqld-slow.log") # Not used at the moment, just preventing mysql to load any modules. if not os.access("/usr/share/mysql/plugins", os.W_OK|os.X_OK): os.mkdir("/usr/share/mysql/plugins") os.chmod("/usr/share/mysql/plugins", 0) os.chown("/usr/share/mysql/plugins", 0, 0) # Under Linux, it is advisable to disable the write-back cache. Otherwise data # can get lost when computer get power-failures. Beware that some drives or # disk controllers may be unable to disable the write-back cache. # app.print_verbose("TODO: Might need to be done from bios?") x("hdparm -W0 /dev/mapper/VolGroup00-var") app.print_verbose("Install /etc/my.cnf") shutil.copy(app.SYCO_PATH + "var/mysql/my.cnf", "/etc/my.cnf") x("chown mysql:mysql /etc/my.cnf") x("chmod 600 /etc/my.cnf") for line in fileinput.FileInput("/etc/my.cnf", inplace=1): line=line.replace("${server-id}", server_id) line=line.replace("${innodb_buffer_pool_size}", innodb_buffer_pool_size) print line, # When the innodb files are configured to be large, it takes some time to # generate the files. app.print_verbose("Increaste timeout for /etc/init.d/mysqld to 120 seconds.") for line in fileinput.FileInput("/etc/init.d/mysqld", inplace=1): line=line.replace("STARTTIMEOUT=30", "STARTTIMEOUT=120") print line, x("service mysqld start") # Secure the mysql installation. mysql_exec("truncate mysql.db") mysql_exec("truncate mysql.user") current_host_config = config.host(net.get_hostname()) # Used by monitor services (icingas nrpe plugin etc.) mysql_exec( "GRANT REPLICATION CLIENT ON *.* " + "TO 'monitor'@'127.0.0.1' IDENTIFIED BY '%s'" % ( app.get_mysql_monitor_password() ) ) # Required by nrpe plugins mysql_exec("GRANT SHOW DATABASES ON *.* TO 'monitor'@'127.0.0.1' ") # Used by backup scripts to flush master and check slave status etc. when # doing an lvm backup. mysql_exec( "GRANT RELOAD,SUPER,REPLICATION CLIENT ON *.* " + "TO 'backup'@'localhost' IDENTIFIED BY '%s'" % ( app.get_mysql_backup_password() ) ) mysql_exec("DROP DATABASE test;") mysql_exec("SELECT host,user FROM mysql.db;") mysql_exec("SELECT host,user FROM mysql.user;") mysql_exec( "GRANT ALL PRIVILEGES ON *.* TO " "'root'@'127.0.0.1' IDENTIFIED BY '%s', " "'root'@'localhost' IDENTIFIED BY '%s', " "'root'@'%s' IDENTIFIED BY '%s'" " WITH GRANT OPTION" % ( app.get_mysql_root_password(), app.get_mysql_root_password(), current_host_config.get_front_ip(), app.get_mysql_root_password() ) ) mysql_exec("flush privileges;", ) repl_peer = current_host_config.get_option("repl_peer", 'None') if repl_peer and repl_peer.lower != 'None': mysql_exec( "GRANT ALL PRIVILEGES ON *.* TO " "'root'@'%s' IDENTIFIED BY '%s'" " WITH GRANT OPTION" % ( repl_peer, app.get_mysql_root_password() ), with_user=True ) mysql_exec("RESET MASTER;", with_user=True) mysql_exec("FLUSH PRIVILEGES;", with_user=True) version_obj.mark_executed()