Linux基础服务二进制一键安装shell脚本

  • 服务版本:

mysql-8.0.20
redis-5.0.0
jdk1.8.0_321
tomcat-8.0.1
minio-RELEASE.2021-10-23T03-28-24Z
nginx-1.20.2

  • 压缩包地址:

链接:https://pan.baidu.com/s/1xz5Ag0rHWUhMovTPiCgm4g?pwd=8dyr
提取码:8dyr

  • 解压之后执行前需要修改脚本,init.sh为安装脚本,这个压缩包自带所需的离线yum源,根据自己需求定义函数
#!/bin/bash
#此脚本所有的安装目录全部都在${max_dir}下,这个变量的会筛选出当前机器空间最大的挂载目录
#请在解压目录执行此脚本

file=$PWD
max_dir=$(df|sed '1d'|awk '$1 ~ "/dev/"{print $4,$6}'|awk 'BEGIN{max=0}{size=$1;if(size>=max){max=size;point=$2}}END{print point}')
if [ ${max_dir} != "/home" ] ; then 
	[ ! -d "${max_dir}/fosafer" ] && mkdir ${max_dir}/fosafer 
	[ ! -L "/home/fosafer" ] && ln -sf ${max_dir}/fosafer /home/fosafer 
	max_dir="${max_dir}/fosafer"
else
	[ ! -d "/home/fosafer" ] && mkdir /home/fosafer 
	max_dir="/home/fosafer"
fi

function init_yum(){
[ ! -d "/etc/yum.repos.d/bak" ] && mkdir /etc/yum.repos.d/bak 
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
cat << EOF >  /etc/yum.repos.d/init.repo
[init]
name=init
baseurl=file://${file}/rpm
gpgcheck=0    
enabled=1
EOF
yum clean all && \
yum makecache 
if [ $? -eq 0 ];then
    echo -e "\033[32m yum is ok \033[0m"
else
    echo -e "\033[31m yum no ok \033[0m"
    exit
fi
}

#安装mysql8.0.20
function mysql_install(){
rpm_mysql=`rpm -qa | grep mysql | wc -l`
rpm_mariadb=`rpm -qa | grep mariadb | wc -l`
if [[ $rpm_mysql -ge 1 ]];then
    for i in `rpm -qa | grep mysql`;do
        rpm -e --nodeps $i
    done
fi    
if [[ $rpm_mariadb -ge 1 ]];then
    for i in `rpm -qa | grep mariadb`;do
        rpm -e --nodeps $i
    done
fi

yum -y install jemalloc openssl-devel libaio 2&>/dev/null && \
cd ${max_dir} && \
#wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz && \
tar -xf $file/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz && \
mv mysql-8.0.20-linux-glibc2.12-x86_64 ${max_dir}/mysql && \
groupadd mysql && \
useradd -r -g mysql -s /sbin/nologin mysql && \
mkdir -p ${max_dir}/mysql/data && \
mkdir -p ${max_dir}/mysql/logs && \
mkdir -p ${max_dir}/mysql/conf && \
mkdir -p ${max_dir}/mysql/status && \
chown -R mysql:mysql ${max_dir}/mysql/data/ && \
chown -R mysql:mysql ${max_dir}/mysql/logs/ && \
chown -R mysql:mysql ${max_dir}/mysql/status/ && \
chmod -R 755 ${max_dir}/mysql/status/ && \
chmod -R 755 ${max_dir}/mysql/data/ && \
chmod -R 755 ${max_dir}/mysql/logs/ && \

cat << -EOF > ${max_dir}/mysql/conf/my.cnf  
[mysqld]
port=3306
basedir=${max_dir}/mysql
datadir=${max_dir}/mysql/data
log-error=${max_dir}/mysql/logs/error.log
socket=${max_dir}/mysql/status/mysql.sock
user=mysql
default_authentication_plugin=mysql_native_password
skip_host_cache
skip-name-resolve=1
#skip-grant-tables
default-time_zone = '+8:00'
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

[client]
port=3306
socket=${max_dir}/mysql/status/mysql.sock
-EOF

${max_dir}/mysql/bin/mysqld --defaults-file=${max_dir}/mysql/conf/my.cnf --initialize --user=mysql && \

passwd=`tail -1 ${max_dir}/mysql/logs/error.log  | awk '{print $13}' `
echo "mysql初始化密码为:$passwd"
${max_dir}/mysql/bin/mysqld_safe --defaults-file=${max_dir}/mysql/conf/my.cnf &
}

#修改mysql密码为fosafer.com
function mysql_init(){
if_mysql=`netstat -ntpl | grep mysqld | wc -l`
if [[ $if_mysql -ge 1 ]];then
    ${max_dir}/mysql/bin/mysqladmin -uroot -p"$1" -S ${max_dir}/mysql/status/mysql.sock password 'fosafer.com' 
    ${max_dir}/mysql/bin/mysql -uroot -pfosafer.com -S ${max_dir}/mysql/status/mysql.sock -e "show databases" 
    if [ $? -eq 0 ];then
        echo -e "\033[32m mysql inited \033[0m"
    fi
else
    echo -e "\033[31m mysql no started \033[0m"
fi 
}

#安装redis5.0
function redis_install(){
yum -y install lrzsz gcc  2&>/dev/null && \
cd ${max_dir} && \
#wget http://download.redis.io/releases/redis-5.0.0.tar.gz && \
tar -xf $file/redis-5.0.0.tar.gz  && \
cd ${max_dir}/redis-5.0.0 && \
make   
make install   
cd ${max_dir}/redis-5.0.0 && \
cp redis.conf redis.conf_bak  && \
sed -i 's/bind 127\.0\.0\.1/bind 0\.0\.0\.0/g' redis.conf && \
sed -i 's/protected-mode yes/protected-mode no/g' redis.conf && \
sed -i 's/daemonize no/daemonize yes/g' redis.conf && \
cd src/ && \
./redis-server ${max_dir}/redis-5.0.0/redis.conf  
sleep 5
if_redis=`netstat -ntpl | grep redis|wc -l`
if [ $if_redis -ge 1 ];then
    echo -e "\033[32m redis installed \033[0m"
    #[ ! -L "/usr/local/bin/redis-server" ] && ln -s ${max_dir}/redis-5.0.0/src/redis-server /usr/local/bin/redis-server
    #[ ! -L "/usr/local/bin/redis-cli" ] && ln -s ${max_dir}/redis-5.0.0/src/redis-cli /usr/local/bin/redis-cli
    #source /etc/profile
else
    echo -e "\033[31m redis no started \033[0m"
fi
}

#安装jdk1.8
function jdk_install(){
cd ${max_dir} && \
tar -xf $file/jdk-8u321-linux-x64.tar.gz && \
ln -s jdk1.8.0_321/ jdk && \

echo "export JAVA_HOME=${max_dir}/jdk" >/etc/profile.d/jdk.sh && \
source /etc/profile.d/jdk.sh && \
echo "export PATH=$PATH:$JAVA_HOME/bin" >> /etc/profile.d/jdk.sh && \
source /etc/profile.d/jdk.sh  && \
java -version 2&>/dev/null
if [ $? -eq 0 ];then
    echo -e "\033[32m jdk installed \033[0m"
else
    echo -e "\033[31m jdk install error \033[0m"
fi
}

#部署tomcat8.5
function tomcat_install(){
cd ${max_dir} && \
tar -xf $file/apache-tomcat-8.0.1.tar.gz && \
mv apache-tomcat-8.0.1 tomcat && \
cd ${max_dir}/tomcat/bin && \
./startup.sh  2&>/dev/null && \
sleep 5
if_tomcat=`netstat -ntpl|grep "java" | wc -l`
if [ $if_tomcat -ge 1 ];then
    echo -e "\033[32m tomcat installed \033[0m"
else
    echo -e "\033[31m tomcat no started \033[0m"
fi
}

#部署minio
function minio_install(){
cd ${max_dir} && \
tar -xf $file/minio_amd64_install.tar.gz && \
cd minio_amd64_install && \
bash ctl.sh install && \
bash ctl.sh start 
sleep 5
if_minio=`netstat -ntpl | grep minio | wc -l`
if [ $if_minio -ge 1 ];then
    echo -e "\033[32m minio installed \033[0m"
else
    echo -e "\033[31m minio install error \033[0m"
fi
}

#部署nginx
function nginx_install(){
yum -y install gcc gcc-c++ zlib-devel openssl openssl-devel 2&>/dev/null && \
cd ${max_dir} && \
tar -xf $file/nginx-1.20.2.tar.gz && \
tar -xf $file/pcre-8.40.tar.gz && \
cd ${max_dir}/pcre-8.40 && \
./configure && make && make install && \
cd ${max_dir}/nginx-1.20.2 && \
./configure --prefix=${max_dir}/nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module && \
make && make install && \
ln -s ${max_dir}/nginx/sbin/nginx /usr/local/sbin/ 
nginx
sleep 5
if_nginx=`netstat -ntpl | grep "nginx" | wc -l `
if [ $if_nginx -ge 1 ];then
    echo -e "\033[32m nginx installed \033[0m"
else
    echo -e "\033[31m nginx no started \033[0m"
fi
}

function init_1(){
init_yum
minio_install
jdk_install
tomcat_install
nginx_install
redis_install
mysql_install
}

#第一次执行,进行安装服务
init_1
#最后需要手动输入一下回车键,然后修改脚本开始第二次执行即可
#第二次修改mysql密码即可
#等待上面几个函数执行完成之后,执行下面这个修改mysql密码,执行脚本后面跟初始化密码,可以使用单引号括住,以免识别密码错误,执行时要把上面的几个函数调用注释掉
#mysql_init $1


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值