Automation deployment Script file directory:
Run the main program:./install.sh
#!/bin/bash
scriptpath=$ (CD "$ (dirname") "; pwd)
install_log= $SCRIPTPATH/install_log.txt
echo "***start install***" > $Install _log
echo "Workspace is $SCRIPTPATH" | Tee-a "$Install _log"
Show_license () {
Clear
Confirm= ' Do you agree with this license? [y/n]: '
More License.txt
Lic_agreed= "
While Read-p ' does agree with this license? [y/n]: ' Lic_agreed
Do
Case ' $lic _agreed ' in
y | Y) break;;
n | N) echo ' License refused-exiting '; exit 1;;
* ) ;;
Esac
Done
}
Install_expect () {
# Start Install expect
RPM-IVH--force expect/tcl-8.5.13-8.el7.x86_64.rpm
if [[0! = $?]]; Then
echo "TCL Install Failed!!!!!!" | Tee-a "$Install _log"
Exit 1
Else
echo "TCL Install Success!!!!!!" | Tee-a "$Install _log"
Fi
RPM-IVH--force expect/expect-5.45-14.el7_1.x86_64.rpm
if [[0! = $?]]; Then
echo "Expect install Failed!!!!!!" | Tee-a "$Install _log"
Exit 1
Else
echo "Expect install Success!!!!!!" | Tee-a "$Install _log"
Fi
# Expect install finish
}
Install_unzip () {
# Start Unzip
RPM-IVH--force unzip/unzip-6.0-19.el7.x86_64.rpm
if [[0! = $?]]; Then
echo "Unzip install Failed!!!!!!" | Tee-a "$Install _log"
Exit 1
Else
echo "Unzip install Success!!!!!!" | Tee-a "$Install _log"
Fi
#unzip Install Finish
}
Install_killall () {
# Start Killall
RPM-IVH--force killall/psmisc-22.20-15.el7.x86_64.rpm
if [[0! = $?]]; Then
echo "Killall Psmisc install Failed!!!!!!" | Tee-a "$Install _log"
Else
echo "Killall Psmisc install Success!!!!!!" | Tee-a "$Install _log"
Fi
#killall Install Finish
}
Install_snmp () {
Snmpstatus=0
RPM-IVH--force snmplib/net-snmp-libs-5.7.2-33.el7_5.2.x86_64.rpm
Let snmpstatus+=$?
Sleep 2
RPM-IVH--force snmplib/net-snmp-utils-5.7.2-33.el7_5.2.x86_64.rpm
Let snmpstatus+=$?
if [[0! = $snmpstatus]]; Then
echo "SNMP Install Failed!!!!!!" | Tee-a "$Install _log"
Else
echo "SNMP Install SUCCESS!!!!!!" | Tee-a "$Install _log"
Fi
}
Install_java () {
#start to install Java
RPM-IVH--force java/jdk-8u144-linux-x64.rpm
if [[0! = $?]]; Then
echo "Java Install Failed!!!!!!" | Tee-a "$Install _log"
Exit 1
Else
echo "Java Install Success!!!!!!" | Tee-a "$Install _log"
Fi
Export java_home=/usr/java/jdk1.8.0_144
Export Jre_home= $JAVA _home/jre
Export path= $PATH: $JAVA _home/bin: $JRE _home/bin
Export classpath=: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar: $JRE _home/lib/dt.jar
#java Install Finish
}
Install_activemq () {
#start to install ACTIVEMQ
Tar zxvf activemq/apache-activemq-5.13.0.tar.gz | Tee-a "$Install _log"
$SCRIPTPATH/apache-activemq-5.13.0/bin/linux-x86-64/activemq Start &
Sleep 5
echo "Activemq Install Finish" | Tee-a "$Install _log"
#activemq Install Finish
}
Install_redis () {
#start to install Redis
Tar zxvf redis/redis-3.2.9.tar.gz
$SCRIPTPATH/redis-3.2.9/src/redis-server $SCRIPTPATH/redis-3.2.9/redis.conf &
Sleep 5
echo "Redis Install Finish" | Tee-a "$Install _log"
#redis Install Finish
}
Install_systemdlib () {
Libstatus=0
RPM-IVH--force libsystemd/lz4-1.7.5-2.el7.x86_64.rpm
Let libstatus+=$?
Sleep 2
RPM-IVH--force libsystemd/systemd-libs-219-57.el7.x86_64.rpm
Let libstatus+=$?
if [[0! = $libstatus]]; Then
echo "Systemdlib Install Failed!!!!!!" | Tee-a "$Install _log"
Exit 1
Else
echo "Systemdlib Install Success!!!!!!" | Tee-a "$Install _log"
Fi
}
Install_postgres () {
#start to install Postgres
CD Postgres
Status=0
RPM-IVH--force pgdg-centos96-9.6-3.noarch.rpm
Let status+=$?
Sleep 2
RPM-IVH--force postgresql96-libs-9.6.5-1pgdg.rhel7.x86_64.rpm
Let status+=$?
Sleep 2
RPM-IVH--force postgresql96-9.6.5-1pgdg.rhel7.x86_64.rpm
Let status+=$?
Sleep 2
RPM-IVH--force libxslt-1.1.28-5.el7.x86_64.rpm
Let status+=$?
Sleep 2
RPM-IVH--force postgresql96-contrib-9.6.5-1pgdg.rhel7.x86_64.rpm
Let status+=$?
Sleep 2
RPM-IVH--force postgresql96-devel-9.6.5-1pgdg.rhel7.x86_64.rpm
Let status+=$?
Sleep 2
RPM-IVH--force postgresql96-server-9.6.5-1pgdg.rhel7.x86_64.rpm
Let status+=$?
Sleep 2
if [[0! = $status]]; Then
echo "Postgres Install Failed!!!!!!" | Tee-a "$Install _log"
Exit 1
Else
echo "Postgres Install Success!!!!!!" | Tee-a "$Install _log"
Fi
Sleep 2
CD $SCRIPTPATH
#postgres Install Finish
}
Init_postgresql () {n
#init PostgreSQL
AddUser Uxsino
/usr/pgsql-9.6/bin/postgresql96-setup Initdb
Service postgresql-9.6 Start
$SCRIPTPATH/init-data.sh| Tee-a "$Install _log"
Sleep 10
Mv-f $SCRIPTPATH/postgresql.conf/var/lib/pgsql/9.6/data/
Mv-f $SCRIPTPATH/pg_hba.conf/var/lib/pgsql/9.6/data/
Sleep 5
Service postgresql-9.6 Restart
Sleep 10
echo "PostgreSQL init Finish" | Tee-a "$Install _log"
#postgresql init finish
}
Stop_firewalld () {
#stop & Disable Firewalld
Systemctl Stop Firewalld.service | Tee-a "$Install _log"
Sleep 10
Systemctl Disable Firewalld.service | Tee-a "$Install _log"
echo "Stop & Disable FIREWALLD finish" | Tee-a "$Install _log"
#stop & Disable FIREWALLD finish
}
Auto_run_config () {
echo "Export java_home=/usr/java/jdk1.8.0_144" > $SCRIPTPATH/autostart.sh
echo "Export jre_home= $JAVA _home/jre" >> $SCRIPTPATH/autostart.sh
echo "Export path= $PATH: $JAVA _home/bin: $JRE _home/bin" >> $SCRIPTPATH/autostart.sh
echo "Export classpath=: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar: $JRE _home/lib/dt.jar" >> $SCRIPTPATH/ autostart.sh
echo "Service postgresql-9.6 restart" >> $SCRIPTPATH/autostart.sh
echo "Sleep" >> $SCRIPTPATH/autostart.sh
echo "$SCRIPTPATH/redis-3.2.9/src/redis-server $SCRIPTPATH/redis-3.2.9/redis.conf & >> $SCRIPTPATH/ autostart.sh
echo "Sleep" >> $SCRIPTPATH/autostart.sh
echo "$SCRIPTPATH/apache-activemq-5.13.0/bin/linux-x86-64/activemq start & >> $SCRIPTPATH/autostart.sh
echo "Sleep" >> $SCRIPTPATH/autostart.sh
echo "Systemctl stop Firewalld.service" >> $SCRIPTPATH/autostart.sh
echo "Sleep" >> $SCRIPTPATH/autostart.sh
echo "$SCRIPTPATH/simo/scripts/runlib" >> $SCRIPTPATH/autostart.sh
chmod 777 $SCRIPTPATH/autostart.sh
Confirm= ' Do you want set SIMO auto run? [y/n]: '
Auto_agreed= "
While Read-p ' does you want set SIMO auto run? [y/n]: ' Auto_agreed
Do
Case ' $auto _agreed ' in
y | Y
#set Simo Auto Run
echo "$SCRIPTPATH/autostart.sh">>/etc/rc.d/rc.local #linux系统自启动文件需要配置的文件路径
chmod +x/etc/rc.d/rc.local
break;;
n | N) echo ' Do not set SIMO auto Run ';
* ) ;;
Esac
Done
}
#unzip Simo and config Simo
Unzip_simo () {
Unzip $SCRIPTPATH/simo-source/simo.zip
CP $SCRIPTPATH/application.properties $SCRIPTPATH/simo/scripts/
#enable/disable Servicecenter
echo "$SCRIPTPATH/simo/scripts/runmodule simo-servicecenter 512m &" > $SCRIPTPATH/runlib
echo "Sleep 5" >> $SCRIPTPATH/runlib
#enable/disable Collector
echo "$SCRIPTPATH/simo/scripts/runmodule simo-collector &" >> $SCRIPTPATH/runlib
echo "Sleep 5" >> $SCRIPTPATH/runlib
#enable/disable Business
echo "$SCRIPTPATH/simo/scripts/runmodule simo-business 512m &" >> $SCRIPTPATH/runlib
echo "Sleep 5" >> $SCRIPTPATH/runlib
#enable/disable ITSM
echo "$SCRIPTPATH/simo/scripts/runmodule simo-itsm 1024m &" >> $SCRIPTPATH/runlib
echo "Sleep 5" >> $SCRIPTPATH/runlib
#enable/disable CMDB
echo "$SCRIPTPATH/simo/scripts/runmodule simo-cmdb 512m &" >> $SCRIPTPATH/runlib
echo "Sleep 5" >> $SCRIPTPATH/runlib
#enable/disable Workflow
echo "$SCRIPTPATH/simo/scripts/runmodule simo-workflow 512m &" >> $SCRIPTPATH/runlib
echo "Sleep" >> $SCRIPTPATH/runlib
#enable/disable MC
echo "$SCRIPTPATH/simo/scripts/runmodule simo-mc 2048m &" >> $SCRIPTPATH/runlib
Mv-f $SCRIPTPATH/runlib $SCRIPTPATH/simo/scripts/
}
Run_simo () {
chmod 777 $SCRIPTPATH/simo/scripts/runlib
$SCRIPTPATH/simo/scripts/runlib
}
Show_license
Install_expect
Install_unzip
Install_killall
Install_snmp
Install_java
Install_activemq
Install_redis
Install_systemdlib
Install_postgres
Init_postgresql
Stop_firewalld
Auto_run_config
Unzip_simo
Run_simo
Exit 0
The init-data.sh script is as follows:
#!/usr/bin/expect
Set Timeout 900
Set User Postgres
Spawn Su $user
Expect "bash-4.2*"
Send "psql\r"
Expect "postgres=#"
Send "alter user postgres with password ' postgres '; \ r"
Expect "postgres=#"
Send "create user Uxsino with password ' uxs!no10 '; \ r"
Expect "postgres=#"
Send "CREATE database Simo_dev owner Uxsino;\r"
Expect "postgres=#"
Send "GRANT all privileges on DATABASE Simo_dev to Uxsino;\r"
Expect "postgres=#"
Send "\\q\r"
Expect "bash-4.2*"
Send "exit\r"
Expect EOF
Automating deployment scripts--linux executing SH scripts