Advertisement
Guest User

Untitled

a guest
May 20th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. #
  4. # Change as needed
  5. #
  6. PGPORT=12346
  7. PGDATA=/var/lib/pgsql/ambari
  8. AMBARI_WEB_USER=admin
  9. AMBARI_WEB_PW=admin
  10. AMBARI_DB_NAME=ambari
  11. AMBARI_DB_USER=ambari
  12. AMBARI_DB_PW=bigdata
  13.  
  14. #
  15. # Variables
  16. #
  17. PG_INIT_PATH=/etc/init.d/postgresql
  18. DB_BKUP_DIR=/tmp/ambari-db-backup
  19. AMBARI_PROPS=/etc/ambari-server/conf/ambari.properties
  20.  
  21. #
  22. # Main
  23. #
  24. echo -e "\n#### Stopping ambari-server"
  25. ambari-server stop
  26.  
  27. echo -e "\n#### Creating the pgpass file"
  28. echo "*:*:*:$AMBARI_DB_USER:$AMBARI_DB_PW" >> $HOME/.pgpass
  29. chmod 600 $HOME/.pgpass
  30.  
  31. echo -e "\n#### Creating database backup directory"
  32. if [ -d $DB_BKUP_DIR ]; then
  33. rm -rf $DB_BKUP_DIR
  34. fi
  35. mkdir -p $DB_BKUP_DIR
  36. chown 777 $DB_BKUP_DIR
  37.  
  38. echo -e "\n#### Backing up ambari-server databases"
  39. pg_dump -U $AMBARI_DB_USER -w -f $DB_BKUP_DIR/ambari.sql
  40.  
  41. echo -e "\n#### Attempting to stop postgres on port $PGPORT, if running"
  42. service postgresql.${PGPORT} stop
  43.  
  44. echo -e "\n#### Setting up new postgres data directory"
  45. if [ -d $PGDATA ]; then
  46. rm -rf $PGDATA
  47. fi
  48. mkdir -p $PGDATA
  49. chown postgres:postgres $PGDATA
  50.  
  51. echo -e "\n#### Creating new init script"
  52. sed -e 's|^PGPORT=.*|PGPORT='$PGPORT'|g' -e 's|^PGDATA=.*|PGDATA='$PGDATA'|g' $PG_INIT_PATH > ${PG_INIT_PATH}.${PGPORT}
  53. chmod 775 ${PG_INIT_PATH}.${PGPORT}
  54.  
  55. echo -e "\n#### Initializing new postgres instance on port $PGPORT"
  56. service postgresql.${PGPORT} initdb
  57.  
  58. echo -e "\n#### Modify postgres config to listen on all interfaces"
  59. sed -i "s|^#\?listen_addresses.*|listen_addresses = '*'|g" $PGDATA/postgresql.conf
  60.  
  61. echo -e "\n#### Copy existing pg_hba.conf"
  62. cp /var/lib/pgsql/data/pg_hba.conf $PGDATA/pg_hba.conf
  63.  
  64. echo -e "\n#### Starting new postgres instance on port $PGPORT"
  65. service postgresql.${PGPORT} start
  66.  
  67. echo -e "\n#### Creating the ambari db"
  68. su - postgres -c "psql -p $PGPORT -c 'CREATE DATABASE ambari;' -d postgres"
  69.  
  70. echo -e "\n#### Creating the ambari db user role"
  71. su - postgres -c "psql -p $PGPORT -c \"CREATE ROLE $AMBARI_DB_USER LOGIN PASSWORD '$AMBARI_DB_PW';\" -d ambari"
  72.  
  73. echo -e "\n#### Restoring ambari database backup"
  74. su - postgres -c "psql -p $PGPORT -f $DB_BKUP_DIR/ambari.sql -d ambari"
  75.  
  76. echo -e "\n#### Updating jdbc config for ambari-server"
  77. grep -v "server.jdbc" $AMBARI_PROPS >${AMBARI_PROPS}.nojdbc
  78. echo "server.jdbc.port=$PGPORT" >> ${AMBARI_PROPS}.nojdbc
  79. echo "server.jdbc.rca.driver=org.postgresql.Driver" >> ${AMBARI_PROPS}.nojdbc
  80. echo "server.jdbc.rca.url=jdbc:postgresql://localhost:${PGPORT}/ambari" >> ${AMBARI_PROPS}.nojdbc
  81. echo "server.jdbc.driver=org.postgresql.Driver" >> ${AMBARI_PROPS}.nojdbc
  82. echo "server.jdbc.user.name=$AMBARI_DB_USER" >> ${AMBARI_PROPS}.nojdbc
  83. echo "server.jdbc.postgres.schema=ambari" >> ${AMBARI_PROPS}.nojdbc
  84. echo "server.jdbc.hostname=localhost" >> ${AMBARI_PROPS}.nojdbc
  85. echo "server.jdbc.rca.user.passwd=/etc/ambari-server/conf/password.dat" >> ${AMBARI_PROPS}.nojdbc
  86. echo "server.jdbc.rca.user.name=$AMBARI_DB_USER" >> ${AMBARI_PROPS}.nojdbc
  87. echo "server.jdbc.url=jdbc:postgresql://localhost:${PGPORT}/ambari" >> ${AMBARI_PROPS}.nojdbc
  88. echo "server.jdbc.user.passwd=/etc/ambari-server/conf/password.dat" >> ${AMBARI_PROPS}.nojdbc
  89. echo "server.jdbc.database=postgres" >> ${AMBARI_PROPS}.nojdbc
  90. echo "server.jdbc.database_name=ambari" >> ${AMBARI_PROPS}.nojdbc
  91. cp ${AMBARI_PROPS}.nojdbc $AMBARI_PROPS
  92.  
  93. echo -e "\n#### Stopping existing postgres instance"
  94. service postgresql stop
  95.  
  96. echo -e "\n#### Running ambari-server setup"
  97. ambari-server setup
  98.  
  99. echo -e "\n#### Starting ambari-server"
  100. service ambari-server start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement