[init] 修改大量代码

This commit is contained in:
zeaslity
2023-10-20 14:10:20 +08:00
parent 3b30f5eee1
commit 7beab04895
8 changed files with 419 additions and 234 deletions

View File

@@ -1,28 +1,25 @@
#!/bin/bash
.
## 对外暴露的安装Redis的主函数
InstallRedis() {
install_redis() {
FunctionStart
RedisPort="6379"
RedisInstallMethod="binary"
RedisInstallHelp="0"
local redis_port="6379"
local redis_install_method="binary"
local redis_install_help="0"
while [[ $# > 0 ]]; do
while [[ $# -gt 0 ]]; do
case "$1" in
-p | --port)
RedisPort="${2}"
redis_port="${2}"
shift # past argument
;;
-m | --method)
RedisInstallMethod="${2}"
redis_install_method="${2}"
shift # past argument
;;
-h | --help)
RedisInstallHelp="1"
redis_install_help="1"
;;
*)
echo "输入的内容有误,请检查!"
@@ -32,7 +29,7 @@ InstallRedis() {
shift # past argument or value
done
if [ "${RedisInstallHelp}" -eq "1" ]; then
if [ "${redis_install_help}" -eq "1" ]; then
cat - 1>&2 <<EOF
./install-release.sh [-h] [-p|--port 6379] [-m|--method binary|docker]
-h, --help 打印此安装帮助说明
@@ -41,28 +38,37 @@ InstallRedis() {
EOF
fi
# echo $RedisPort
# echo $RedisInstallMethod
# echo $redis_port
# echo $redis_install_method
if [[ ${RedisInstallMethod} == "binary" ]]; then
installRedisBinary ${RedisPort}
if [[ ${redis_install_method} == "binary" ]]; then
install_redis_binary "${redis_port}"
else
installRedisDocker ${RedisPort}
install_redis_docker "${redis_port}"
fi
FunctionEnd
}
installRedisBinary() {
RedisPort=""
#######################################
# description
# Globals:
# redis_port
# Arguments:
# 1
# Returns:
# 3 ...
#######################################
install_redis_binary() {
redis_port=""
if [[ $1 -ne " " ]]; then
RedisPort="$1"
echo "Redis Port = ${RedisPort}"
redis_port="$1"
echo "Redis Port = ${redis_port}"
fi
echo "InstallRedisBinary"
CMD_REMOVE gcc
installDemandSoftwares gcc wget
CMD_REMOVE gcc
installDemandSoftwares gcc wget
echo "开始下载 Redis 6.2.6 的二进制包!"
wget https://oss.107421.xyz/redis-6.2.6.tar.gz
@@ -94,22 +100,22 @@ installRedisBinary() {
if [ -e redis-6.2.6.conf ] && [ -e redis-server-6.2.6.service ]; then
echo "redis配置文件下载成功开始进行修改"
echo ""
touch /var/log/redis_${RedisPort}.log
mkdir -p /var/redis/${RedisPort}
touch /var/log/redis_${redis_port}.log
mkdir -p /var/redis/${redis_port}
mkdir -p /etc/redis/
sed -i "s/RedisPort/${RedisPort}/g" redis-6.2.6.conf
cp redis-6.2.6.conf /etc/redis/${RedisPort}.conf
sed -i "s/RedisPort/${redis_port}/g" redis-6.2.6.conf
cp redis-6.2.6.conf /etc/redis/${redis_port}.conf
sed -i "s/RedisPort/${RedisPort}/g" redis-server-6.2.6.service
sed -i "s/RedisPort/${redis_port}/g" redis-server-6.2.6.service
cp redis-server-6.2.6.service /etc/init.d/redisd
cd /etc/init.d
chmod +x /etc/init.d/redisd
if [ command_exists chkconfig ]; then
if command_exists chkconfig ; then
chkconfig redisd on
elif [ command_exists update-rc.d ]; then
elif command_exists update-rc.d ; then
update-rc.d redisd defaults
else
echo "所需要的守护程序未安装,请手动设置!!"
@@ -135,17 +141,27 @@ installRedisBinary() {
}
installRedisDocker() {
RedisPort=""
#######################################
# description
# Globals:
# RED
# redis_port
# Arguments:
# 1
# Returns:
# 3 ...
#######################################
install_redis_docker() {
redis_port=""
if [[ $1 -ne " " ]]; then
RedisPort="$1"
echo "Redis Port = ${RedisPort}"
redis_port="$1"
echo "Redis Port = ${redis_port}"
fi
echo "InstallRedisDocker"
echo ""
if [ ! command_exists "docker info" ]; then
if ! command_exists "docker info" ; then
colorEcho ${RED} "docker 未安装!! 无法使用docker的方式安装 redis"
return 3
fi
@@ -161,7 +177,7 @@ installRedisDocker() {
docker run -d \
-e ALLOW_EMPTY_PASSWORD=yes \
-e REDIS_AOF_ENABLED=no \
-e REDIS_PORT_NUMBER=${RedisPort} \
-e REDIS_PORT_NUMBER=${redis_port} \
--name redis-server \
--network host \
bitnami/redis:6.2.6
@@ -178,7 +194,7 @@ InstallMysql() {
colorEcho ${BLUE} "本脚本默认安装版本为 8.0.27 的MySQL "
colorEcho ${BLUE} "本脚本默认安装版本为 8.0.27 的MySQL "
while [[ $# > 0 ]]; do
while [[ $# -gt 0 ]]; do
case "$1" in
-p | --port)
MysqlPort="${2}"
@@ -312,7 +328,7 @@ InstallJDK() {
JDK_Install_Method="binary"
JDKInstallHelp="0"
while [[ $# > 0 ]]; do
while [[ $# -gt 0 ]]; do
case "$1" in
-v | --version)
JDK_VERSION="${2}"
@@ -439,3 +455,21 @@ installJDKPackage() {
java -version
}
install_golang_1.21.3(){
FunctionStart "开始安装Golang运行环境"
wget --timeout=10 -q https://go.dev/dl/go1.21.3.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.3.linux-amd64.tar.gz
log "开始配置环境变量!"
sed -i "$ a export GOPATH=/usr/local/go" /etc/profile
sed -i "$ a PATH=$PATH:/usr/local/go/bin" /etc/profile
source /etc/profile
log "查看golang的版本"
go version
}