MySQL/Redis 쉘스크립트 고도화

호밀빵 굽는 쿼카·2022년 1월 22일
0

NHN Cloud 인턴

목록 보기
13/48

Local

Redis

#!/bin/bash

# input version
version=6.2.6

# redis download link
ZIPLINK=https://download.redis.io/releases/redis-$version.tar.gz

# redis tar file
ZIPFILE=redis-$version.tar.gz

# download wget 
sudo yum -y install wget
# download gcc 
sudo yum -y install gcc
# check install gcc
str=`sudo grep 'Installed' /var/log/messages | awk -F\Installed: {'print $2'}`
if [[ "$str" == *wget* && "$str" == *gcc* ]]; then
        echo "ok"
else
        echo "fail"
        exit 9
fi

# alias
alias redis-cli='src/redis-cli'

# download tar file
touch redis-wget-log.txt
wget -o redis-wget-log.txt $ZIPLINK 
# check install redis tar file
if [[ `sudo grep "‘$ZIPFILE’ saved" /home/centos/redis-wget-log.txt` ]]; then
	echo "success install redis tar file"
	# unzip tar file
	tar xzf redis-$version.tar.gz >> redis-tar-log.txt
	# check unzip file exist
	if [ -e  redis-tar-log.txt ]; then
		echo "success"
	else
		echo "fail"
		exit 9
	fi
else
    echo "fail install redis zip file"
	exit 9
fi


# cd redis file
cd redis-$version
if [ $? -eq 0 ]; then
	echo "success"
else
	echo "fail"
	exit 9
fi


# make comfile
make
# check comfile
if [ $? -eq 0 ]; then 
	echo "success comfile"
else
	echo "fail comfile"
	exit 9
fi 


# start redis-server (daemon)
# edit redis.conf
sed -i 's/daemonize no/daemonize yes/g' redis.conf
# check edit redis.conf
if [[ `sudo grep "daemonize yes" ./redis.conf` ]]; then
	echo "success edit redis.conf"
	src/redis-server ./redis.conf
else
	echo "error edit redis.conf"
	exit 9
fi



# start alias redis-cli
redis-cli
if [ $? -eq 0 ]; then 
	echo "success"
else
	echo "error start"
    exit 9
fi


MySQL

#!/bin/bash

# input (version)
version=8.0.27

# mysql download link
ZIPLINK=https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-$version-linux-glibc2.12-x86_64.tar.xz

# mysql tar file
ZIPFILE="mysql-$version-linux-glibc2.12-x86_64.tar.xz"

# remove defualt db ( mariadb ) and check
sudo yum -y erase mariadb* 
if [ $? -eq 0 ];then
	echo "mariadb erase ok"
else
	echo "mariadb already no exist"
fi

# install wget,libaio and check
sudo yum -y install wget
sudo yum -y install libaio
str=`sudo grep 'Installed' /var/log/messages | awk -F\Installed: {'print $2'}`
if [[ "$str" == *wget* && "$str" == *libaio* ]]; then
	echo "success install"
else
    echo "fail install"
fi

# cd /home/centos
cd /home/centos
if [ $? -eq 0 ];then
	echo "success move to /home/centos"
else
	echo "fail move to /home/centos"
	exit 9
fi

# download tar file and check
touch wget-log.txt
wget -o mysql-wget-log.txt $ZIPLINK 
if [[ `sudo grep "saved" /home/centos/mysql-wget-log.txt` ]]; then
	echo "success install mysql zip file"
    # unzip tar file and check
	tar -xvf mysql-$version-linux-glibc2.12-x86_64.tar.xz >> mysql-tar-log.txt
	if [ -e mysql-tar-log.txt ]; then
		echo "success tar zip file"
	else
		echo "fail tar zip file"
		exit 9
    fi
else
    echo "fail install mysql zip file"
	exit 9
fi
	
    
# rename file name and check
mv mysql-$version-linux-glibc2.12-x86_64/ mysql
if [ -d 'mysql' ]; then
	echo "success change name"
	# edit my.cnf in mysql
	cd mysql
	touch my.cnf
	echo "[client]
