mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-31 03:12:30 +00:00 
			
		
		
		
	add ODBC setup support
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6907 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		| @@ -12,6 +12,8 @@ | ||||
|    on xCAT.  It will automate the setup of the DB2 to run | ||||
|    xCAT on the IBM DB2 database on AIX and Linux. | ||||
|    On AIX ( AIX61J - AIX61 TL5(AIX 6.1.5.0)) or later and Linux.  | ||||
|    As an option it will also setup the ODBC for C/C++ applications | ||||
|    to be able to use the database. | ||||
|    It will setup an xcatdb | ||||
|    database ,a db2instance id, name xcatdb ( same as database),  | ||||
|    and instance  password to be used in the /etc/xcat/cfgloc file | ||||
| @@ -118,6 +120,13 @@ if (($::SERVER) && ($::CLIENT)) | ||||
|     &usage; | ||||
|     exit(1); | ||||
| } | ||||
| if ((!($::SERVER)) && (!($::CLIENT)) && ($::SETUPODBC)) | ||||
| { | ||||
|     xCAT::MsgUtils->message("I", | ||||
|                        "Either -S  or -C flag must be chosen with the -o flag"); | ||||
|     &usage; | ||||
|     exit(1); | ||||
| } | ||||
|  | ||||
| # check to see if only odbc update,  no passwords needed | ||||
| my $odbconly = 0; | ||||
| @@ -210,9 +219,10 @@ if ($::SERVER) | ||||
| } | ||||
|  | ||||
| #  if not just odbc update  and xcat MN is not already running on DB2 | ||||
| #   or if we are setting up the  Client then Get  instance password | ||||
| #   or if we are setting up the  Client and not just the ODBC  | ||||
| #   then Get  instance password | ||||
| # | ||||
| if ((($odbconly == 0) && ($::xcatrunningdb2 == 0)) || ($::CLIENT)) | ||||
| if ((($odbconly == 0) && ($::xcatrunningdb2 == 0)) || (($::CLIENT) && ($odbconly == 0))) | ||||
| { | ||||
|     if ($ENV{'XCATDB2PW'})    # passwd supplied | ||||
|     { | ||||
| @@ -367,9 +377,7 @@ if ($::SETUPODBC) | ||||
|     #  set up the ODBC on the Management Node | ||||
|     # | ||||
|  | ||||
|     xCAT::MsgUtils->message("I", "setup ODBC is not supported yet."); | ||||
|  | ||||
|     #&setupODBC; | ||||
|     &setupODBC; | ||||
|  | ||||
| } | ||||
|  | ||||
| @@ -396,7 +404,7 @@ sub usage | ||||
|         "Usage:\ndb2sqlsetup - Performs the setup of IBM DB2 for xCAT to use as its database. See man db2sqlsetup for more information." | ||||
|         ); | ||||
|     my $msg = | ||||
|       "db2sqlsetup <-h|--help>\n           <-v|--version>\n           <-i|--init> <-S|-C> [-o|--setupODBC] [-V|--verbose]\n           <-o|--setupODBC> [-V|--verbose]"; | ||||
|       "db2sqlsetup <-h|--help>\n           <-v|--version>\n           <-i|--init> <-S|-C> [-o|--setupODBC] [-V|--verbose]\n           <-o|--setupODBC> <-S|-C> [-V|--verbose]"; | ||||
|  | ||||
|     xCAT::MsgUtils->message('I', "$msg"); | ||||
| } | ||||
| @@ -838,26 +846,29 @@ sub catalogServer | ||||
| { | ||||
|     xCAT::MsgUtils->message("I", "Cataloging the DB2 Server"); | ||||
|     my $MN; | ||||
|     if ($ENV{'XCATDB2SERVER'}) {   # hostname or ip address supplied | ||||
|        $MN=$ENV{'XCATDB2SERVER'}; | ||||
|     } else { | ||||
|       my $msg = | ||||
|       "Input the hostname or ip address of the Management Node as known by this Service node.  Should be the same as the site.master attribute: "; | ||||
|     if ($ENV{'XCATDB2SERVER'}) | ||||
|     {    # hostname or ip address supplied | ||||
|         $MN = $ENV{'XCATDB2SERVER'}; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         my $msg = | ||||
|           "Input the hostname or ip address of the Management Node as known by this Service node.  Should be the same as the site.master attribute: "; | ||||
|  | ||||
|       xCAT::MsgUtils->message('I', "$msg"); | ||||
|       chop($MN = <STDIN>); | ||||
|    } | ||||
|    my $cmd; | ||||
|         xCAT::MsgUtils->message('I', "$msg"); | ||||
|         chop($MN = <STDIN>); | ||||
|     } | ||||
|     my $cmd; | ||||
|     my $rc = 0; | ||||
|  | ||||
|     # su to xcatdb and catalog the database server and database | ||||
|     $cmd = "db2 catalog tcpip node mn  remote $MN server db2c_xcatdb  "; | ||||
|     $rc  = &rundb2cmd($cmd); | ||||
|     $cmd = "db2 terminate";    # refresh the cache | ||||
|     $cmd = "db2 terminate";                                  # refresh the cache | ||||
|     $rc  = &rundb2cmd($cmd); | ||||
|     $cmd = "db2 catalog db xcatdb  as xcatdb at node mn  "; | ||||
|     $rc  = &rundb2cmd($cmd); | ||||
|     $cmd = "db2 terminate";    # refresh the cache | ||||
|     $cmd = "db2 terminate";                                  # refresh the cache | ||||
|     $rc  = &rundb2cmd($cmd); | ||||
|  | ||||
| } | ||||
| @@ -942,7 +953,7 @@ sub db2reboot | ||||
|  | ||||
| =head3   setupODBC  | ||||
| 	 | ||||
|          Will setup the ODBC. Only needed if C, C++ applications are running | ||||
|          Will setup the ODBC.  C++ applications are running | ||||
| 		 that need access to the DB2 database for example LoadLeveler. | ||||
|  | ||||
| =cut | ||||
| @@ -967,114 +978,95 @@ sub setupODBC | ||||
|         exit(1); | ||||
|     } | ||||
|  | ||||
|     # for aix and redhat | ||||
|     if (($::linuxos =~ /rh.*/) || ($::osname eq 'AIX')) | ||||
|     { | ||||
|         $cmd = "rpm -qa | grep mysql-connector-odbc"; | ||||
|         xCAT::Utils->runcmd($cmd, 0); | ||||
|         if ($::RUNCMD_RC != 0) | ||||
|         { | ||||
|             my $message = | ||||
|               "\nxcat-connector-odbc is not installed.  It should be first obtained from the xcat dependency tarballs and installed before running this command. If on Linux, install from the OS CDs."; | ||||
|             xCAT::MsgUtils->message("E", " $cmd failed. $message"); | ||||
|             exit(1); | ||||
|         } | ||||
|     } | ||||
|     else    # sles | ||||
|     { | ||||
|         $cmd = "rpm -qa | grep mysql-client"; | ||||
|         xCAT::Utils->runcmd($cmd, 0); | ||||
|         if ($::RUNCMD_RC != 0) | ||||
|         { | ||||
|             my $message = | ||||
|               "\nmysql-client is not installed.  It should be first installed from the SLES CDs."; | ||||
|             xCAT::MsgUtils->message("E", " $cmd failed. $message"); | ||||
|             exit(1); | ||||
|         } | ||||
|         $cmd = "rpm -qa | grep libmysqlclient"; | ||||
|         xCAT::Utils->runcmd($cmd, 0); | ||||
|         if ($::RUNCMD_RC != 0) | ||||
|         { | ||||
|             my $message = | ||||
|               "\nlibmysqlclient is not installed.  It should be first installed from the SLES CDs."; | ||||
|             xCAT::MsgUtils->message("E", " $cmd failed. $message"); | ||||
|             exit(1); | ||||
|         } | ||||
|         $cmd = "rpm -qa | grep MyODBC-unixODBC"; | ||||
|         xCAT::Utils->runcmd($cmd, 0); | ||||
|         if ($::RUNCMD_RC != 0) | ||||
|         { | ||||
|             my $message = | ||||
|               "\n$cmd failed. MyODBC-unixODBC is not installed.  It should be first installed from the SLES CDs."; | ||||
|             xCAT::MsgUtils->message("E", "$message"); | ||||
|             exit(1); | ||||
|         } | ||||
|     }    # end sles | ||||
|     my @rpmoutput; | ||||
|     my $odbcinstfile; | ||||
|     my $odbcfile; | ||||
|     my $message; | ||||
|  | ||||
|     # configure the ODBC, again SLES different than the rest | ||||
|     my $homedir          = xCAT::Utils->getHomeDir(); | ||||
|     my $xcatconfig       = "/etc/xcat/cfgloc"; | ||||
|     my $xcatconfigbackup = "/etc/xcat/cfgloc.mysql"; | ||||
|     my $xcatconfigbackup = "/etc/xcat/cfgloc.db2"; | ||||
|     if (!(-e ($xcatconfig)) && (!(-e ($xcatconfigbackup)))) | ||||
|     { | ||||
|         $message = | ||||
|           "The $xcatconfig and $xcatconfigbackup files are missing. You need to configure xCAT for MySQL before setting up the ODBC."; | ||||
|           "The $xcatconfig and $xcatconfigbackup files are missing. You need to configure xCAT for DB2 before setting up the ODBC."; | ||||
|         xCAT::MsgUtils->message("E", "$message"); | ||||
|         exit(1); | ||||
|  | ||||
|     } | ||||
|     $cmd = "fgrep -i  host $xcatconfig"; | ||||
|     $cmd = "fgrep -i  DB2 $xcatconfig"; | ||||
|     my @output; | ||||
|     @output = xCAT::Utils->runcmd($cmd, -1); | ||||
|     if ($::RUNCMD_RC != 0)    # then try backup | ||||
|     { | ||||
|         $cmd = "fgrep -i  host $xcatconfigbackup"; | ||||
|         $cmd = "fgrep -i DB2 $xcatconfigbackup"; | ||||
|         @output = xCAT::Utils->runcmd($cmd, -1); | ||||
|         if ($::RUNCMD_RC != 0)    # then try backup | ||||
|         { | ||||
|             $message = | ||||
|               "Cannot find host info in the cfgloc or cfgloc.mysql file. Configuration of ODBC cannot continue."; | ||||
|               "Cannot find DB2 info in the cfgloc or cfgloc.db2 file. Configuration of ODBC cannot continue."; | ||||
|             xCAT::MsgUtils->message("E", " $cmd failed. $message"); | ||||
|             exit(1); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     # get host and password from cfgloc | ||||
|     (my $connstring, my $adminid, my $passwd) = split(/\|/, $output[0]); | ||||
|     (my $database,   my $id,      my $server) = split(/=/,  $connstring); | ||||
|     # instance, database and password from cfgloc | ||||
|     (my $databasehdr, my $instance, my $passwd) = split(/\|/, $output[0]); | ||||
|     (my $header, my $database) = split(/:/, $databasehdr); | ||||
|  | ||||
|     # The unixODBC Driver Manager loads the DB2 Driver dynamically | ||||
|     # so the shared object must be extracted from the driver | ||||
|     #if it does not already exist | ||||
|     if (!(-e "/var/lib/db2/sqllib/lib/libdb2.so")) | ||||
|     { | ||||
|         if (($::linuxos =~ /rh.*/) || ($::osname eq 'AIX')) | ||||
|         { | ||||
|             $cmd = "ar -x /var/lib/db2/sqllib/lib/libdb2.a"; | ||||
|             @rpmoutput = xCAT::Utils->runcmd($cmd, 0); | ||||
|             if ($::RUNCMD_RC != 0) | ||||
|             { | ||||
|                 my $message = "Cannot configure the ODBC."; | ||||
|                 xCAT::MsgUtils->message("E", " $cmd failed. $message"); | ||||
|                 exit(1); | ||||
|             } | ||||
|             $cmd = "mv shr.o /var/lib/db2/sqllib/lib/libdb2.so"; | ||||
|             @rpmoutput = xCAT::Utils->runcmd($cmd, 0); | ||||
|             if ($::RUNCMD_RC != 0) | ||||
|             { | ||||
|                 my $message = "Cannot configure the ODBC."; | ||||
|                 xCAT::MsgUtils->message("E", " $cmd failed. $message"); | ||||
|                 exit(1); | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|         {    #sles  TBD | ||||
|             xCAT::MsgUtils->message("E", | ||||
|                                     " SLES ODBC support not implemented yet"); | ||||
|             exit(1); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     if (($::linuxos =~ /rh.*/) || ($::osname eq 'AIX')) | ||||
|     { | ||||
|         $odbcinstfile = "/etc/odbcinst.ini"; | ||||
|         $odbcfile     = "/etc/odbc.ini"; | ||||
|         $cmd          = "rpm -ql mysql-connector-odbc | grep libmyodbc..so"; | ||||
|         @rpmoutput    = xCAT::Utils->runcmd($cmd, 0); | ||||
|     } | ||||
|     else | ||||
|     {    #sles | ||||
|         $odbcinstfile = "/etc/unixODBC/odbcinst.ini "; | ||||
|         $odbcfile     = "/etc/unixODBC/odbc.ini "; | ||||
|         $cmd          = "rpm -ql rpm -ql MyODBC-unixODBC | grep libmyodbc..so"; | ||||
|         @rpmoutput    = xCAT::Utils->runcmd($cmd, 0); | ||||
|     } | ||||
|     if ($::RUNCMD_RC != 0) | ||||
|     { | ||||
|         my $message = "Cannot configure the ODBC."; | ||||
|         xCAT::MsgUtils->message("E", " $cmd failed. $message"); | ||||
|         $odbcinstfile = "/etc/unixODBC/odbcinst.ini"; | ||||
|         $odbcfile     = "/etc/unixODBC/odbc.ini"; | ||||
|         xCAT::MsgUtils->message("E", " SLES ODBC support not implemented yet"); | ||||
|         exit(1); | ||||
|     } | ||||
|  | ||||
|     # setup the odbcinst.ini file | ||||
|     my $sharedlib = $rpmoutput[0]; | ||||
|     my $sharedlib = "/var/lib/db2/sqllib/lib/libdb2.so"; | ||||
|     $cmd = "fgrep -i  driver $odbcinstfile "; | ||||
|     xCAT::Utils->runcmd($cmd, -1); | ||||
|     if ($::RUNCMD_RC != 0)    # then driver entry not there | ||||
|     { | ||||
|         my $entry = | ||||
|           "[MySQL]\nDescription = ODBC for MySQL\nDriver      = $sharedlib"; | ||||
|           "[DB2]\nDescription = ODBC for DB2\nDriver      = $sharedlib"; | ||||
|         $cmd = "echo \"$entry\" >> $odbcinstfile"; | ||||
|         xCAT::Utils->runcmd($cmd, 0); | ||||
|         if ($::RUNCMD_RC != 0) | ||||
| @@ -1083,6 +1075,24 @@ sub setupODBC | ||||
|             xCAT::MsgUtils->message("E", "$message"); | ||||
|             exit(1); | ||||
|         } | ||||
|         $entry = "FileUsage = 1"; | ||||
|         $cmd   = "echo \"$entry\" >> $odbcinstfile"; | ||||
|         xCAT::Utils->runcmd($cmd, 0); | ||||
|         if ($::RUNCMD_RC != 0) | ||||
|         { | ||||
|             $message = "$cmd failed. Could not setup ODBC."; | ||||
|             xCAT::MsgUtils->message("E", "$message"); | ||||
|             exit(1); | ||||
|         } | ||||
|         $entry = "DontDLClose = 1"; | ||||
|         $cmd   = "echo \"$entry\" >> $odbcinstfile"; | ||||
|         xCAT::Utils->runcmd($cmd, 0); | ||||
|         if ($::RUNCMD_RC != 0) | ||||
|         { | ||||
|             $message = "$cmd failed. Could not setup $odbcinstfile."; | ||||
|             xCAT::MsgUtils->message("E", "$message"); | ||||
|             exit(1); | ||||
|         } | ||||
|     } | ||||
|     else | ||||
|     {    # entry already there | ||||
| @@ -1090,18 +1100,17 @@ sub setupODBC | ||||
|         xCAT::MsgUtils->message("I", "$message"); | ||||
|     } | ||||
|  | ||||
|     # setup the DSN odbc.ini file | ||||
|     # setup the Database and instance Name in the  odbc.ini file | ||||
|     $cmd = "fgrep -i  XCATDB $odbcfile"; | ||||
|     xCAT::Utils->runcmd($cmd, -1); | ||||
|     if ($::RUNCMD_RC != 0)    # then xcat entry not there | ||||
|     { | ||||
|         my $entry = | ||||
|           "[xCATDB]\nDriver   = MySQL\nSERVER   = $server\nPORT     = 3306\nDATABASE = xcatdb"; | ||||
|         my $entry = "[$instance]\nDriver   = DB2\nDATABASE = xcatdb"; | ||||
|         $cmd = "echo \"$entry\" >> $odbcfile"; | ||||
|         xCAT::Utils->runcmd($cmd, 0); | ||||
|         if ($::RUNCMD_RC != 0) | ||||
|         { | ||||
|             $message = "$cmd failed. Could not setup ODBC DNS file."; | ||||
|             $message = "$cmd failed. Could not setup $odbcfile."; | ||||
|             xCAT::MsgUtils->message("E", "$message"); | ||||
|             exit(1); | ||||
|  | ||||
| @@ -1116,7 +1125,6 @@ sub setupODBC | ||||
|     # setup $roothome/.odbc.ini so root will not have to specify password | ||||
|     # when accessing through ODBC | ||||
|  | ||||
|     my $homedir      = xCAT::Utils->getHomeDir(); | ||||
|     my $rootodbcfile = $homedir; | ||||
|     if ($::osname eq "AIX") | ||||
|     { | ||||
| @@ -1133,12 +1141,12 @@ sub setupODBC | ||||
|     if ($::RUNCMD_RC != 0)    # then xcat entry not there | ||||
|     { | ||||
|         my $entry = | ||||
|           "[xCATDB]\nSERVER =$server\nDATABASE = xcatdb\nUSER     = xcatadm\nPASSWORD = $passwd"; | ||||
|           "[$instance]\nDATABASE = $database\nUSER     = $instance\nPASSWORD = $passwd"; | ||||
|         $cmd = "echo \"$entry\" >> $rootodbcfile"; | ||||
|         xCAT::Utils->runcmd($cmd, 0); | ||||
|         if ($::RUNCMD_RC != 0) | ||||
|         { | ||||
|             $message = "$cmd failed. Could not setup root ODBC file."; | ||||
|             $message = "$cmd failed. Could not setup $rootodbcfile."; | ||||
|             xCAT::MsgUtils->message("E", "$message"); | ||||
|             exit(1); | ||||
|  | ||||
| @@ -1153,6 +1161,43 @@ sub setupODBC | ||||
|     # allow readonly by root | ||||
|     chmod 0600, $rootodbcfile; | ||||
|  | ||||
|     # if on the client, must setup /var/lib/db2/sqllib/cfg/db2cli.ini | ||||
|     # this is a db2 support bug workaround | ||||
|  | ||||
|     if ($::CLIENT) | ||||
|     { | ||||
|         my $db2clifile       = "/var/lib/db2/sqllib/cfg/db2cli.ini"; | ||||
|         my $db2clifilebackup = "/var/lib/db2/sqllib/cfg/db2cli.ini.org"; | ||||
|         $cmd = "fgrep -i  XCATDB $db2clifile"; | ||||
|         xCAT::Utils->runcmd($cmd, -1); | ||||
|         if ($::RUNCMD_RC != 0)    # then xcat entry not there | ||||
|         { | ||||
|             $cmd = "cp $db2clifile $db2clifilebackup "; | ||||
|             xCAT::Utils->runcmd($cmd, 0); | ||||
|             if ($::RUNCMD_RC != 0) | ||||
|             { | ||||
|                 $message = "$cmd failed. Could not setup ODBC."; | ||||
|                 xCAT::MsgUtils->message("E", "$message"); | ||||
|                 exit(1); | ||||
|  | ||||
|             } | ||||
|             my $entry = "\n[$instance]\nuid=$instance\npasswd=$passwd"; | ||||
|             $cmd = "echo \"$entry\" >> $db2clifile"; | ||||
|             xCAT::Utils->runcmd($cmd, 0); | ||||
|             if ($::RUNCMD_RC != 0) | ||||
|             { | ||||
|                 $message = "$cmd failed. Could not setup $db2clifile."; | ||||
|                 xCAT::MsgUtils->message("E", "$message"); | ||||
|                 exit(1); | ||||
|  | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|         {    # entry already there | ||||
|             $message = "$db2clifile  already configured, will not change."; | ||||
|             xCAT::MsgUtils->message("I", "$message"); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| #----------------------------------------------------------------------------- | ||||
| @@ -1205,7 +1250,7 @@ sub createcfgloc | ||||
| =head3   restorexcatdb  | ||||
| 	    | ||||
| 		Restores the database from ~/xcat-dbback and restarts the xcatd using | ||||
| 		MySQL | ||||
| 	        DB2	 | ||||
| 	 | ||||
| =cut | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user