linux自动部署--sh脚本安装jdk,tomcat,mysqlclient
Posted SingleOneMan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux自动部署--sh脚本安装jdk,tomcat,mysqlclient相关的知识,希望对你有一定的参考价值。
linux自动部署–sh脚本安装jdk,tomcat,mysqlclient
文章目录
环境
linux
注意替换自己的安装包和路径
root下执行
1sh脚本创建用户组及用户
#!bin/bash
# creat user
# $?表示上一个命令的执行结果
# group is same user
res=`sudo grep -c "test" /etc/group`
#echo "res is:$res "
if [ $res -eq 0 ];then
sudo groupadd test
echo "creat group: 'test'"
else
echo "group: 'test' is exist"
fi
res2=`sudo grep -c "test" /etc/passwd`
if [ $res2 -eq 0 ];then
sudo useradd -g test test
`sudo echo "123456789" |passwd test --stdin`
sudo echo 'test ALL=(ALL) ALL' >> /etc/sudoers
echo "creat user: 'test'"
else
echo "user: 'test' is exist"
fi
#切换用户
res=`sudo su - test -c "123456789"`
echo "change to user: 'test',exe 'ls:'"
sudo ls
2.sh脚本安装jdk
#!bin/bash
#install jdk
JDK_PKG="jdk-8u162-linux-x64.tar.gz"
JDK_DIR="/usr/local/jdk/jdk1.8.0_162"
JDK_PARENT_DIR="/usr/local/jdk"
#sudo su - test -c "123456789"
res=`sudo echo $JAVA_HOME`
if [ ! -n "$res" ] ;then
echo "begin to install jdk:$JDK_DIR"
sudo mkdir -p $JDK_PARENT_DIR
sudo chmod 777 -R $JDK_PARENT_DIR
sudo tar zxvf ./$JDK_PKG -C $JDK_PARENT_DIR
sudo echo "export JAVA_HOME=$JDK_DIR" >> /etc/profile
sudo echo "export PATH=$JDK_DIR/bin:$PATH" >> /etc/profile
source /etc/profile
java -version
else
echo "jdk has installed!"
fi
#test java demo
source /etc/profile
echo $JAVA_HOME
java -jar ./test-jar-0.0.1-SNAPSHOT.jar
3.sh脚本安装tomcat
#!bin/bash
#install tomcat
PKG="apache-tomcat-9.0.21.tar.gz"
DIR="/usr/local/tomcat/apache-tomcat-9.0.21"
PARENT_DIR="/usr/local/tomcat"
if [ ! -d "$DIR" ]; then
echo "begin to install tomcat:$DIR"
sudo mkdir -p $PARENT_DIR
sudo chmod 777 -R $PARENT_DIR
sudo tar zxvf ./$PKG -C $PARENT_DIR
echo "finish install tomcat"
else
echo "tomcat has installed:$DIR"
fi
#sh $DIR/bin/startup.sh start
##nohup sh $DIR/bin/startup.sh start >>$DIR/bin/tomcat.out 2>&1 &
PIDS=`ps -ef |grep tomcat |grep -v grep | awk 'print $2'`
if [ "$PIDS" != "" ]; then
echo "tomcat exist pid:$PIDS"
`kill -9 $PIDS`
echo "restart tomcat..."
sh $DIR/bin/startup.sh start
else
echo "start tomcat..."
sh $DIR/bin/startup.sh start
fi
res=`ps -ef |grep tomcat |grep -v grep | awk 'print $2'`
echo "tomcat running pid:$res"
4.sh脚本安装mysql-client,sh执行mysql命令
#!bin/bash
#install mysql client
PKG="MySQL-client-5.6.39-1.el7.x86_64.rpm"
SOFT="MySQL-client-5.6.39-1.el7.x86_64"
res=`rpm -qa |grep $SOFT`
if [ $res = "" ]; then
echo "begin to install:$SOFT"
rpm -ivh $PKG
echo "finish install $SOFT"
else
rpm -e --nodeps $SOFT
rpm -ivh $PKG
echo "$SOFT has installed"
fi
echo "test mysql client..."
echo "excute easy sql:"
mysql -h 192.168.0.110 -P3306 -uroot -proot -e "show databases;";
echo "excute sql file:"
mysql -h 192.168.0.110 -P3306 -uroot -proot <./db.sql
db.sql
show databases;
use test;
show tables;
以上是关于linux自动部署--sh脚本安装jdk,tomcat,mysqlclient的主要内容,如果未能解决你的问题,请参考以下文章