touch install_mysql.sh
chmod +x install_mysql.sh
sh install_mysql.sh 8.0.27
#!/bin/bash
# download wget
sudo yum -y install wget
# download libaio
sudo yum -y install libaio
# remove mariadb(centos7 default db)
sudo yum -y erase mariadb*
# get user input (version)
version=$1
# NHN CLOUD basically install under root(/), move to /home/centos
cd /home/centos
# download zip file
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-$version-linux-glibc2.12-x86_64.tar.xz
# upzip file
tar -xvf mysql-$version-linux-glibc2.12-x86_64.tar.xz
# change name
mv mysql-$version-linux-glibc2.12-x86_64/ mysql
# go mysql file
cd mysql
# touch my.cnf
touch my.cnf
# set up my.cnf
# vi 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
# make data,logs directory
mkdir data
mkdir logs
# give permission to centos
sudo chown -R centos:centos /home/centos/mysql
# initialize
/home/centos/mysql/bin/mysqld --defaults-file=/home/centos/mysql/my.cnf --initialize
# apply my.cnf
/home/centos/mysql/bin/mysqld --defaults-file=/home/centos/mysql/my.cnf &
# sleep for connect
sleep 3
# find rootpass
ROOTPASS="`sudo grep 'temporary password' /home/centos/mysql/logs/mysqld.log | sed 's/.*root@localhost: //'`"
# mysql start with rootpass
/home/centos/mysql/bin/mysql -uroot -p$ROOTPASS -S /home/centos/mysql/mysql.sock
virtual box 에서는 mysql 접속까지 한번에 진행되는데, NHN Cloud에서는 please use --connect-expired-password 오류가 남. 따로 임시비밀번호로 로그인하면 mysql 접속 됨. 이를 해결할 방법은 initialize 진행 시 -insecure를 해주는 방법밖에 없는지??
mysql 설치 완료되면 중간에 'OK' 뜸 => 확인되면 압축해제하는 형식으로
touch install_redis.sh
chmod +x install_redis.sh
sh install_redis.sh 6.2.6
#!/bin/bash
# get user input (version)
echo $1
# download wget
sudo yum -y install wget
# download gcc
sudo yum -y install gcc
# alias
alias redis-cli='src/redis-cli'
# download zip file
wget https://download.redis.io/releases/redis-$1.tar.gz
# unzip file
tar xzf redis-$1.tar.gz
# cd redis file
cd redis-$1
# make comfile
make
# start redis-server (daemon)
# edit redis.conf
sed -i 's/daemonize no/daemonize yes/g' redis.conf
src/redis-server ./redis.conf
# start alias redis-cli
redis-cli
스크립트를 NHN Cloud 인스턴스 생성 시 예약 스크립트에 넣어주세요.
#!/bin/bash
# download wget
sudo yum -y install wget
# download libaio
sudo yum -y install libaio
# remove mariadb(centos7 default db)
sudo yum -y erase mariadb*
# input version
version=8.0.27
# NHN CLOUD basically install under root(/), move to /home/centos
cd /home/centos
# download zip file
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-$version-linux-glibc2.12-x86_64.tar.xz
# upzip file
tar -xvf mysql-$version-linux-glibc2.12-x86_64.tar.xz
# change name
mv mysql-$version-linux-glibc2.12-x86_64/ mysql
# go mysql file
cd mysql
# touch my.cnf
touch my.cnf
# set up my.cnf
# vi 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
# make data,logs directory
mkdir data
mkdir logs
# set mysql.server route
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
# give permission to centos
sudo chown -R centos:centos /home/centos/mysql
# initialize
/home/centos/mysql/bin/mysqld --defaults-file=/home/centos/mysql/my.cnf --initialize
# apply my.cnf
/home/centos/mysql/bin/mysqld --defaults-file=/home/centos/mysql/my.cnf &
# start mysql.server
/home/centos/mysql/support-files/mysql.server start
# sleep for connect
# sleep 3
# find rootpass
ROOTPASS="`sudo grep 'temporary password' /home/centos/mysql/logs/mysqld.log | sed 's/.*root@localhost: //'`"
# echo rootpass
echo $ROOTPASS
# mysql start with rootpass
/home/centos/mysql/bin/mysql -uroot -p'cloud-init-output.log에서 확인한 임시비밀번호' -S /home/centos/mysql/mysql.sock
NHN CLOUD 실행 시 cloud-init-output.log
에서 ROOTPASS 확인하고 마지막 명령어는 따로 실행해주어야 함
임시비밀번호를 확인하는 또다른 방법의 코드
ROOTPASS=`cat /var/log/mysqld.log | grep generated | awk -F\localhost:" " {'print $2'}`
awk -F를 통해 localhost:" " 를 기준으로 앞에는 $1, 뒤에는 $2 로 구분지어줍니다.
임시비밀번호는 print $2 를 통해 출력가능
궁금점 🧐
NHN CLOUD에서 임시비밀번호를 사용해서 mysql 접속까지 한번에 실행해주는 건 불가능일까?
하지만 보안상 추천하진 않아요!
#!/bin/bash
# input version
version=6.2.6
# download wget
sudo yum -y install wget
# download gcc
sudo yum -y install gcc
# alias
alias redis-cli='src/redis-cli'
# download zip file
wget https://download.redis.io/releases/redis-$version.tar.gz
# unzip file
tar xzf redis-$version.tar.gz
# cd redis file
cd redis-$version
# make comfile
make
# start redis-server (daemon)
# edit redis.conf
sed -i 's/daemonize no/daemonize yes/g' redis.conf
src/redis-server ./redis.conf
# start alias redis-cli
redis-cli
NHN CLOUD 실행 시 마지막 명령어 src/redis-cli는 따로 실행해주어야 함
01/18 리뷰
피드백
질문
1) 보안상 취약점
2) 인터넷이 안되는 환경에서는?
---> 결론 : 내부망과 인터넷망(외부망)을 분리하는 망분리가 중요. 망분리는 내부망과 외부망을 분리해 외부로부터의 침입을 막고, 내부 정보의 유출을 막는 것이 목적. db는 보안이 중요하기 때문**
스크립트 고도화