|
|
|
@ -5,6 +5,22 @@
|
|
|
|
|
# T&M Hansson IT AB © - 2022, https://www.hanssonit.se/
|
|
|
|
|
# GPLv3 or later.
|
|
|
|
|
#
|
|
|
|
|
{
|
|
|
|
|
echo "Started at $(date +'%Y-%m-%d %H:%M:%S')" >> opensearch-installer.log
|
|
|
|
|
|
|
|
|
|
while getopts m: option
|
|
|
|
|
do
|
|
|
|
|
case "${option}"
|
|
|
|
|
in
|
|
|
|
|
m) MODE=${OPTARG};;
|
|
|
|
|
\?) echo "Usage: sudo bash ./$0 [-m debug]" && exit;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
#DEBUG
|
|
|
|
|
if [ "$MODE" = "debug" ]; then
|
|
|
|
|
set -x
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Reset
|
|
|
|
|
Color_Off='\e[0m' # Text Reset
|
|
|
|
@ -18,6 +34,9 @@ Purple='\e[0;35m' # Purple
|
|
|
|
|
Cyan='\e[0;36m' # Cyan
|
|
|
|
|
|
|
|
|
|
MEM_AVAILABLE="$(grep MemTotal /proc/meminfo| grep -o '[0-9]\+')"
|
|
|
|
|
DIST=$(lsb_release -sc)
|
|
|
|
|
TODAY=$(date +%s)
|
|
|
|
|
NEXT_LTS_DATE=$(date -d 2024-04-01 +%s)
|
|
|
|
|
OPNSDIR="/opt/opensearch"
|
|
|
|
|
INDEX_USER="$(tr -dc '[:lower:]' < /dev/urandom | fold -w 24 | head -n1)"
|
|
|
|
|
OPNSREST="$(tr -dc "a-zA-Z0-9" < /dev/urandom | fold -w 32 | head -n1)"
|
|
|
|
@ -27,9 +46,22 @@ fts_node="fts_os-node"
|
|
|
|
|
max_map_count="512000"
|
|
|
|
|
NL="$(printf '\n ')"
|
|
|
|
|
|
|
|
|
|
rename_distro() {
|
|
|
|
|
if [ "$DIST" = "$1" ]; then
|
|
|
|
|
DIST="$2"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
#Trisquel distro upstream referencing.
|
|
|
|
|
rename_distro nabia focal
|
|
|
|
|
rename_distro aramo jammy
|
|
|
|
|
printwc() {
|
|
|
|
|
printf "%b$2%b" "$1" "${Color_Off}"
|
|
|
|
|
}
|
|
|
|
|
print_title() {
|
|
|
|
|
printwc "${Blue}" "\n#--------------------------------------------------"
|
|
|
|
|
printwc "${Blue}" "\n# $1"
|
|
|
|
|
printwc "${Blue}" "\n#--------------------------------------------------\n"
|
|
|
|
|
}
|
|
|
|
|
install_if_not() {
|
|
|
|
|
if [ "$(dpkg-query -W -f='${Status}' "$1" 2>/dev/null | \
|
|
|
|
|
grep -c "ok installed")" == "1" ]; then
|
|
|
|
@ -77,6 +109,14 @@ while [ $secs -gt 0 ]; do
|
|
|
|
|
: $((secs--))
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
wait_for_bootstrapping() {
|
|
|
|
|
if [ "$(nproc)" -gt 2 ]
|
|
|
|
|
then
|
|
|
|
|
countdown "Waiting for Docker bootstrapping..." "30"
|
|
|
|
|
else
|
|
|
|
|
countdown "Waiting for Docker bootstrapping..." "60"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#Check if user is root
|
|
|
|
|
if ! [ "$(id -u)" = 0 ]; then
|
|
|
|
@ -84,11 +124,31 @@ if ! [ "$(id -u)" = 0 ]; then
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
printf "\nOS: %s" "$(lsb_release -sd)"
|
|
|
|
|
if [ "$DIST" = "focal" ] || \
|
|
|
|
|
[ "$DIST" = "jammy" ]; then
|
|
|
|
|
printf "\nGood, this is a supported platform!"
|
|
|
|
|
else
|
|
|
|
|
printf "\nSorry, this platform is not supported... exiting"
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
# Suggest 22.04 LTS release over 20.04 in April 2024
|
|
|
|
|
if [ "$DIST" = "focal" ]; then
|
|
|
|
|
if [ "$TODAY" -gt "$NEXT_LTS_DATE" ]; then
|
|
|
|
|
echo " > $(lsb_release -sc), even when it's compatible and functional."
|
|
|
|
|
echo -n " We suggest to use the next (LTS) release, for longer"
|
|
|
|
|
echo " support and security reasons."
|
|
|
|
|
read -n 1 -s -r -p "Press any key to continue..."$'\n'
|
|
|
|
|
else
|
|
|
|
|
echo "Focal is supported."
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Check update
|
|
|
|
|
apt-get update -q2
|
|
|
|
|
|
|
|
|
|
# Test RAM size (4GB min) + CPUs (min 2)
|
|
|
|
|
#Check system resources
|
|
|
|
|
print_title "Check system resources"
|
|
|
|
|
printf "\n\nVerifying System Resources:"
|
|
|
|
|
if [ "$(nproc --all)" -lt 2 ];then
|
|
|
|
|
printf "\nWarning!: The system do not meet the minimum CPU"
|
|
|
|
@ -134,7 +194,8 @@ printf '\nThis server will likely have issues due the lack of resources.\n'
|
|
|
|
|
printf '>>> We highly recommend to increase resources of this server. <<<\n'
|
|
|
|
|
fi
|
|
|
|
|
sleep .1
|
|
|
|
|
# Set domain
|
|
|
|
|
|
|
|
|
|
print_title "Set CA domain"
|
|
|
|
|
while [ "$ANS_DMN" != "yes" ]
|
|
|
|
|
do
|
|
|
|
|
read -p "> Set your CA domain (or subdomain) here: $NL" -r DOMAIN
|
|
|
|
@ -165,13 +226,15 @@ else
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
sleep .1
|
|
|
|
|
# Check & install docker
|
|
|
|
|
install_if_not docker.io
|
|
|
|
|
install_if_not docker-compose
|
|
|
|
|
|
|
|
|
|
print_title "Set system vm.max_map_count."
|
|
|
|
|
sysctl -w vm.max_map_count="$max_map_count"
|
|
|
|
|
set_once_hash_comment "vm.max_map_count=$max_map_count" "/etc/sysctl.conf"
|
|
|
|
|
|
|
|
|
|
print_title "Install and setup Docker"
|
|
|
|
|
install_if_not docker.io
|
|
|
|
|
install_if_not docker-compose
|
|
|
|
|
|
|
|
|
|
mkdir -p "$OPNSDIR"
|
|
|
|
|
docker pull "$opens_fts"
|
|
|
|
|
BCRYPT_HASH="$(docker run --rm -it $opens_fts \
|
|
|
|
@ -295,23 +358,17 @@ networks:
|
|
|
|
|
#[1] https://github.com/opensearch-project/performance-analyzer
|
|
|
|
|
YML_DOCKER_COMPOSE
|
|
|
|
|
|
|
|
|
|
# Prepare certs
|
|
|
|
|
print_title "Prepare certs"
|
|
|
|
|
create_certs "$DOMAIN"
|
|
|
|
|
|
|
|
|
|
# Set permissions
|
|
|
|
|
chmod 744 -R $OPNSDIR
|
|
|
|
|
|
|
|
|
|
# Launch docker-compose
|
|
|
|
|
print_title "Launch opensearch via docker-compose"
|
|
|
|
|
cd $OPNSDIR
|
|
|
|
|
docker-compose up -d
|
|
|
|
|
|
|
|
|
|
# Wait for bootstrapping
|
|
|
|
|
if [ "$(nproc)" -gt 2 ]
|
|
|
|
|
then
|
|
|
|
|
countdown "Waiting for Docker bootstrapping..." "30"
|
|
|
|
|
else
|
|
|
|
|
countdown "Waiting for Docker bootstrapping..." "60"
|
|
|
|
|
fi
|
|
|
|
|
wait_for_bootstrapping
|
|
|
|
|
|
|
|
|
|
# Make sure password setup is enforced.
|
|
|
|
|
docker-compose exec fts_os-node \
|
|
|
|
@ -329,6 +386,17 @@ docker-compose exec fts_os-node \
|
|
|
|
|
../../../config/admin.pem \
|
|
|
|
|
../../../config/admin-key.pem"
|
|
|
|
|
|
|
|
|
|
wait_for_bootstrapping
|
|
|
|
|
docker logs $fts_node
|
|
|
|
|
|
|
|
|
|
printwc "$Green" "\n\nYou can now use: \"http://${INDEX_USER}:${OPNSREST}@localhost:9200\"\n"
|
|
|
|
|
if curl -sXGET "http://${INDEX_USER}:${OPNSREST}@localhost:9200"
|
|
|
|
|
then
|
|
|
|
|
printwc "$Green" "\n\nYou can now use: "
|
|
|
|
|
printwc "$Cyan" "'http://${INDEX_USER}:${OPNSREST}@localhost:9200'\n"
|
|
|
|
|
else
|
|
|
|
|
printwc "$Red" "\n\nSetup have failed please report to: "
|
|
|
|
|
printwc "$Cyan" \
|
|
|
|
|
"'https://forge.switnet.net/switnet/simple-opensearch-installer'\n"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
} > >(tee -a opensearch-installer.log) 2> >(tee -a opensearch-installer.log >&2)
|
|
|
|
|