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 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 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") 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") 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 " ) # Used by monitor services (icingas nrpe plugin etc.) mysql_exec("GRANT REPLICATION CLIENT ON *.* " + "TO 'monitor'@'127.0.0.1' " + "IDENTIFIED BY '" + app.get_mysql_monitor_password() + "'" ) # 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'@'127.0.0.1' " + "IDENTIFIED BY '" + 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("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()