port=3306
socket=/home/centos/mysql/mysql.sock
[mysqld]
socket=/home/centos/mysql/mysql.sock
basedir=/home/centos/mysql
datadir=/home/centos/mysql/data
user=centos
key_buffer_size=64M
max_allowed_packet=32M
#query_cache_size=32M
max_connections=2625
max_connect_errors=2000000
wait_timeout=60
explicit_defaults_for_timestamp = 1
pid-file=/home/centos/mysql/mysqld.pid
log-error=/home/centos/mysql/logs/mysqld.log
bulk_insert_buffer_size=0" > my.cnf
else
	echo "error change name"
	exit 9
fi

# make directory and check
mkdir data
mkdir logs
if [ -d 'data' ] && [ -d 'logs' ]; then
	echo "success mkdir"
else
    echo "fail mkdir"
	exit 9
fi

# edit path mysql.server and check
cd /home/centos/mysql/support-files        
sed -i '1,50s|'datadir='|'datadir=/home/centos/mysql/data'|g' mysql.server     
sed -i '1,50s|'basedir='|'basedir=/home/centos/mysql'|g' mysql.server
if [ $? -eq 0 ]; then
	echo "success support-files"
else
	echo "error support-files"
	exit 9
fi

# chown and check
sudo chown -R centos:centos /home/centos/mysql
if [ $? -eq 0 ]; then
	echo "success chown"
else
	echo "fail chown"
	exit 9
fi

# initialize and check
/home/centos/mysql/bin/mysqld --defaults-file=/home/centos/mysql/my.cnf --initialize
if [ $? -eq 0 ]; then
	echo "success initialize my.cnf"
else
	echo "fail initialize my.cnf"
	exit 9
fi

# server start and check
/home/centos/mysql/bin/mysqld --defaults-file=/home/centos/mysql/my.cnf &
/home/centos/mysql/support-files/mysql.server start
if [ $? -eq 0 ]; then
	echo "success start server"
else
	echo "fail start server"
	exit 9
fi

/home/centos/mysql/bin/mysql -uroot -p$ROOTPASS -S /home/centos/mysql/mysql.sock 로 실행



NHN Cloud

Redis

#!/bin/bash

# input version
version=6.2.6

# redis download link
ZIPLINK=https://download.redis.io/releases/redis-$version.tar.gz

# redis file
ZIPFILE=redis-$version.tar.gz

# nhn cloud default path is / -> move cd /home/centos
cd /home/centos

# download wget 
sudo yum -y install wget
# download gcc 
sudo yum -y install gcc
# check install gcc
str=`sudo grep 'Installed' /var/log/messages | awk -F\Installed: {'print $2'}`
if [[ "$str" == *gcc* ]]; then
        echo "ok"
else
        echo "fail"
        exit 9
fi

# alias
alias redis-cli='src/redis-cli'

# download zip file
# touch redis-wget-log.txt
# wget -o redis-wget-log.txt $ZIPLINK 
wget $ZIPLINK 
if [ -e $ZIPFILE ]; then
	echo "success install redis zip file"
	# unzip file
	tar xzf redis-$version.tar.gz >> redis-tar-log.txt
	if [ -e  redis-tar-log.txt ]; then
		echo "success"
	else
		echo "fail"
		exit 9
	fi
else
	echo "fail install redis zip file"
	exit 9
fi


# cd redis file
cd redis-$version
if [ $? -eq 0 ]; then
	echo "success"
else
	echo "fail"
	exit 9
fi


# make comfile
make
if [ $? -eq 0 ]; then 
	echo "success comfile"
else
	echo "fail comfile"
	exit 9
fi 


# start redis-server (daemon)
# edit redis.conf
sed -i 's/daemonize no/daemonize yes/g' redis.conf
if [[ `sudo grep "daemonize yes" ./redis.conf` ]]; then
	echo "success edit redis.conf"
	src/redis-server ./redis.conf
else
	echo "error edit redis.conf"
	exit 9
fi



# start alias redis-cli
redis-cli
if [ $? -eq 0 ]; then 
	echo "success"
