-
Notifications
You must be signed in to change notification settings - Fork 54
/
install-openshift.sh
executable file
·220 lines (174 loc) · 6.73 KB
/
install-openshift.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/bin/bash
## see: https://youtu.be/aqXSbDZggK4
## Default variables to use
export INTERACTIVE=${INTERACTIVE:="true"}
export PVS=${INTERACTIVE:="true"}
export DOMAIN=${DOMAIN:="$(curl -s ipinfo.io/ip).nip.io"}
export USERNAME=${USERNAME:="$(whoami)"}
export PASSWORD=${PASSWORD:=password}
export VERSION=${VERSION:="3.11"}
export SCRIPT_REPO=${SCRIPT_REPO:="https://raw.githubusercontent.com/okd-community-install/installrhel/master"}
export IP=${IP:="$(ip route get 8.8.8.8 | awk '{print $NF; exit}')"}
export API_PORT=${API_PORT:="8443"}
export EORG_USER=${EORG_USER}
export EORG_PASSWORD=${EORG_PASSWORD}
## Make the script interactive to set the variables
if [ "$INTERACTIVE" = "true" ]; then
read -rp "Is your system registered and attached to the correct pool?: (Y/N) " choice;
if [ "$choice" == "N" ] || [ "$choice" == "n" ] ; then
echo "Users to need run the following command before this script:"
echo "$> subscription-manager register"
echo "$> subscription-manager attach --pool=POOLID"
echo "$> subscription-manager repos --disable=\"*\""
exit 1;
fi
read -rp "Domain to use: ($DOMAIN): " choice;
if [ "$choice" != "" ] ; then
export DOMAIN="$choice";
fi
read -rp "Username: ($USERNAME): " choice;
if [ "$choice" != "" ] ; then
export USERNAME="$choice";
fi
read -rp "Password: ($PASSWORD): " choice;
if [ "$choice" != "" ] ; then
export PASSWORD="$choice";
fi
read -rp "OpenShift Version: ($VERSION): " choice;
if [ "$choice" != "" ] ; then
export VERSION="$choice";
fi
read -rp "IP: ($IP): " choice;
if [ "$choice" != "" ] ; then
export IP="$choice";
fi
read -rp "API Port: ($API_PORT): " choice;
if [ "$choice" != "" ] ; then
export API_PORT="$choice";
fi
read -rp "Red Hat Username: ($EORG_USER): " choice;
if [ "$choice" != "" ] ; then
export EORG_USER="$choice";
fi
read -rp "Red Hat Password: ($EORG_PASSWORD): " choice;
if [ "$choice" != "" ] ; then
export EORG_PASSWORD="$choice";
fi
echo
fi
echo "******"
echo "* Your domain is $DOMAIN "
echo "* Your IP is $IP "
echo "* Your username is $USERNAME "
echo "* Your password is $PASSWORD "
echo "* OpenShift version: $VERSION "
echo "* Red Hat account: $EORG_USER "
echo "******"
# Users to need run the following command before this script
# subscription-manager register
# subscription-manager attach --pool=POOLID
# subscription-manager repos --disable="*"'
#install epel
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
subscription-manager repos --enable "rhel-7-server-rpms" --enable "rhel-7-server-extras-rpms" --enable "rhel-7-fast-datapath-rpms" --enable "rhel-7-server-ose-3.11-rpms"
subscription-manager repos --enable "rhel-*-optional-rpms" --enable "rhel-*-extras-rpms"
subscription-manager repos --enable rhel-7-server-ansible-2.6-rpms
# install updates
yum update -y
# install the following base packages
yum install -y wget git zile nano net-tools docker-1.13.1\
bind-utils iptables-services \
bridge-utils bash-completion \
kexec-tools sos psacct openssl-devel \
httpd-tools NetworkManager \
python-cryptography python2-pip python-devel python-passlib \
java-1.8.0-openjdk-headless "@Development Tools"
# Disable the EPEL repository globally so that is not accidentally used during later steps of the installation
sed -i -e "s/^enabled=1/enabled=0/" /etc/yum.repos.d/epel.repo
systemctl | grep "NetworkManager.*running"
if [ $? -eq 1 ]; then
systemctl start NetworkManager
systemctl enable NetworkManager
fi
# install the packages for Ansible
yum -y install ansible pyOpenSSL
[ ! -d openshift-ansible ] && git clone https://github.com/openshift/openshift-ansible.git
cd openshift-ansible && git fetch && git checkout release-3.11 && cd ..
cat <<EOD > /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
${IP} $(hostname) console console.${DOMAIN}
EOD
if [ -z $DISK ]; then
echo "Not setting the Docker storage."
else
cp /etc/sysconfig/docker-storage-setup /etc/sysconfig/docker-storage-setup.bk
echo DEVS=$DISK > /etc/sysconfig/docker-storage-setup
echo VG=DOCKER >> /etc/sysconfig/docker-storage-setup
echo SETUP_LVM_THIN_POOL=yes >> /etc/sysconfig/docker-storage-setup
echo DATA_SIZE="100%FREE" >> /etc/sysconfig/docker-storage-setup
systemctl stop docker
rm -rf /var/lib/docker
wipefs --all $DISK
docker-storage-setup
fi
systemctl restart docker
systemctl enable docker
if [ ! -f ~/.ssh/id_rsa ]; then
ssh-keygen -q -f ~/.ssh/id_rsa -N ""
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh -o StrictHostKeyChecking=no root@$IP "pwd" < /dev/null
fi
export METRICS="True"
export LOGGING="True"
memory=$(cat /proc/meminfo | grep MemTotal | sed "s/MemTotal:[ ]*\([0-9]*\) kB/\1/")
if [ "$memory" -lt "4194304" ]; then
export METRICS="False"
fi
if [ "$memory" -lt "8388608" ]; then
export LOGGING="False"
fi
curl -o inventory.download $SCRIPT_REPO/inventory.ini
envsubst < inventory.download > inventory.ini
# add proxy in inventory.ini if proxy variables are set
if [ ! -z "${HTTPS_PROXY:-${https_proxy:-${HTTP_PROXY:-${http_proxy}}}}" ]; then
echo >> inventory.ini
echo "openshift_http_proxy=\"${HTTP_PROXY:-${http_proxy:-${HTTPS_PROXY:-${https_proxy}}}}\"" >> inventory.ini
echo "openshift_https_proxy=\"${HTTPS_PROXY:-${https_proxy:-${HTTP_PROXY:-${http_proxy}}}}\"" >> inventory.ini
if [ ! -z "${NO_PROXY:-${no_proxy}}" ]; then
__no_proxy="${NO_PROXY:-${no_proxy}},${IP},.${DOMAIN}"
else
__no_proxy="${IP},.${DOMAIN}"
fi
echo "openshift_no_proxy=\"${__no_proxy}\"" >> inventory.ini
fi
mkdir -p /etc/origin/master/
touch /etc/origin/master/htpasswd
ansible-playbook -i inventory.ini openshift-ansible/playbooks/prerequisites.yml
ansible-playbook -i inventory.ini openshift-ansible/playbooks/deploy_cluster.yml
htpasswd -b /etc/origin/master/htpasswd ${USERNAME} ${PASSWORD}
oc adm policy add-cluster-role-to-user cluster-admin ${USERNAME}
if [ "$PVS" = "true" ]; then
for i in `seq 1 200`;
do
DIRNAME="vol$i"
mkdir -p /mnt/data/$DIRNAME
chcon -Rt svirt_sandbox_file_t /mnt/data/$DIRNAME
chmod 777 /mnt/data/$DIRNAME
sed "s/name: vol/name: vol$i/g" vol.yaml > oc_vol.yaml
sed -i "s/path: \/mnt\/data\/vol/path: \/mnt\/data\/vol$i/g" oc_vol.yaml
oc create -f oc_vol.yaml
echo "created volume $i"
done
rm oc_vol.yaml
fi
echo "******"
echo "* Your console is https://console.$DOMAIN:$API_PORT"
echo "* Your username is $USERNAME "
echo "* Your password is $PASSWORD "
echo "*"
echo "* Login using:"
echo "*"
echo "$ oc login -u ${USERNAME} -p ${PASSWORD} https://console.$DOMAIN:$API_PORT/"
echo "******"
oc login -u ${USERNAME} -p ${PASSWORD} https://console.$DOMAIN:$API_PORT/