-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathgcp-postinstall.sh
executable file
·148 lines (116 loc) · 4.08 KB
/
gcp-postinstall.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
#!/bin/sh
# shell script to run for GCP environments
# to finish off compute installs
if [ -z "$SCRIPT" ]
then
script /tmp/post-install.txt /bin/sh -c "$0 $*"
exit 0
fi
# check for a flag and exit
if [ -f /ran_startup ]; then
exit;
fi
function distro() {
if [ -f /etc/os-release ]; then
source /etc/os-release
echo $ID
else
uname
fi
}
# if OS is RHEL based
if [[ $(distro) = @(centos|rhel|rocky|alma|fedora) ]]; then
# disable selinux
sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/sysconfig/selinux
setenforce Permissive
# create elasticsearch repo
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
cat >> /etc/yum.repos.d/elasticsearch.repo<<EOF
[elasticsearch-7]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
[elasticsearch-8]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF
# enable fastmirror
cat > /etc/dnf/dnf.conf<<EOF
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
best=False
skip_if_unavailable=True
ip_resolve=4
fastestmirror=1
EOF
yum clean all
yum makecache
# install epel repository
yum install epel-release -y
# install docker repo
yum config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# install packages
yum install unzip bind-utils openssl vim-enhanced bash-completion git wget nmap bc jq net-tools kubectl docker-ce docker-ce-cli containerd.io -y
# enable docker
for u in $(lid -g -n google-sudoers); do usermod -a -G docker $u; done
systemctl enable docker
systemctl start docker
# disable services
for service in auditd firewalld mdmonitor postfix
do
systemctl disable ${service}
done
# updating vm.max_map_count
cat >> /etc/sysctl.d/20-elastic.conf<<EOF
vm.max_map_count = 262144
EOF
# install some of my scripts
curl -fsSL https://raw.githubusercontent.com/jlim0930/scripts/master/deploy-elastic.sh -o /usr/local/bin/deploy-elastic.sh
curl -fsSL https://raw.githubusercontent.com/jlim0930/scripts/master/deploy-elastick8s.sh -o /usr/local/bin/deploy-elastick8s.sh
curl -fsSL https://raw.githubusercontent.com/jlim0930/scripts/master/kube.sh -o /usr/local/bin/kube.sh
chmod +x /usr/local/bin/*.sh
yum update -y
elif [[ $(distro) = @(debian|ubuntu) ]]; then
# add elasticsearch repo
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
apt-get install apt-transport-https ca-certificates curl software-properties-common -y
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-7.x.list
echo "deb https://artifacts.elastic.co/packages/8.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-8.x.list
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
apt-cache policy docker-ce
# install packages
apt-get update
apt-get install unzip openssl bash-completion git wget nmap bc jq docker-ce kubectl -y
# disable services
for service in apparmor ufw
do
systemctl disable ${service}
done
# enable docker
for u in $(lid -g -n google-sudoers); do usermod -a -G docker $u; done
systemctl enable docker
systemctl start docker
# updating vm.max_map_count
cat >> /etc/sysctl.d/20-elastic.conf<<EOF
vm.max_map_count = 262144
EOF
# install some of my scripts
curl -fsSL https://raw.githubusercontent.com/jlim0930/scripts/master/deploy-elastic.sh -o /usr/local/bin/deploy-elastic.sh
curl -fsSL https://raw.githubusercontent.com/jlim0930/scripts/master/deploy-elastick8s.sh -o /usr/local/bin/deploy-elastick8s.sh
curl -fsSL https://raw.githubusercontent.com/jlim0930/scripts/master/kube.sh -o /usr/local/bin/kube.sh
chmod +x /usr/local/bin/*.sh
fi
echo "done" > /ran_startup
reboot