You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by fr...@apache.org on 2017/04/20 18:39:57 UTC
[08/44] incubator-trafficcontrol git commit: [TC-228] postinstall and
INSTALL.md updates
[TC-228] postinstall and INSTALL.md updates
INSTALL.md
- Changed manual installation approach for non-containered postgres
postinstall
- Set reconfigure to 1, always init database
- Set debug to 1, always output so the end user sees what is
happening
- set the goose needed driver to "postgres" instead of "Pg"
- changed question default: "Database server root (admin) user"
name from "root" to "postgres"
- set PGUSER and PGPASSWORD in env to login to the postgres
superuser account
- update traffic_ops database table with the "admin" user name
and password provided by user (after initdb)
(cherry picked from commit f08a1c2a20266d67ed1a0c778180b6da99426096)
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/da80d754
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/da80d754
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/da80d754
Branch: refs/heads/2.0.x
Commit: da80d75478d0651cfe30aaf87aa8dce69eae945b
Parents: 610bdbf
Author: Jeff Martin <ma...@gmail.com>
Authored: Tue Apr 11 15:06:55 2017 -0400
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Wed Apr 19 15:35:15 2017 -0600
----------------------------------------------------------------------
traffic_ops/INSTALL.md | 109 +++++++++++++++++++++++++++++++
traffic_ops/install/bin/postinstall | 49 ++++++++++----
2 files changed, 146 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/da80d754/traffic_ops/INSTALL.md
----------------------------------------------------------------------
diff --git a/traffic_ops/INSTALL.md b/traffic_ops/INSTALL.md
new file mode 100644
index 0000000..91f5921
--- /dev/null
+++ b/traffic_ops/INSTALL.md
@@ -0,0 +1,109 @@
+# From new CentOS 7 install:
+
+## Disable selinux:
+### change `/etc/selinux/config` to `SELINUX=disabled`
+
+## Install Postgreql 9.6 client and libraries
+
+Instructions are here: https://yum.postgresql.org/
+
+- grab the link for CentOS 7 and install:
+
+ $ sudo yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-xxxx.noarch.rpm
+
+ NOTE: get a valid link from https://yum.postgresql.org/ with the correct version number.
+
+- install `postgresql96` (for psql commands) and `postgresql96-devel` (for includes/libraries needed to install `DBD::Pg` perl library)
+
+ $ sudo yum install postgresql96 postgresql96-devel
+
+## Install Postgres 9.6 server (in a container or on the host)
+
+### on the host:
+
+ $ sudo su -
+ # yum install postgresql96-server
+ $ su - postgres
+ $ /usr/pgsql-9.6/bin/initdb -A md5 -W #-W forces the user to provide a superuser (postgres) password
+ $ exit
+ # systemctl start postgresql-9.6
+ # systemctl status postgresql-9.6
+
+### -or- in a container
+
+NOTE: you do *not* need postgresql96-server if running postgres within a `docker` container.
+
+Install `docker` and `docker-compose` using instructions here:
+
+ https://docs.docker.com/engine/installation/linux/centos/
+
+ https://docs.docker.com/compose/install/
+
+Add yourself to `docker` group
+
+ $ sudo usermod -G docker $USER
+
+Remember to logout and login again.. You should see `docker` in your list of groups:
+
+ $ id
+ uid=9876(myuser) gid=9876(myuser) groups=9876(myuser),990(docker) ...
+
+Edit `mysql-to-postgres.env` to suit your needs.
+* modify `POSTGRES_*` vars to apply to new postgres container that will house your database, e.g.
+ * POSTGRES_USER=postgres
+ * POSTGRES_PASSWORD=itSas3cre4
+
+If migrating from an existing pre-2.0 traffic_ops server (mysql):
+* `TO_*` vars for admin access to existing mysql-based `traffic_ops` (to get a db dump), e.g.
+ * TO_SERVER=https://trafficops.example.com
+ * TO_USER=dennisr
+
+* `MYSQL_*` vars to apply to temporary mysql container -- really no need to change..
+
+Start a docker container to run postgres
+
+ $ cd incubator-trafficcontrol/traffic_ops/app/db/pg-migration
+ $ ./start_postgres.sh
+
+Run migration from existing mysql-based `traffic_ops`
+
+ $ ./migrate.sh
+
+## Install `traffic_ops`
+
+ $ sudo yum install traffic_ops
+
+## Install `go` and `git` (required for `goose` and some `Perl` modules)
+
+ $ sudo yum install git go
+
+## Install Perl modules
+
+ $ sudo cpanm Carton
+
+IMPORTANT!!: We're using a later version of Postgresql, so it's not installed in the default place.
+We need to tell carton where it is so the `DBD::Pg` module is installed correctly.
+
+ $ sudo su -
+ # cd /opt/traffic_ops/app
+ # POSTGRES_HOME=/usr/pgsql-9.6 /usr/local/bin/carton
+
+
+## Install goose
+
+ $ sudo GOPATH=/usr/local go get bitbucket.org/liamstask/goose/cmd/goose
+
+
+## Install any extensions needed
+
+ - install in /opt/traffic_ops_extensions
+
+## Install `openssl` certs (or use this to generate them)
+
+ $ sudo /opt/traffic_ops/install/bin/generateCert
+
+## as the root user run postinstall
+ $ sudo su -
+ # export POSTGRES_HOME=/usr/pgsql-9.6
+ # export GOPATH=/usr/local
+ # /opt/traffic_ops/install/bin/postinstall
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/da80d754/traffic_ops/install/bin/postinstall
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall b/traffic_ops/install/bin/postinstall
index 024a659..eae17d6 100755
--- a/traffic_ops/install/bin/postinstall
+++ b/traffic_ops/install/bin/postinstall
@@ -59,13 +59,13 @@ my $post_install_cfg = "/opt/traffic_ops/install/data/json/post_install.json";
my $logFile = "/var/log/traffic_ops/postinstall.log";
# debug mode
-my $debug = 0;
+my $debug = 1;
# log file for cpan output
my $cpanLogFile = "/var/log/traffic_ops/cpan.log";
# whether or not to reconfigure traffic ops
-my $reconfigure = 0;
+my $reconfigure = 1;
# used to check for .reconfigure_defaults file for backwards compatability
my $reconfigure_defaults = "/opt/traffic_ops/.reconfigure_defaults";
@@ -180,10 +180,16 @@ sub generateDbConf {
# broken out into separate file/config area
my %todbconf = getConfig( $userInput, $toDBFileName );
+ # Check if the Postgres db is used and set the driver to be "postgres"
+ my $dbDriver = $dbconf{type};
+ if ( $dbconf{type} eq "Pg" ) {
+ $dbDriver = "postgres";
+ }
+
# No YAML library installed, but this is a simple file..
open( my $fh, '>', $toDBFileName ) or errorOut("Can't write to $toDBFileName!");
print $fh "production:\n";
- print $fh " driver: $dbconf{type}\n";
+ print $fh " driver: $dbDriver\n";
print $fh " open: host=$dbconf{hostname} port=$dbconf{port} user=$dbconf{user} password=$dbconf{password} dbname=$dbconf{dbname} sslmode=disable\n";
close $fh;
@@ -398,7 +404,7 @@ sub getDefaults {
],
$dbConfFile => [
{
- "Database server root (admin) user" => "root",
+ "Database server root (admin) user" => "postgres",
"config_var" => "dbAdminUser"
},
{
@@ -552,26 +558,35 @@ sub getDefaults {
# opensslconf: The openssl configuration if any
sub setupDatabase {
- my $todbconf = shift;
- my $opensslconf = shift;
- my $setupMaxmind = shift;
+ my $todbconf = shift;
+ my $opensslconf = shift;
+ my $setupMaxmind = shift;
my $databaseConfFile = shift;
- my $dbconf = InstallUtils::readJson( $databaseConfFile );
+ my $dbconf = InstallUtils::readJson($databaseConfFile);
+
+ # Check if the Postgres db is used and set the admin database to be "postgres"
+ my $dbName = $dbconf{type};
+ if ( $dbconf{type} eq "Pg" ) {
+ $dbName = "postgres";
+ }
- my $dsn = sprintf( "DBI:%s:dbname=%s", $dbconf->{"type"}, $dbconf->{"dbname"} );
+ my $dsn = sprintf( "DBI:%s:dbname=%s", $dbconf->{"type"}, $dbName );
my $dbh = DBI->connect( $dsn, $todbconf->{"dbAdminUser"}, $todbconf->{"dbAdminPw"} );
if ($dbh) {
- InstallUtils::logger("Database connection succeeded", "info");
+ InstallUtils::logger( "Database connection succeeded", "info" );
+
# Success!
$dbh->disconnect();
}
else {
- InstallUtils::logger("Error connecting to database", "error");
- exit(-1)
+ InstallUtils::logger( "Error connecting to database", "error" );
+ exit(-1);
}
InstallUtils::logger( "Setting up database", "info" );
+ $ENV{PGUSER} = $todbconf->{"dbAdminUser"};
+ $ENV{PGPASSWORD} = $todbconf->{"dbAdminPw"};
chdir("/opt/traffic_ops/app");
my $result = InstallUtils::execCommand( "/usr/bin/perl", "db/admin.pl", "--env=production", "setup" );
@@ -763,6 +778,16 @@ sub main {
# if reconfigure is set then setup the database
if ($reconfigure) {
setupDatabase( $todbconf, $opensslconf, $todbconf->{"maxmind"}, $databaseConfFile );
+
+ ## Create the tm_user
+ my $dbconf = InstallUtils::readJson($databaseConfFile);
+ my $dsn = sprintf( "DBI:%s:dbname=%s", $dbconf->{"type"}, $dbconf->{"dbname"} );
+ my $dbh = DBI->connect( $dsn, $todbconf->{"dbAdminUser"}, $todbconf->{"dbAdminPw"} );
+ my $sha1_passwd = sha1_hex( $adminconf->{"password"} );
+ my $sub_string = sprintf( "('%s', 4, '%s')", $adminconf->{"username"}, $sha1_passwd, $sha1_passwd );
+
+ $dbh->do("insert into tm_user (username, role, local_passwd) values $sub_string");
+
}
InstallUtils::logger( "Starting Traffic Ops", "info" );