forked from fabiog1901/SingleNodeCDPCluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_pgsql.sh
135 lines (107 loc) · 4.13 KB
/
setup_pgsql.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#! /bin/bash
echo "-- Configure and optimize the OS"
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.d/rc.local
echo "echo never > /sys/kernel/mm/transparent_hugepage/defrag" >> /etc/rc.d/rc.local
# add tuned optimization https://www.cloudera.com/documentation/enterprise/6/6.2/topics/cdh_admin_performance.html
echo "vm.swappiness = 1" >> /etc/sysctl.conf
sysctl vm.swappiness=1
timedatectl set-timezone UTC
echo "-- Install Java OpenJDK8 and other tools"
yum install -y java-1.8.0-openjdk-devel vim wget curl git bind-utils rng-tools
cp /usr/lib/systemd/system/rngd.service /etc/systemd/system/
systemctl daemon-reload
systemctl start rngd
systemctl enable rngd
# Check input parameters
case "$1" in
aws)
echo "server 169.254.169.123 prefer iburst minpoll 4 maxpoll 4" >> /etc/chrony.conf
systemctl restart chronyd
;;
azure)
umount /mnt/resource
mount /dev/sdb1 /opt
;;
gcp)
;;
*)
echo $"Usage: $0 {aws|azure|gcp} template-file username password [docker-device]"
echo $"example: ./setup.sh azure templates/essential.json fabio my_pass"
echo $"example: ./setup.sh aws template/cml.json fabio my_pass /dev/xvdb"
exit 1
esac
TEMPLATE=$2
USERNAME=$3
PASSWORD=$4
DOCKERDEVICE=$5
echo "-- Configure networking"
PUBLIC_IP=`curl https://api.ipify.org/`
hostnamectl set-hostname `hostname -f`
echo "`hostname -I` `hostname`" >> /etc/hosts
sed -i "s/HOSTNAME=.*/HOSTNAME=`hostname`/" /etc/sysconfig/network
systemctl disable firewalld
systemctl stop firewalld
setenforce 0
sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
echo "-- Install CM and pgsql"
## CM 7
cat - >/etc/yum.repos.d/cloudera-manager.repo <<EOF
[cm]
name=cm
enabled=1
type=rpm-md
baseurl=https://$USERNAME:[email protected]/p/cm7/7.0.3/redhat7/yum/
gpgcheck=0
EOF
yum clean all
rm -rf /var/cache/yum/
yum repolist
## PostgreSQL
yum install -y cloudera-manager-agent cloudera-manager-daemons cloudera-manager-server
yum install -y postgresql-server python-pip
pip install psycopg2==2.7.5 --ignore-installed
echo 'LC_ALL="en_US.UTF-8"' >> /etc/locale.conf
sudo su -l postgres -c "postgresql-setup initdb"
cat conf/pg_hba.conf > /var/lib/pgsql/data/pg_hba.conf
cat conf/postgresql.conf > /var/lib/pgsql/data/postgresql.conf
echo "--Enable and start pgsql"
systemctl enable postgresql
systemctl restart postgresql
echo "-- Create DBs required by CM"
sudo -u postgres psql < scripts/pgsql_create_db.sql
echo "-- Prepare CM database 'scm'"
/opt/cloudera/cm/schema/scm_prepare_database.sh postgresql scm scm cloudera
echo "-- Install CSDs"
# install local CSDs
mv ~/*.jar /opt/cloudera/csd/
chown cloudera-scm:cloudera-scm /opt/cloudera/csd/*
chmod 644 /opt/cloudera/csd/*
echo "-- Install local parcels"
mv ~/*.parcel ~/*.parcel.sha /opt/cloudera/parcel-repo/
chown cloudera-scm:cloudera-scm /opt/cloudera/parcel-repo/*
echo "-- Enable passwordless root login via rsa key"
ssh-keygen -f ~/myRSAkey -t rsa -N ""
mkdir ~/.ssh
cat ~/myRSAkey.pub >> ~/.ssh/authorized_keys
chmod 400 ~/.ssh/authorized_keys
ssh-keyscan -H `hostname` >> ~/.ssh/known_hosts
sed -i 's/.*PermitRootLogin.*/PermitRootLogin without-password/' /etc/ssh/sshd_config
systemctl restart sshd
echo "-- Start CM, it takes about 2 minutes to be ready"
systemctl start cloudera-scm-server
while [ `curl -s -X GET -u "admin:admin" http://localhost:7180/api/version` -z ] ;
do
echo "waiting 10s for CM to come up..";
sleep 10;
done
echo "-- Now CM is started and the next step is to automate using the CM API"
yum install -y epel-release
pip install --upgrade pip cm_client
sed -i "s/YourHostname/`hostname -f`/g" $TEMPLATE
sed -i "s/YourCDSWDomain/cdsw.$PUBLIC_IP.nip.io/g" $TEMPLATE
sed -i "s/YourPrivateIP/`hostname -I | tr -d '[:space:]'`/g" $TEMPLATE
sed -i "s#YourDockerDevice#$DOCKERDEVICE#g" $TEMPLATE
sed -i "s/YourHostname/`hostname -f`/g" scripts/create_cluster.py
python scripts/create_cluster.py $TEMPLATE $USERNAME $PASSWORD