自动化部署脚本--linux执行sh脚本
自动化部署脚本文件目录:
运行主程序:./install.sh
#!/bin/bash
SCRIPTPATH=$(cd "$(dirname "$0")"; 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 'Do you 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#$? 是上一个程序执行是否成功的标志,如果执行成功则$? 为0,否则 不为0
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+=$?# $?取上一个安装结果,安装成功为0,安装失败为1
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 30" >> $SCRIPTPATH/autostart.sh
echo "$SCRIPTPATH/redis-3.2.9/src/redis-server $SCRIPTPATH/redis-3.2.9/redis.conf &" >> $SCRIPTPATH/autostart.sh
echo "sleep 10" >> $SCRIPTPATH/autostart.sh
echo "$SCRIPTPATH/apache-activemq-5.13.0/bin/linux-x86-64/activemq start &" >> $SCRIPTPATH/autostart.sh
echo "sleep 10" >> $SCRIPTPATH/autostart.sh
echo "systemctl stop firewalld.service" >> $SCRIPTPATH/autostart.sh
echo "sleep 10" >> $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 'Do 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' ;break;;
* ) ;;
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 1024 &" >> $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 10" >> $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
init-data.sh脚本如下:
#!/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
自动化部署脚本--linux执行sh脚本的更多相关文章
- linux执行sh脚本文件命令
linux执行sh脚本文件命令 很多时候需要多个命令来完成一项工作,而这个工作又常常是重复的,这个时候我们自然会想到将这些命令写成sh脚本,下次执行下这个脚本一切就都搞定了,下面就是发布代码的一个脚本 ...
- 在Linux中执行.sh脚本,异常
在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory. 分析:这是不同系统编码格式引起的:在windows系统中 ...
- 在Linux中执行.sh脚本,异常/bin/sh^M
在Linux中执行.sh脚本,异常/bin/sh^M 在linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory. 分 ...
- Linux定时执行.sh脚本
因为测试ffmpeg推流用flv方式的话没有做自动断流,所以要先用.sh脚本来执行关流,降低CPU和其他资源占用 首先编写.sh文件 #! /bin/bash echo "kill ffmp ...
- 执行sh脚本文件下载Github上的代码(雷霄骅的ffmpeg示例代码)
今天想重新学习下ffmpeg,于是又来到了雷晓骅的博客,先下载了他的所有代码,这里记录一下在Windows上使用sh脚本下载GitHub上代码的过程. CygWin(最后并没有用到) 可以 ...
- windows调起git bash执行sh脚本定时统计git仓库代码量
本来挺简单的一个东西硬是弄了两天 心力交瘁 找了网上不少资料 整理一下发给大家 首先是统计每个人的代码量的git命令 在网上找的 我这里做了以下修改 git log --format='%aN'|so ...
- Linux执行shell脚本方式及区别&命令后台运行
Linux执行shell脚本方式及区别&命令后台运行 http://blog.csdn.net/heqiyu34/article/details/19089951/
- Linux执行.sh文件,提示No such file or directory的问题的解决方法
亲测有效:http://www.jb51.net/LINUXjishu/56395.html Linux执行.sh文件,提示No such file or directory的问题的解决方法 在win ...
- linux执行sh报错:$’\r’: 未找到命令的解决
背景 执行.sh脚本时出现$'\r': 未找到命令, 原因 是因为命令直接从windows 复制过来导致的 解决 yum install dos2unix dos2unix **.sh 进行转换 再次 ...
随机推荐
- java中this总结(转载请注明出处)
1:this在构造方法中:this可以进行构造方法中的相互调用,this(参数): 2:this调用方法中,代表调用该方法的对象的地址,例如下面的代码比较 package thisTest; publ ...
- MySQL存储引擎知多少
MySQL是我们经常使用的数据库处理系统(DBMS),不知小伙伴们有没有注意过其中的“存储引擎”(storage_engine)呢?有时候面试题中也会问道MySQL几种常用的存储引擎的区别.这次就简短 ...
- webpack 四个核心概念
webpack 是当下最热门的前端资源模块化和打包工具.它可以将许多松散的模块(如 CommonJs 模块. AMD 模块. ES6 模块.CSS.图片. JSON.Coffeescript. LES ...
- 安装Mybatis插件
http://blog.csdn.net/nextyu/article/details/69225004
- Spring IOC的简单实现
简单的说,Spring就是通过工厂+反射将我们的bean放到它的容器中的,当我们想用某个bean的时候,只需要调用getBean("beanID")方法即可. 原理简单说明: Sp ...
- laravel相关备忘
此次笔记采用的是laravel5.1版本 1.从gitcheckout下来后,首先在env修改数据库相关 2.默认laravel没有model目录,默认有一个model文件User.php放在app里 ...
- Linux下svn服务器的安装与配置-备份-恢复-计划任务
简介:SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS.CVS,它采用了分支管理系统,它的设计目标就是取代CVS.互联网上很多版本控制服务已从CVS迁移到Subvers ...
- 网络初级篇之DHCP原理与配置(原理与实验)
一.什么是DHCP DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)通常被应用在大型的局域网络环境中,主要作用是集中的管理.分配IP地址,使网络环境 ...
- host文件介绍
默认位置为%SystemRoot%\system32\drivers\etc\,但也可以改变. 动态目录由注册表键\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSe ...
- Adaptive Synchronization of Dynamics on Evolving Complex Networks
原文链接:https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.100.114101 发表在:PRL 2008 ------------- ...