Дипломная работа: Автоматизация доставки программного обеспечения при помощи DevOps практик и инструментов в облаке AWS в компании ООО "Команда Лабс"

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
121
echo -e "\n$(date +"%d-%b-%Y-%H-%M-%S") | Installing NGINX from .deb
package...\n" |& tee -a ${INSTALL_LOG_FILE_PATH}
# Install the .deb package, this allows uninstall via apt-get
sudo dpkg -i ${DEB_PKG_FILE} |& tee -a ${INSTALL_LOG_FILE_PATH}
echo "$(date +"%d-%b-%Y-%H-%M-%S") | Install completed successfully,
creating archive of source files..." |& tee -a ${INSTALL_LOG_FILE_PATH}
# Move the .deb package to a new folder since we are going to create an
# archive from the directory containing the downloaded source code files,
# which is our current working directory
sudo mv ${DEB_PKG_FILE}
${DEB_PKG_FOLDER_PATH}/${DEB_PKG_FILE} >>
${INSTALL_LOG_FILE_PATH} 2>&1
# Create an archive containing all the source files needed to build NGINX and
# compress the files using the .tar.gz format
cd $SRC_FOLDER_PATH/ && sudo tar -zcf ../$ALL_SRC_FILES_TAR . >>
${INSTALL_LOG_FILE_PATH} 2>&1
cd ..
sudo mv $ALL_SRC_FILES_TAR $DEB_PKG_FOLDER_PATH >>
${INSTALL_LOG_FILE_PATH} 2>&1
# Make both .deb package and source files archive executable by all users
sudo chmod 755 ${DEB_PKG_FOLDER_PATH}/nginx*.* >>
${INSTALL_LOG_FILE_PATH} 2>&1
122
Конфигурация Nginx после установки
#!/bin/bash -e
GEOIP1_PRE=GeoLite2-City
GEOIP2_PRE=GeoLite2-Country
EXT=.tar.gz
EXT_DB=.mmdb
SRC_FOLDER_PATH=${WORKING_DIR}/${SRC_FOLDER}
DEB_PKG_FOLDER_PATH=${WORKING_DIR}/${DEB_PKG_FOLDER
}
INSTALL_LOG_FOLDER_PATH=${WORKING_DIR}/${LOG_FOLDER
}
INSTALL_LOG_FILE_PATH=${INSTALL_LOG_FOLDER_PATH}/${LO
G_FILE}
GEOIP1_DB_TAR=${GEOIP1_PRE}${EXT}
GEOIP2_DB_TAR=${GEOIP2_PRE}${EXT}
GEOIP1_DB_FOLDER=${GEOIP1_PRE}_${GEOIP_VER}
GEOIP2_DB_FOLDER=${GEOIP2_PRE}_${GEOIP_VER}
GEOIP1_DB_FILE=${GEOIP1_PRE}${EXT_DB}
GEOIP2_DB_FILE=${GEOIP2_PRE}${EXT_DB}
##############################################################
############
123
# Create a directory at /var/lib/nginx to prevent the NGINX config
# file from failing verification in next command (sudo nginx -t)
sudo mkdir -p /var/lib/nginx >> ${INSTALL_LOG_FILE_PATH} 2>&1
echo -e "\n$(date +"%d-%b-%Y-%H-%M-%S") | Verify configuration file
syntax is correct and test is successful:\n" |& tee -a ${INSTALL_LOG_FILE_PATH}
&& \
# This command tests the nginx.conf file for syntax errors and other
# potential issues like file access, permissions, etc.
sudo nginx -t |& tee -a ${INSTALL_LOG_FILE_PATH} && \
echo -e "\n$(date +"%d-%b-%Y-%H-%M-%S") | Verify NGINX version
and configure arguments match your selections:\n" |& tee -a
${INSTALL_LOG_FILE_PATH} && \
# Verify NGINX version and verify configuration options match what
# was specified with the ./configure command
sudo nginx -V |& tee -a ${INSTALL_LOG_FILE_PATH} && \
echo -e "\n$(date +"%d-%b-%Y-%H-%M-%S") | Creating folders for
nginx virtual hosts..." |& tee -a ${INSTALL_LOG_FILE_PATH} && \
# Create folders for nginx virtual hosts
cd /etc/nginx
sudo mkdir sites-available >> ${INSTALL_LOG_FILE_PATH} 2>&1
sudo mkdir sites-enabled >> ${INSTALL_LOG_FILE_PATH} 2>&1
#echo -e "$(date +"%d-%b-%Y-%H-%M-%S") | Downloading GeoIP2
database files..." |& tee -a ${INSTALL_LOG_FILE_PATH} && \
## Create directory for GeoIP2 databases
#sudo mkdir -p /etc/nginx/geoip2 >> ${INSTALL_LOG_FILE_PATH} 2>&1
124
#
## Download latest versions of GeoIP2 databases and extract database files
#sudo wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-
City.tar.gz >> ${INSTALL_LOG_FILE_PATH} 2>&1 && \
# sudo tar -xzf $GEOIP1_DB_TAR
$GEOIP1_DB_FOLDER/$GEOIP1_DB_FILE --strip-components 1 >>
${INSTALL_LOG_FILE_PATH} 2>&1
#sudo wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-
Country.tar.gz >> ${INSTALL_LOG_FILE_PATH} 2>&1 && \
# sudo tar -zxf $GEOIP2_DB_TAR
$GEOIP2_DB_FOLDER/$GEOIP2_DB_FILE --strip-components 1 >>
${INSTALL_LOG_FILE_PATH} 2>&1
#
## Move GeoIP2 database files to NGINX config directory and remove .tar.gz
archives
#sudo mv *.mmdb /etc/nginx/geoip2 >> ${INSTALL_LOG_FILE_PATH}
2>&1
#sudo rm *.tar.gz |& tee >> ${INSTALL_LOG_FILE_PATH} 2>&1
echo "$(date +"%d-%b-%Y-%H-%M-%S") | Configuring firewall app
profile..." |& tee -a ${INSTALL_LOG_FILE_PATH}
# Move the UFW app profile uploaded by the previous script to
# the correct location. UFW is disabled by default
sudo mv ${DEB_PKG_FOLDER_PATH}/nginx
/etc/ufw/applications.d/nginx
echo "$(date +"%d-%b-%Y-%H-%M-%S") | Configuring systemd unit file..."
|& tee -a ${INSTALL_LOG_FILE_PATH}
# Move the file to correct location so NGINX can be started,
# stopped and reloaded with global commands
125
sudo mv /${DEB_PKG_FOLDER_PATH}/nginx.service
/etc/systemd/system/nginx.service
echo "$(date +"%d-%b-%Y-%H-%M-%S") | Setting permissions for NGINX
user account..." |& tee -a ${INSTALL_LOG_FILE_PATH}
sudo touch /run/nginx.pid
sudo chown www-data:www-data /run/nginx.pid
sudo chmod 755 /run/nginx.pid
sudo chown -R www-data:www-data /var/log/nginx/*
sudo chown -R www-data:www-data /var/lib/nginx/*
sudo chown -R www-data:www-data /etc/nginx/*
echo "$(date +"%d-%b-%Y-%H-%M-%S") | Installation and configuration is
complete, removing source files..." |& tee -a ${INSTALL_LOG_FILE_PATH}
# Remove all source files
sudo rm -rf $SRC_FOLDER_PATH
echo -e "$(date +"%d-%b-%Y-%H-%M-%S") | Starting NGINX, verify
service is active:\n" |& tee -a ${INSTALL_LOG_FILE_PATH} && \
# Start and enable NGINX service
sudo systemctl start nginx.service >> ${INSTALL_LOG_FILE_PATH}
2>&1 && \
sudo systemctl enable nginx.service >> ${INSTALL_LOG_FILE_PATH}
2>&1 && \
# Verify NGINX is running
sudo systemctl status nginx.service |& tee -a
${INSTALL_LOG_FILE_PATH} && \
Источник: https://baza.diplomsite.ru/previewfile/1758