else
	echo "error start"
    exit 9
fi

MySQL

#!/bin/bash

# input (version)
version=8.0.27

# mysql download link
ZIPLINK=https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-$version-linux-glibc2.12-x86_64.tar.xz

# mysql tar file
ZIPFILE=mysql-$version-linux-glibc2.12-x86_64.tar.xz

# remove defualt db ( mariadb ) and check
sudo yum -y erase mariadb* 
if [ $? -eq 0 ];then
	echo "mariadb erase ok"
else
	echo "mariadb already no exist"
fi

# install wget,libaio and check
sudo yum -y install wget
sudo yum -y install libaio
str=`sudo grep 'Installed' /var/log/messages | awk -F\Installed: {'print $2'}`
if [[ "$str" == *libaio* ]]; then
	echo "success install"
else
    echo "fail install"
    exit 9
fi

# cd /home/centos
cd /home/centos
if [ $? -eq 0 ];then
	echo "success move to /home/centos"
else
	echo "fail move to /home/centos"
	exit 9
fi

# download tar file and check
touch wget-log.txt
wget -o mysql-wget-log.txt $ZIPLINK 
if [[ `sudo grep "saved" /home/centos/mysql-wget-log.txt` ]]; then
	echo "success install mysql zip file"
    # unzip tar file and check
	tar -xvf mysql-$version-linux-glibc2.12-x86_64.tar.xz >> mysql-tar-log.txt
	if [ -e mysql-tar-log.txt ]; then
		echo "success tar zip file"
	else
		echo "fail tar zip file"
		exit 9
    fi
else
    echo "fail install mysql zip file"
	exit 9
fi
	
    
# rename file name and check
mv mysql-$version-linux-glibc2.12-x86_64/ mysql
if [ -d 'mysql' ]; then
	echo "success change name"
	# edit my.cnf in mysql
	cd mysql
	touch my.cnf
	echo "[client]
port=3306
socket=/home/centos/mysql/mysql.sock
[mysqld]
socket=/home/centos/mysql/mysql.sock
basedir=/home/centos/mysql
datadir=/home/centos/mysql/data
user=centos
key_buffer_size=64M
max_allowed_packet=32M
#query_cache_size=32M
max_connections=2625
max_connect_errors=2000000
wait_timeout=60
explicit_defaults_for_timestamp = 1
pid-file=/home/centos/mysql/mysqld.pid
log-error=/home/centos/mysql/logs/mysqld.log
bulk_insert_buffer_size=0" > my.cnf
else
	echo "error change name"
	exit 9
fi

# make directory and check
mkdir data
mkdir logs
if [ -d 'data' ] && [ -d 'logs' ]; then
	echo "success mkdir"
else
    echo "fail mkdir"
	exit 9
fi

# edit path mysql.server and check
cd /home/centos/mysql/support-files        
sed -i '1,50s|'datadir='|'datadir=/home/centos/mysql/data'|g' mysql.server     
sed -i '1,50s|'basedir='|'basedir=/home/centos/mysql'|g' mysql.server
if [ $? -eq 0 ]; then
	echo "success support-files"
else
	echo "error support-files"
	exit 9
fi

# chown and check
sudo chown -R centos:centos /home/centos/mysql
if [ $? -eq 0 ]; then
	echo "success chown"
else
	echo "fail chown"
	exit 9
fi

# initialize and check
/home/centos/mysql/bin/mysqld --defaults-file=/home/centos/mysql/my.cnf --initialize
if [ $? -eq 0 ]; then
	echo "success initialize my.cnf"
else
	echo "fail initialize my.cnf"
	exit 9
fi

# server start and check
/home/centos/mysql/bin/mysqld --defaults-file=/home/centos/mysql/my.cnf &
/home/centos/mysql/support-files/mysql.server start
if [ $? -eq 0 ]; then
	echo "success start server"
else
	echo "fail start server"
	exit 9
fi

/home/centos/mysql/bin/mysql -uroot -p$ROOTPASS -S /home/centos/mysql/mysql.sock 로 실행

profile
열심히 굽고 있어요🍞

0개의 댓글