shell脚本搭建b2c商城
提前先将对应的软件包上传
shell代码
echo"已提前上传文件至opt目录"
#关闭防火墙
systemctl stop firewalld
yum -y install unzip
#jdk部署
cd /opt
tar -zxvf jdk-8u151-linux-x64.tar.gz
sed -e '10i export JAVA_HOME=/opt/jdk1.8.0_151' -e '10s/$/:$JAVA_HOME\/bin\//' /root/.bash_profile -i
source ~/.bash_profile
java -version
#tomacat部署
cd /opt
tar -xzvf apache-tomcat-8.0.53.tar.gz
unzip ./b2c.zip -d ./apache-tomcat-8.0.53/webapps/
sed 's/33[0-9][0-9]/3306/g' /opt/apache-tomcat-8.0.53/webapps/b2c/config/jdbc.properties -i
#配置数据库
cd /opt
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-server
systemctl start mysqld
mysql -e "create database b2c_db charset utf8;"
mysql -e "grant all privileges on *.* to 'root'@'%' identified by '';"
mysql -e "flush privileges;"
mysql b2c_db</opt/apache-tomcat-8.0.53/webapps/b2c/config/bak.sql
#重启服务
source /root/.bash_profile
sh /opt/apache-tomcat-8.0.53/bin/startup.sh
if [ $? -ne 0 ]; then
source /root/.bash_profile
sh /opt/apache-tomcat-8.0.53/bin/startup.sh
fi
echo"请访问:http://192.168.120.138:8080/b2c/"
实现结果
运行脚本时候使用source;
注意:source script.sh 在当前环境下执行, 所有的变量即使脚本运行结束也会被保留下来(无需显示的声明),也可以使用当前bash中定义的变量.