X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=installers%2Ffull_install_osm.sh;h=e759c56605f7e1b77ed63d8a19e137b310d70ee2;hb=c26d90bf8c425638f43f639b220ec09770a52e0c;hp=8384224e84e562006bcdd70c3d978d8e5d31b723;hpb=8339ed24e9270f4cd7aa34bb632505d8d72f6c4a;p=osm%2Fdevops.git diff --git a/installers/full_install_osm.sh b/installers/full_install_osm.sh index 8384224e..e759c566 100755 --- a/installers/full_install_osm.sh +++ b/installers/full_install_osm.sh @@ -53,6 +53,7 @@ function usage(){ echo -e " --soui: install classic build of OSM (Rel THREE v3.1, based on LXD containers, with SO and UI)" echo -e " --lxdimages: (only for Rel THREE with --soui) download lxd images from OSM repository instead of creating them from scratch" echo -e " --pullimages: pull/run osm images from docker.io/opensourcemano" + echo -e " --k8s_monitor: install the OSM kubernetes moitoring with prometheus and grafana" echo -e " -l : (only for Rel THREE with --soui) use specified repository url for lxd images" echo -e " -p : (only for Rel THREE with --soui) use specified repository path for lxd images" # echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)" @@ -132,6 +133,19 @@ function remove_network() { sg docker -c "docker network rm net${stack}" } +function remove_iptables() { + stack=$1 + if [ -z "$OSM_VCA_HOST" ]; then + OSM_VCA_HOST=`sg lxd -c "juju show-controller ${stack}"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'` + [ -z "$OSM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address" + fi + + if sudo iptables -t nat -C PREROUTING -p tcp -m tcp --dport 17070 -j DNAT --to-destination $OSM_VCA_HOST; then + sudo iptables -t nat -D PREROUTING -p tcp -m tcp --dport 17070 -j DNAT --to-destination $OSM_VCA_HOST + sudo netfilter-persistent save + fi +} + function remove_stack() { stack=$1 if sg docker -c "docker stack ps ${stack}" ; then @@ -169,19 +183,18 @@ function uninstall_lightweight() { remove_stack osm_elk $WORKDIR_SUDO rm -rf $OSM_DOCKER_WORK_DIR/osm_elk fi - if [ -n "$INSTALL_PERFMON" ]; then - echo -e "\nUninstalling OSM Performance Monitoring stack" - remove_stack osm_metrics - $WORKDIR_SUDO rm -rf $OSM_DOCKER_WORK_DIR/osm_metrics - fi else echo -e "\nUninstalling OSM" if [ -n "$KUBERNETES" ]; then + if [ -n "$K8S_MONITOR" ]; then + # uninstall OSM MONITORING + uninstall_k8s_monitoring + fi remove_k8s_namespace $OSM_STACK_NAME else + remove_stack $OSM_STACK_NAME remove_stack osm_elk - remove_stack osm_metrics fi echo "Now osm docker images and volumes will be deleted" newgrp docker << EONG @@ -202,6 +215,7 @@ EONG remove_volumes $OSM_STACK_NAME remove_network $OSM_STACK_NAME fi + remove_iptables $OSM_STACK_NAME echo "Removing $OSM_DOCKER_WORK_DIR" $WORKDIR_SUDO rm -rf $OSM_DOCKER_WORK_DIR sg lxd -c "juju destroy-controller --destroy-all-models --yes $OSM_STACK_NAME" @@ -564,12 +578,12 @@ function install_osmclient(){ CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "} key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY curl $key_location | sudo apt-key add - - sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient" + sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient IM" sudo apt-get update - sudo apt-get install -y python-pip - sudo -H LC_ALL=C pip install -U pip - sudo -H LC_ALL=C python -m pip install python-magic - sudo apt-get install -y python-osmclient + sudo apt-get install -y python3-pip + sudo -H LC_ALL=C python3 -m pip install -U pip + sudo -H LC_ALL=C python3 -m pip install -U python-magic pyangbind + sudo apt-get install -y python3-osm-im python3-osmclient #sed 's,OSM_SOL005=[^$]*,OSM_SOL005=True,' -i ${HOME}/.bashrc #echo 'export OSM_HOSTNAME=localhost' >> ${HOME}/.bashrc #echo 'export OSM_SOL005=True' >> ${HOME}/.bashrc @@ -588,6 +602,42 @@ function install_osmclient(){ return 0 } +function install_prometheus_nodeexporter(){ + if (systemctl -q is-active node_exporter) + then + echo "Node Exporter is already running." + else + echo "Node Exporter is not active, installing..." + if getent passwd node_exporter > /dev/null 2>&1; then + echo "node_exporter user exists" + else + echo "Creating user node_exporter" + sudo useradd --no-create-home --shell /bin/false node_exporter + fi + sudo wget -q https://github.com/prometheus/node_exporter/releases/download/v$PROMETHEUS_NODE_EXPORTER_TAG/node_exporter-$PROMETHEUS_NODE_EXPORTER_TAG.linux-amd64.tar.gz -P /tmp/ + sudo tar -C /tmp -xf /tmp/node_exporter-$PROMETHEUS_NODE_EXPORTER_TAG.linux-amd64.tar.gz + sudo cp /tmp/node_exporter-$PROMETHEUS_NODE_EXPORTER_TAG.linux-amd64/node_exporter /usr/local/bin + sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter + sudo rm -rf node_exporter-$PROMETHEUS_NODE_EXPORTER_TAG.linux-amd64* + sudo cp ${OSM_DEVOPS}/installers/docker/files/node_exporter.service /etc/systemd/system/node_exporter.service + sudo systemctl daemon-reload + sudo systemctl restart node_exporter + sudo systemctl enable node_exporter + echo "Node Exporter has been activated in this host." + fi + return 0 +} + +function uninstall_prometheus_nodeexporter(){ + sudo systemctl stop node_exporter + sudo systemctl disable node_exporter + sudo rm /etc/systemd/system/node_exporter.service + sudo systemctl daemon-reload + sudo userdel node_exporter + sudo rm /usr/local/bin/node_exporter + return 0 +} + function install_from_lxdimages(){ LXD_RELEASE=${RELEASE#"-R "} if [ -n "$LXD_REPOSITORY_PATH" ]; then @@ -655,6 +705,7 @@ function install_juju() { echo "Installing juju" sudo snap install juju --classic [ -z "$INSTALL_NOLXD" ] && sudo dpkg-reconfigure -p medium lxd + [[ ":$PATH": != *":/snap/bin:"* ]] && PATH="/snap/bin:${PATH}" echo "Finished installation of juju" return 0 } @@ -703,6 +754,10 @@ function generate_docker_images() { sg docker -c "docker pull prom/prometheus:${PROMETHEUS_TAG}" || FATAL "cannot get prometheus docker image" fi + if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q GRAFANA ; then + sg docker -c "docker pull grafana/grafana:${GRAFANA_TAG}" || FATAL "cannot get grafana docker image" + fi + if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q NBI || echo $TO_REBUILD | grep -q KEYSTONE-DB ; then sg docker -c "docker pull mariadb:${KEYSTONEDB_TAG}" || FATAL "cannot get keystone-db docker image" fi @@ -766,6 +821,11 @@ function generate_docker_images() { elif [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LW-osmclient; then sg docker -c "docker build -t ${DOCKER_USER}/osmclient ${BUILD_ARGS[@]} -f $OSM_DEVOPS/docker/osmclient ." fi + + if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q PROMETHEUS ; then + sg docker -c "docker pull google/cadvisor:${PROMETHEUS_CADVISOR_TAG}" || FATAL "cannot get prometheus cadvisor docker image" + fi + echo "Finished generation of docker images" } @@ -802,7 +862,11 @@ function generate_docker_env_files() { $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/docker-compose.yaml $OSM_DOCKER_WORK_DIR/docker-compose.yaml # Prometheus - $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/prometheus.yml $OSM_DOCKER_WORK_DIR/prometheus.yml + $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/files/prometheus.yml $OSM_DOCKER_WORK_DIR/prometheus.yml + + # Grafana & Prometheus Exporter files + $WORKDIR_SUDO mkdir -p $OSM_DOCKER_WORK_DIR/files + $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/files/* $OSM_DOCKER_WORK_DIR/files/ fi # LCM @@ -891,6 +955,13 @@ function generate_docker_env_files() { $WORKDIR_SUDO sed -i "s|OSMMON_VCA_SECRET.*|OSMMON_VCA_SECRET=$OSM_VCA_SECRET|g" $OSM_DOCKER_WORK_DIR/mon.env fi + if ! grep -Fq "OSMMON_VCA_CACERT" $OSM_DOCKER_WORK_DIR/mon.env; then + echo "OSMMON_VCA_CACERT=${OSM_VCA_CACERT}" | $WORKDIR_SUDO tee -a $OSM_DOCKER_WORK_DIR/mon.env + else + $WORKDIR_SUDO sed -i "s|OSMMON_VCA_CACERT.*|OSMMON_VCA_CACERT=${OSM_VCA_CACERT}|g" $OSM_DOCKER_WORK_DIR/mon.env + fi + + # POL if [ ! -f $OSM_DOCKER_WORK_DIR/pol.env ]; then echo "OSMPOL_SQL_DATABASE_URI=mysql://root:${MYSQL_ROOT_PASSWORD}@mysql:3306/pol" | $WORKDIR_SUDO tee -a $OSM_DOCKER_WORK_DIR/pol.env @@ -1004,9 +1075,11 @@ function deploy_lightweight() { OSM_UI_PORT=80 OSM_MON_PORT=8662 OSM_PROM_PORT=9090 + OSM_PROM_CADVISOR_PORT=8080 OSM_PROM_HOSTPORT=9091 + OSM_GRAFANA_PORT=3000 [ -n "$INSTALL_ELK" ] && OSM_ELK_PORT=5601 - [ -n "$INSTALL_PERFMON" ] && OSM_PM_PORT=3000 + #[ -n "$INSTALL_PERFMON" ] && OSM_PM_PORT=3000 if [ -n "$NO_HOST_PORTS" ]; then OSM_PORTS+=(OSM_NBI_PORTS=$OSM_NBI_PORT) @@ -1015,7 +1088,9 @@ function deploy_lightweight() { OSM_PORTS+=(OSM_UI_PORTS=$OSM_UI_PORT) OSM_PORTS+=(OSM_MON_PORTS=$OSM_MON_PORT) OSM_PORTS+=(OSM_PROM_PORTS=$OSM_PROM_PORT) - [ -n "$INSTALL_PERFMON" ] && OSM_PORTS+=(OSM_PM_PORTS=$OSM_PM_PORT) + OSM_PORTS+=(OSM_PROM_CADVISOR_PORTS=$OSM_PROM_CADVISOR_PORT) + OSM_PORTS+=(OSM_GRAFANA_PORTS=$OSM_GRAFANA_PORT) + #[ -n "$INSTALL_PERFMON" ] && OSM_PORTS+=(OSM_PM_PORTS=$OSM_PM_PORT) [ -n "$INSTALL_ELK" ] && OSM_PORTS+=(OSM_ELK_PORTS=$OSM_ELK_PORT) else OSM_PORTS+=(OSM_NBI_PORTS=$OSM_NBI_PORT:$OSM_NBI_PORT) @@ -1024,7 +1099,9 @@ function deploy_lightweight() { OSM_PORTS+=(OSM_UI_PORTS=$OSM_UI_PORT:$OSM_UI_PORT) OSM_PORTS+=(OSM_MON_PORTS=$OSM_MON_PORT:$OSM_MON_PORT) OSM_PORTS+=(OSM_PROM_PORTS=$OSM_PROM_HOSTPORT:$OSM_PROM_PORT) - [ -n "$INSTALL_PERFMON" ] && OSM_PORTS+=(OSM_PM_PORTS=$OSM_PM_PORT:$OSM_PM_PORT) + OSM_PORTS+=(OSM_PROM_CADVISOR_PORTS=$OSM_PROM_CADVISOR_PORT:$OSM_PROM_CADVISOR_PORT) + OSM_PORTS+=(OSM_GRAFANA_PORTS=$OSM_GRAFANA_PORT:$OSM_GRAFANA_PORT) + #[ -n "$INSTALL_PERFMON" ] && OSM_PORTS+=(OSM_PM_PORTS=$OSM_PM_PORT:$OSM_PM_PORT) [ -n "$INSTALL_ELK" ] && OSM_PORTS+=(OSM_ELK_PORTS=$OSM_ELK_PORT:$OSM_ELK_PORT) fi echo "export ${OSM_PORTS[@]}" | $WORKDIR_SUDO tee $OSM_DOCKER_WORK_DIR/osm_ports.sh @@ -1034,6 +1111,8 @@ function deploy_lightweight() { echo "export KAFKA_TAG=${KAFKA_TAG}" | $WORKDIR_SUDO tee --append $OSM_DOCKER_WORK_DIR/osm_ports.sh echo "export PROMETHEUS_TAG=${PROMETHEUS_TAG}" | $WORKDIR_SUDO tee --append $OSM_DOCKER_WORK_DIR/osm_ports.sh echo "export KEYSTONEDB_TAG=${KEYSTONEDB_TAG}" | $WORKDIR_SUDO tee --append $OSM_DOCKER_WORK_DIR/osm_ports.sh + echo "export PROMETHEUS_CADVISOR_TAG=${PROMETHEUS_CADVISOR_TAG}" | $WORKDIR_SUDO tee --append $OSM_DOCKER_WORK_DIR/osm_ports.sh + echo "export GRAFANA_TAG=${GRAFANA_TAG}" | $WORKDIR_SUDO tee --append $OSM_DOCKER_WORK_DIR/osm_ports.sh pushd $OSM_DOCKER_WORK_DIR sg docker -c ". ./osm_ports.sh; docker stack deploy -c $OSM_DOCKER_WORK_DIR/docker-compose.yaml $OSM_STACK_NAME" @@ -1092,20 +1171,6 @@ function deploy_elk() { return 0 } -function deploy_perfmon() { - echo "Pulling docker images for PM (Grafana)" - sg docker -c "docker pull grafana/grafana" || FATAL "cannot get grafana docker image" - echo "Finished pulling PM docker images" - $WORKDIR_SUDO mkdir -p $OSM_DOCKER_WORK_DIR/osm_metrics - $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.yml $OSM_DOCKER_WORK_DIR/osm_metrics - $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.json $OSM_DOCKER_WORK_DIR/osm_metrics - remove_stack osm_metrics - echo "Deploying PM stack (Grafana)" - sg docker -c "OSM_NETWORK=net${OSM_STACK_NAME} docker stack deploy -c $OSM_DOCKER_WORK_DIR/osm_metrics/docker-compose.yml osm_metrics" - echo "Finished deployment of PM stack" - return 0 -} - function install_lightweight() { [ "${OSM_STACK_NAME}" == "osm" ] || OSM_DOCKER_WORK_DIR="$OSM_WORK_DIR/stack/$OSM_STACK_NAME" [ -n "$KUBERNETES" ] && OSM_K8S_WORK_DIR="$OSM_DOCKER_WORK_DIR/osm_pods" && OSM_NAMESPACE_VOL="${OSM_HOST_VOL}/${OSM_STACK_NAME}" @@ -1211,6 +1276,10 @@ function install_lightweight() { generate_docker_env_files if [ -n "$KUBERNETES" ]; then + if [ -n "$K8S_MONITOR" ]; then + # uninstall OSM MONITORING + uninstall_k8s_monitoring + fi #remove old namespace remove_k8s_namespace $OSM_STACK_NAME deploy_cni_provider @@ -1226,9 +1295,15 @@ function install_lightweight() { deploy_lightweight generate_osmclient_script track docker_deploy + install_prometheus_nodeexporter [ -n "$INSTALL_VIMEMU" ] && install_vimemu && track vimemu [ -n "$INSTALL_ELK" ] && deploy_elk && track elk - [ -n "$INSTALL_PERFMON" ] && deploy_perfmon && track perfmon + fi + + if [ -n "$KUBERNETES" ] && [ -n "$K8S_MONITOR" ]; then + # install OSM MONITORING + install_k8s_monitoring + track install_k8s_monitoring fi [ -z "$INSTALL_NOHOSTCLIENT" ] && install_osmclient @@ -1270,6 +1345,18 @@ function install_vimemu() { echo " osm vim-create --name emu-vim1 --user username --password password --auth_url http://${VIMEMU_HOSTNAME}:6001/v2.0 --tenant tenantName --account_type openstack" } +function install_k8s_monitoring() { + # install OSM monitoring + chmod +x $WORKDIR_SUDO $OSM_DEVOPS/installers/k8s/*.sh + $WORKDIR_SUDO $OSM_DEVOPS/installers/k8s/install_osm_k8s_monitoring.sh +} + +function uninstall_k8s_monitoring() { + # install OSM monitoring + chmod +x $WORKDIR_SUDO $OSM_DEVOPS/installers/k8s/*.sh + $WORKDIR_SUDO $OSM_DEVOPS/installers/k8s/uninstall_osm_k8s_monitoring.sh +} + function dump_vars(){ echo "DEVELOP=$DEVELOP" echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE" @@ -1286,7 +1373,7 @@ function dump_vars(){ echo "INSTALL_LIGHTWEIGHT=$INSTALL_LIGHTWEIGHT" echo "INSTALL_ONLY=$INSTALL_ONLY" echo "INSTALL_ELK=$INSTALL_ELK" - echo "INSTALL_PERFMON=$INSTALL_PERFMON" + #echo "INSTALL_PERFMON=$INSTALL_PERFMON" echo "TO_REBUILD=$TO_REBUILD" echo "INSTALL_NOLXD=$INSTALL_NOLXD" echo "INSTALL_NODOCKER=$INSTALL_NODOCKER" @@ -1347,12 +1434,13 @@ LXD_REPOSITORY_PATH="" INSTALL_LIGHTWEIGHT="y" INSTALL_ONLY="" INSTALL_ELK="" -INSTALL_PERFMON="" +#INSTALL_PERFMON="" TO_REBUILD="" INSTALL_NOLXD="" INSTALL_NODOCKER="" INSTALL_NOJUJU="" KUBERNETES="" +K8S_MONITOR="" INSTALL_NOHOSTCLIENT="" NOCONFIGURE="" RELEASE_DAILY="" @@ -1377,6 +1465,9 @@ DOCKER_USER=opensourcemano PULL_IMAGES="y" KAFKA_TAG=2.11-1.0.2 PROMETHEUS_TAG=v2.4.3 +GRAFANA_TAG=latest +PROMETHEUS_NODE_EXPORTER_TAG=0.18.1 +PROMETHEUS_CADVISOR_TAG=latest KEYSTONEDB_TAG=10 OSM_DATABASE_COMMONKEY= ELASTIC_VERSION=6.4.2 @@ -1455,7 +1546,7 @@ while getopts ":hy-:b:r:c:k:u:R:l:p:D:o:m:H:S:s:w:t:U:P:A:" o; do INSTALL_ONLY="y" [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue - [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue + #[ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue ;; m) [ "${OPTARG}" == "LW-UI" ] && TO_REBUILD="$TO_REBUILD LW-UI" && continue @@ -1468,6 +1559,7 @@ while getopts ":hy-:b:r:c:k:u:R:l:p:D:o:m:H:S:s:w:t:U:P:A:" o; do [ "${OPTARG}" == "MONGO" ] && TO_REBUILD="$TO_REBUILD MONGO" && continue [ "${OPTARG}" == "PROMETHEUS" ] && TO_REBUILD="$TO_REBUILD PROMETHEUS" && continue [ "${OPTARG}" == "KEYSTONE-DB" ] && TO_REBUILD="$TO_REBUILD KEYSTONE-DB" && continue + [ "${OPTARG}" == "GRAFANA" ] && TO_REBUILD="$TO_REBUILD GRAFANA" && continue [ "${OPTARG}" == "NONE" ] && TO_REBUILD="$TO_REBUILD NONE" && continue ;; -) @@ -1487,7 +1579,7 @@ while getopts ":hy-:b:r:c:k:u:R:l:p:D:o:m:H:S:s:w:t:U:P:A:" o; do [ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && RELEASE="-R ReleaseTHREE" && REPOSITORY="-r stable" && continue [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue - [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue + #[ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue @@ -1496,6 +1588,7 @@ while getopts ":hy-:b:r:c:k:u:R:l:p:D:o:m:H:S:s:w:t:U:P:A:" o; do [ "${OPTARG}" == "nodockerbuild" ] && DOCKER_NOBUILD="y" && continue [ "${OPTARG}" == "nohostclient" ] && INSTALL_NOHOSTCLIENT="y" && continue [ "${OPTARG}" == "pullimages" ] && continue + [ "${OPTARG}" == "k8s_monitor" ] && K8S_MONITOR="y" && continue echo -e "Invalid option: '--$OPTARG'\n" >&2 usage && exit 1 ;; @@ -1575,7 +1668,7 @@ fi [ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0 [ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0 [ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_ELK" ] && deploy_elk -[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_PERFMON" ] && deploy_perfmon +#[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_PERFMON" ] && deploy_perfmon [ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_VIMEMU" ] && install_vimemu [ -n "$INSTALL_ONLY" ] && echo -e "\nDONE" && exit 0