**因工作需要,在内网环境下安装运行环境,故写成脚本以供参考。
以下软件已在CentOS7下离线安装成功,成功后个别配置文件(fastDFS,nginx等)需手动配置,脚本中不再赘述。
先说下离线安装包在linux中的放置路径:/opt/install_package
install_package文件夹下面文件列表:
fastDFS:
jdk1.8
LibreOffice
mysql 5.7
nginx
**完整shell代码如下
#!/bin/bash
function install_JDK(){
java -version >> /dev/null 2>&1
if [ $? -eq 0 ];then
echo "**************JDK is already installed***************"
return
fi
if [ ! -f "/opt/install_package/jdk1.8/jdk1.8.tar.gz" ];then
echo "*****************JDK installation package does not exist******************"
return
fi
echo "begin to install jdk"
cd jdk1.8
tar zxvf jdk1.8.tar.gz -C /usr/local/
chmod 777 /usr/local/jdk1.8/bin/java
chmod 777 /usr/local/jdk1.8/bin/javac
echo 'JAVA_HOME=/usr/local/jdk1.8' >> ~/.bash_profile
echo 'JAVA_BIN=$JAVA_HOME/bin' >> ~/.bash_profile
echo 'JRE_HOME=$JiAVA_HOME/jre' >> ~/.bash_profile
echo 'JRE_BIN=$JRE_HOME/bin' >> ~/.bash_profile
echo 'PATH=$JAVA_BIN:$JRE_BIN:$PATH' >> ~/.bash_profile
echo 'export JAVA_HOME JRE_HOME PATH' >> ~/.bash_profile
source ~/.bash_profile
java -version
if [ $? -eq 0 ];then
echo "JDK installed successfully"
else
echo "jdk install failed!"
fi
}
function install_mysql(){
isExit=`ps -ef | grep mysql| grep -v grep`
if [ -n "${isExit}" ];then
echo "**********************MySQL is already installed*****************************"
return
fi
if [ ! -f "mysql/mysql-5.7.9-1.el7.x86_64.rpm-bundle.tar" ];then
echo "*****************MySQL installation package does not exist******************"
return
fi
echo "**************begin to install mysql*********************"
cp -rf mysql /usr/local/
cd /usr/local/mysql
tar xvf mysql-5.7.9-1.el7.x86_64.rpm-bundle.tar
rpm -ivh mysql-community-common-5.7.9-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.9-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-devel-5.7.9-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-libs-compat-5.7.9-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-client-5.7.9-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-server-5.7.9-1.el7.x86_64.rpm --nodeps --force
service mysqld stop
echo "skip-grant-tables" >> /etc/my.cnf
service mysqld start
echo "****************mysql install sucessed**********************"
echo "****account:root,password is empty,Please change the password in time****"
}
function install_nginx(){
isExit=`ps -ef | grep nginx |grep -v grep`
if [ -n "${isExit}" ];then
echo "**********************Nginx is already installed*****************************"
return
fi
if [ ! -d "nginx" ];then
echo "Nginx installation package does not exist"
return
fi
pacakgeNum=`ls nginx|wc -w`
if [ ${pacakgeNum} -ne 4 ];then
echo "*********************Wrong number of installation packages*******************"
return
fi
echo "**********************begin to install nginx***********************"
cp -rf nginx /usr/local/
cd /usr/local/nginx
tar zxvf openssl-fips-2.0.10.tar.gz
cd openssl-fips-2.0.10
./config && make && make install
cd ..
tar zxvf pcre-8.42.tar.gz
cd pcre-8.42
./configure && make && make install
cd ..
tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure && make && make install
cd ..
tar zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure && make && make install
ln -s /usr/local/lib/libpcre.so.1 /lib64/
path=`whereis nginx |awk -F: '{print $2}'`
systemctl stop firewalld.service
${path}/sbin/nginx
if [ $? -eq 0 ];then
echo "****************Nginx installed successfully***********************"
else
echo "****************Nginx installation failed**************************"
fi
}
function isntall_LibreOffice(){
isExit=`ps -ef | grep libreoffice5.3 | grep -v grep`
if [ -n "${isExit}" ];then
echo "*******************Libreoffice is already installed**********************"
return
fi
if [ ! -f "libreOffice/LibreOffice_5.3.7_Linux_x86-64_rpm.tar.gz" ];then
echo "*****************LibreOffice installation package does not exist******************"
return
fi
tar zxvf libreOffice/LibreOffice_5.3.7_Linux_x86-64_rpm.tar.gz -C /usr/local/
cd /usr/local/LibreOffice_5.3.7.2_Linux_x86-64_rpm/RPMS
rpm -ivh *.rpm
cd /opt/libreoffice5.3/program
./soffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard &
isExit=`ps -ef | grep libreoffice5.3 | grep -v grep`
if [ -n "${isExit}" ];then
echo "*******************Libreoffice installed successfully**********************"
else
echo "*******************Libreoffice installation failed*************************"
fi
}
function install_fastDFS(){
while read -p "请输入fastDFS服务器ip地址:" cur_ip
do
ipcalc -cs ${cur_ip}
if [ "$?" -eq 0 ];then
break
else
echo "ip地址填写错误,请重新填写!"
continue
fi
done
cp -rf fastDFS /usr/local/
cd /usr/local/fastDFS
tar zxvf libevent-2.0.22-stable.tar.gz
cd libevent-2.0.22-stable
./configure --prefix=/data/libevent
cd /usr/local/fastDFS
tar -zxvf libfastcommon.tar.gz
cd libfastcommon
./make.sh
./make.sh install
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
cd /usr/local/fastDFS/
tar -zxvf FastDFS_v5.05.tar.gz
cd FastDFS
old='TARGET_PREFIX=$DESTDIR/usr'
new='TARGET_PREFIX=$DESTDIR/usr/local'
sed -i "s#$old#$new#g" make.sh
./make.sh && ./make.sh install
####配置tracker.conf
mkdir -p /data/fdfs/tracker
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
old=`cat /etc/fdfs/tracker.conf | grep "^base_path="`
new="base_path=/data/fdfs/tracker"
sed -i "s#$old#$new#g" /etc/fdfs/tracker.conf
if [ ! -f "/etc/init.d/fdfs_trackerd" ];then
cp -rf /usr/local/fastDFS/FastDFS/init.d/fdfs_trackerd /etc/init.d/
fi
##设置trackerd开机自启
chkconfig --add fdfs_trackerd
chkconfig fdfs_trackerd on
service fdfs_trackerd start
##配置storage.conf
mkdir -p /data/fdfs/storage
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
old=`cat /etc/fdfs/storage.conf | grep "^base_path="`
new="base_path=/data/fdfs/storage"
sed -i "s#$old#$new#g" /etc/fdfs/storage.conf
old=`cat /etc/fdfs/storage.conf | grep "^store_path0="`
new="store_path0=/data/fdfs/storage"
sed -i "s#$old#$new#g" /etc/fdfs/storage.conf
old=`cat /etc/fdfs/storage.conf | grep "^tracker_server="`
new="tracker_server=${cur_ip}:22122"
sed -i "s#$old#$new#g" /etc/fdfs/storage.conf
if [ ! -f "/etc/init.d/fdfs_storaged" ];then
cp -rf /usr/local/fastDFS/FastDFS/init.d/fdfs_storaged /etc/init.d/
fi
##设置tracker开机自启
chkconfig --add fdfs_storaged
chkconfig fdfs_storaged on
service fdfs_storaged start
##配置client.conf
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
old=`cat /etc/fdfs/client.conf | grep "^base_path="`
new="base_path=/data/fdfs/tracker"
sed -i "s#$old#$new#g" /etc/fdfs/client.conf
old=`cat /etc/fdfs/client.conf | grep "^tracker_server="`
new="tracker_server=${cur_ip}:22122"
sed -i "s#$old#$new#g" /etc/fdfs/client.conf
##获取tracker配置端口,需与client.conf保持一致
tracker_port=`cat /etc/fdfs/tracker.conf | grep "^http.server_port="|awk -F= '{print $2}'`
old=`cat /etc/fdfs/client.conf | grep "http.tracker_server_port="`
new="http.tracker_server_port=${tracker_port}"
sed -i "s#$old#$new#g" /etc/fdfs/client.conf
echo "*******************fastDFS installed successfully**********************"
echo "path of storage.conf is /etc/fdfs/storage.conf"
echo "path of tracker.conf is /etc/fdfs/tracker.conf"
echo "path of client.conf is /etc/fdfs/tracker.conf"
echo "path of data is /data/fdfs/storage/data"
}
Tips="
此脚本用来一键安装各种应用程序软件,包括jdk、应用程序、nginx等\n
1、离线安装jdk并配置环境变量\n
2、离线安装nginx\n
3、离线安装mysql\n
4、离线安装word转pdf打印服务(Libreoffice)\n
5、离线安装fastDFS\n
0、 退出
"
echo -e ${Tips}
while read -p "请输入您的操作序号:" val
do
if [ "$val" == "0" ];then
break
elif [ "$val" == "1" ];then
install_JDK
echo -e ${Tips}
continue
elif [ "$val" == "2" ];then
install_nginx
echo -e ${Tips}
continue
elif [ "$val" == "3" ];then
install_mysql
echo -e ${Tips}
continue
elif [ "$val" == "4" ];then
isntall_LibreOffice
echo -e ${Tips}
continue
elif [ "$val" == "5" ];then
install_fastDFS
echo -e ${Tips}
continue
else
echo "Wrong number input, please input again ."
fi
done
离线安装包(1G)下载链接: https://pan.baidu.com/s/14_NbibeuGwf35K4CmZ7HzQ 提取码: 829i