- Apache - Tomcat - MySQL์ Source๋ก ์ปดํ์ผํ์ฌ ์ค์นํ๋ค.
- service๋ฅผ ๋ฑ๋กํ์ฌ systemctl ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ ์ ์๋๋ก ํ๋ค.
- mod_jk ๋ชจ๋์ ์ฌ์ฉํ์ฌ Apache-Tomcat์ ์ฐ๋ํ๋ ๋ฐฉ๋ฒ์ ํ์ ํ๋ค.
- JDBC Driver๋ฅผ ์ฌ์ฉํ์ฌ Tomcat-MySQL์ ์ฐ๋ํด๋ณธ๋ค.
- MySQL Master - Slave ์๋ฒ ๊ฐ์ Replication ์ฐ๋์ ํ์ฌ ๋ฐ์ดํฐ์ ๊ฐ์ฉ์ฑ์ ๋์ธ๋ค.
- OS : Ubuntu 18.04
- Instance Type : t2.micro
- Apache 2.4.46
- tomcat_connector : 1.2.48
- Instance Type : t2.micro
- OS : Ubuntu 18.04
- Tomcat : 9.0.41
- Instance Type : t2.micro
- OS : Ubuntu 18.04
- MySQL : 5.7.31
[1] VPC
: ์ฌ์ฉ์๊ฐ ์ ์ํ ๋ ผ๋ฆฌ์ ์ผ๋ก ๋ถ๋ฆฌ๋ ํด๋ผ์ฐ๋ ๋คํธ์ํฌ
[2] Subnet
: VPC ๋ด์์ IPv4 ์ฃผ์๊ฐ CIDR ๋ธ๋ก์ ์ํด ๋๋ ์ง ์ฃผ์ ๋จ์
[3] Internet Gateway
: ์ธํฐ๋ท์ ์ฐ๊ฒฐ๋ Host ( Public Subnet์ ์ํ NAT )
[4] NAT Gateway
: Private Subnet์ ์ธํฐ๋ท์ ํฅํ Outbound ํธ๋ํฝ ํ์ฉ ( IPv4 ์ ์ฉ )
[5] Security Group
: ์ธ์คํด์ค์ ๋ํ Inbound & Outbound ํธ๋ํฝ ์ ์ด (๊ฐ์ ๋ฐฉํ๋ฒฝ)
[6] Routing Table
: Traffic์ ์ด๋๋ก ๋ณด๋ด์ค ์ง ์ค์
[7] 3-Tier Public Routing Table
: ํด๋น ๋ผ์ฐํ ํ ์ด๋ธ์ ๊ฐ์ง Subnet๋ค์ IGW๋ก ๊ฐ ๊ฒ์ ์ ์
[8] 3-Tier Private Routing Table (์ด๊ธฐ)
: ํด๋น ๋ผ์ฐํ ํ ์ด๋ธ์ ๊ฐ์ง Subnet๋ค์ NAT๋ก ๊ฐ ๊ฒ์ ์ ์
[9] 3-Tier Private Routing Table (DB Instance์์ ํ์ํ ํจํค์ง, ํ์ผ ์ค์น ํ)
: DB ์ธ์คํด์ค๊ฐ ์๋ Subnet์ ๋ด๋ถ์์๋ง ํต์ ํ ๊ฒ์ ์ ์
[10] EC2 Instance
: ๊ฐ์ ์ปดํจํ ํ๊ฒฝ
[11] Load Balancer
: AWS์์ ์ ๊ณตํ๋ ๋ถํ ๋ถ์ฐ ์ฅ์น
- Bastion โ web, was, db ์ธ์คํด์ค๋ก ssh ์๊ฒฉ ์ ์์ ํ๊ธฐ ์ํด ssh key๋ฅผ ์ฎ๊น
scp -i .\3tier-bastion-key.pem .\3tier-web-key.pem ubuntu@<<Bastion IP>>:/home/ubuntu
### Bastion -> WEB
### 3tier-was-key๋ก ์ ์์ ๋ถํ, 3tier-web-key๋ก ์ ์์ ์ฑ๊ณต
ubuntu@ip-10-0-1-41:~/.ssh$ ssh -i 3tier-was-key.pem [email protected]
[email protected]: Permission denied (publickey).
ubuntu@ip-10-0-1-41:~/.ssh$ ssh -i 3tier-web-key.pem [email protected]
Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 5.4.0-1029-aws x86_64)
### Bastion -> WAS
ubuntu@ip-10-0-1-41:~/.ssh$ ssh -i 3tier-was-key.pem [email protected]
The authenticity of host '10.0.5.115 (10.0.5.115)' can't be established.
ECDSA key fingerprint is SHA256:q7eHQcdu530g9oOAkew8cJjnnRtd/P1AezXpWAMxK68.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.5.115' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 5.4.0-1029-aws x86_64)
### Bastion -> DB
ubuntu@ip-10-0-1-41:~/.ssh$ ssh -i 3tier-db-key.pem [email protected]
The authenticity of host '10.0.7.165 (10.0.7.165)' can't be established.
ECDSA key fingerprint is SHA256:VB2YaUg2m5J6KLv3VCbxo+T51Xvqdfci+BFN0Y+5RtE.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.7.165' (ECDSA) to the list of known hosts.
ubuntu@ip-10-0-1-41:~$ chmod 400 *
ubuntu@ip-10-0-1-41:~/.ssh$ ls -al
total 32
drwx------ 2 ubuntu ubuntu 4096 Jan 19 08:31 .
drwxr-xr-x 5 ubuntu ubuntu 4096 Jan 19 08:31 ..
-r-------- 1 ubuntu ubuntu 1704 Jan 19 08:30 3tier-bastion-key.pem
-r-------- 1 ubuntu ubuntu 1700 Jan 19 08:30 3tier-db-key.pem
-r-------- 1 ubuntu ubuntu 1700 Jan 19 08:30 3tier-was-key.pem
-r-------- 1 ubuntu ubuntu 1704 Jan 19 08:30 3tier-web-key.pem
-rw------- 1 ubuntu ubuntu 399 Jan 19 07:59 authorized_keys
-rw-r--r-- 1 ubuntu ubuntu 222 Jan 19 08:26 known_hosts
- ์ปดํ์ผ ์ค์น๋ฅผ ์ํด ํ์ํ ํจํค์ง ์ค์น
- PCRE, APR, APR-util, HTTPD ์์ค ํ์ผ ๋ฐ์์ค๊ธฐ
- ์์ค ํ์ผ ํ๊ฒฝ ์ค์ ( ./configure )
- ์์คํ์ผ ์ปดํ์ผ ( make, make install )
- systemd ์๋น์ค ํ์ผ ์์ฑ ๋ฐ ๋ฑ๋ก
- Test
sudo su -
# Install the necessary packages
apt-get update -y
apt-get install build-essential -y
apt-get install libexpat1-dev -y
cd /usr/local/src
wget https://ftp.pcre.org/pub/pcre/pcre-$PCRE_VERSION.tar.gz
wget https://downloads.apache.org//apr/apr-$APR_VERSION.tar.gz
wget https://downloads.apache.org//apr/apr-util-$APRUTIL_VERSION.tar.gz
wget https://downloads.apache.org//httpd/httpd-$HTTPD_VERSION.tar.gz
## 1. apr
cd /usr/local/src/apr-$APR_VERSION
./configure --prefix=/usr/local/apr
make; make install
## 2. apr-util
cd /usr/local/src/apr-util-$APRUTIL_VERSION
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make; make install
## 3. PCRE
cd /usr/local/src/pcre-$PCRE_VERSION
./configure --prefix=/usr/local/pcre
make; make install
## 4. HTTPD
cd /usr/local/src/httpd-$HTTPD_VERSION
./configure --prefix=/usr/local/apache \
--enable-module=so --enable-rewrite --enable-so \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--with-pcre=/usr/local/pcre \
--enable-mods-shared=all
make; make install
## ์คํ : httpd -k start
## ์ข
๋ฃ : httpd -k stop
/usr/local/apache2.4/bin/httpd -k start
root@ip-10-0-3-171:/usr/local/apache2.4# ./bin/httpd -k restart
root@ip-10-0-3-171:/usr/local/apache2.4# ps -ef | grep httpd
root 31522 1 0 00:41 ? 00:00:00 ./bin/httpd -k start
daemon 31627 31522 0 00:42 ? 00:00:00 ./bin/httpd -k start
daemon 31628 31522 0 00:42 ? 00:00:00 ./bin/httpd -k start
daemon 31629 31522 0 00:42 ? 00:00:00 ./bin/httpd -k start
root 31712 1879 0 00:42 pts/0 00:00:00 grep --color=auto httpd
root@ip-10-0-3-171:/usr/local/apache2.4# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 872/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1184/sshd
tcp6 0 0 :::22 :::* LISTEN 1184/sshd
tcp6 0 0 :::80 :::* LISTEN 31522/./bin/httpd
root@ip-10-0-3-171:/usr/local/apache2.4# curl localhost
<html><body><h1>It works!</h1></body></html>
vim /usr/lib/systemd/system/httpd.service
[Unit]
Description=apache
After=network.target syslog.target
[Service]
Type=forking
User=root
Group=root
ExecStart=/usr/local/apache2.4/bin/apachectl start
ExecStop=/usr/local/apache2.4/bin/apachectl stop
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
root@ip-10-0-3-171:/usr/local/apache2.4# systemctl restart httpd
root@ip-10-0-3-171:/usr/local/apache2.4# systemctl status httpd
โ httpd.service - apache
Loaded: loaded (/lib/systemd/system/httpd.service; disabled; vendor preset: enabled)
Active: active (running) since Mon 2021-01-25 00:47:50 UTC; 1s ago
Process: 32511 ExecStop=/usr/local/apache2.4/bin/apachectl stop (code=exited, status=0/SUCCESS)
Process: 32514 ExecStart=/usr/local/apache2.4/bin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 32527 (httpd)
Tasks: 82 (limit: 1140)
CGroup: /system.slice/httpd.service
โโ32527 /usr/local/apache2.4/bin/httpd -k start
โโ32528 /usr/local/apache2.4/bin/httpd -k start
โโ32529 /usr/local/apache2.4/bin/httpd -k start
โโ32530 /usr/local/apache2.4/bin/httpd -k start
Jan 25 00:47:50 ip-10-0-3-171 systemd[1]: Stopped apache.
Jan 25 00:47:50 ip-10-0-3-171 systemd[1]: Starting apache...
Jan 25 00:47:50 ip-10-0-3-171 systemd[1]: Started apache.
root@ip-10-0-3-171:/usr/local/apache2.4# systemctl stop httpd
root@ip-10-0-3-171:/usr/local/apache2.4# systemctl status httpd
โ httpd.service - apache
Loaded: loaded (/lib/systemd/system/httpd.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Jan 25 00:47:29 ip-10-0-3-171 systemd[1]: Started apache.
Jan 25 00:47:50 ip-10-0-3-171 systemd[1]: Stopping apache...
Jan 25 00:47:50 ip-10-0-3-171 systemd[1]: Stopped apache.
Jan 25 00:47:50 ip-10-0-3-171 systemd[1]: Starting apache...
Jan 25 00:47:50 ip-10-0-3-171 systemd[1]: Started apache.
Jan 25 00:47:59 ip-10-0-3-171 systemd[1]: Stopping apache...
Jan 25 00:47:59 ip-10-0-3-171 systemd[1]: Stopped apache.
Jan 25 00:47:59 ip-10-0-3-171 systemd[1]: /lib/systemd/system/httpd.service:13: Unknown lvalue 'Umask' in section 'Service'
Jan 25 00:47:59 ip-10-0-3-171 systemd[1]: /lib/systemd/system/httpd.service:13: Unknown lvalue 'Umask' in section 'Service'
Jan 25 00:48:00 ip-10-0-3-171 systemd[1]: /lib/systemd/system/httpd.service:13: Unknown lvalue 'Umask' in section 'Service'
- Java Runtime ( JRE 11 ) ์ค์น
- /etc/profile ๋ชจ๋ ์ฌ์ฉ์ ๋์ ํ๊ฒฝ๋ณ์ ๋ฑ๋ก
- Tomcat Group, User ์์ฑ
- Apache-Tomcat ์ค์น
- Tomcat ์๋น์ค ํ์ผ ์์ฑ ๋ฐ ๋ฑ๋ก
- Test
- jdk ์ค์น
# sudo su -๋ฅผ ์ํ ๊ฒฝ์ฐ ๊ถํ ์ค์ ์ ์ ํด์ฃผ์ด์ผ ํจ
sudo su -
sudo apt-get update -y
sudo apt-get install openjdk-11-jre-headless -y
- ํ๊ฒฝ๋ณ์ ๋ฑ๋ก
- /usr/bin/java ๊ฒฝ๋ก์ Symbolic Link ๊ฒฝ๋ก๊ฐ ๊ฑธ๋ ค์์ผ๋ฏ๋ก ์ค์ ๊ฒฝ๋ก๋ฅผ ์ฐพ์ ํ๊ฒฝ๋ณ์๋ฅผ ๋ฑ๋กํด์ฃผ์ด์ผ ํ๋ค.
- ์ค์ ๊ฒฝ๋ก๋ฅผ ์ฐพ์์ผ๋ฉด 3๊ฐ์ง (JAVA_HOME, PATH, CLASSPATH)๋ฅผ ๋ฑ๋ก
root@ip-10-0-5-115:/home/ubuntu# readlink -f /usr/bin/java
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
## JAVA_HOME, CATALINA_HOME, PATH ํ๊ฒฝ๋ณ์ ๋ฑ๋ก
sudo bash -c 'cat >> /etc/profile' << EOF
# 1. JAVA_HOME DIR
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/
# 2. TOMCAT SERVER HOME DIR
CATALINA_HOME=/usr/local/tomcat
# 3. binary
PATH=$PATH:/usr/lib/jvm/java-11-openjdk-amd64/bin
export JAVA_HOME CATALINA_HOME PATH
EOF
## source ๋ช
๋ น์ด๋ก ์ ์ฉ
source /etc/profile
echo $JAVA_HOME
echo $CATALINA_HOME
echo $PATH
root@ip-10-0-5-206:~# java -version
openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04)
OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04, mixed mode, sharing)
sudo groupadd tomcat
sudo useradd -s `which nologin | sed -n 1p` -g tomcat -d /usr/local/tomcat tomcat
cd /usr/local/src
sudo wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.41/bin/apache-tomcat-9.0.41.tar.gz
sudo tar -zxvf apache-tomcat-9.0.41.tar.gz
sudo mv apache-tomcat-9.0.41 /usr/local/tomcat
cd /usr/local
sudo chmod -R 755 tomcat
sudo chown -R tomcat:tomcat tomcat
cat << EOF >> /etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
SuccessExitStatus=143
Restart=always
RestartSec=10
UMask=0007
[Install]
WantedBy=multi-user.target
EOF
## ๋๋ชฌ ์ฌ์์
systemctl daemon-reload
systemctl restart tomcat
systemctl status tomcat
โ tomcat.service - Apache Tomcat Web Application Container
Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: enabled)
Active: active (running) since Mon 2021-01-25 01:05:07 UTC; 2s ago
Process: 4318 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
## netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 882/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1181/sshd
tcp6 0 0 :::8080 :::* LISTEN 4339/java
tcp6 0 0 :::22 :::* LISTEN 1181/sshd
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 4339/java
## ์ ์ Test
curl localhost:8080
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Apache Tomcat/9.0.41</title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link href="tomcat.css" rel="stylesheet" type="text/css" />
</head>
..
..
..
..
- ์ปดํ์ผ ์ค์น๋ฅผ ์ํด ํ์ํ ํจํค์ง ์ค์น
- User, Group ์์ฑ
- Source ํ์ผ Download ๋ฐ ์์ถ ํด์
- cmake ์ํ ํ make ๋น๋
- ๋๋ ํฐ๋ฆฌ ์์ฑ ๋ฐ ๊ถํ ๋ณ๊ฒฝ
- my.cnf ์์ฑ ๋ฐ DB ์์ฑ ํ ์ด๊ธฐ ์ค์
- DB ์๋น์ค ๋ฑ๋ก ๋ฐ ์์
- Test
sudo apt install build-essential bison \
gcc g++ libncurses5-dev libxml2-dev openssl \
libssl-dev curl libcurl4-openssl-dev libjpeg-dev \
libpng-dev libfreetype6-dev libsasl2-dev \
autoconf libncurses5-dev libtirpc-dev \
ncurses* cmake-gui cmake -y
-
cmake : make์ ์์ค๊ด๋ฆฌ ๋ฌธ์ ์ ์ ๊ฐ์ ์์ผ ์๋กญ๊ฒ ๋์จ ๋น๋ ํ๋ ์์ํฌ ํ๋ก๊ทธ๋จ
( centos 7.x ์ด์ ์ง์)
-
make : ์ง์ ์์ค๋ฅผ ๋น๋ํ๋ ํ๋ก๊ทธ๋จ (์์ค๋ฅผ ๋น๋ํ์ฌ ๊ธฐ๊ณ์ด๋ก ๋ง๋ค์ด์ฃผ๋ ํต์ฌ์ ์ธ ์ญํ , GNU make 3.75 ์ด์ ๋ฒ์ ์ ๊ฐ๋ ฅํ ๊ถ๊ณ )
-
ncurses library : ํ๋ก๊ทธ๋๋จธ๊ฐ ํ ์คํธ ์ฌ์ฉ์ ์ธํฐํ์ด์ค๋ฅผ ํฐ๋ฏธ๋ ๋ ๋ฆฝ ๋ฐฉ์์ผ๋ก ๊ธฐ๋กํ ์ ์๋๋ก APU๋ฅผ ์ ๊ณตํ๋ ํ๋ก๊ทธ๋๋ฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
-
boost : ๊ฐ์ข ๋ฐ์ดํฐ ๊ตฌ์กฐ์ ์๊ณ ๋ฆฌ์ฆ์ ๋ชจ์๋ C++ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
- nologin : ์ ์ ์ ๋ก๊ทธ์ธ์ ์ฌ์ฉ ๋ชปํ๊ฒ ํจ ( mysql์ด๋ผ๋ ์ ์ ๋ mysql ๋ฐ๋ชฌ์ ์คํํ๊ธฐ ์ํ ์ ์ ์ผ ๋ฟ, ๋ณด์ ๊ฐํ ์ธก๋ฉด)
root@ip-10-0-7-218:~# which nologin
/usr/sbin/nologin
root@ip-10-0-7-218:~# useradd -s /usr/sbin/nologin -g mysql mysql
cd /usr/local/src
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-5.7.31.tar.gz
tar zxvf mysql-boost-5.7.31.tar.gz
cd mysql-5.7.31
sudo cmake \
'-DCMAKE_INSTALL_PREFIX=/usr/local/mysql5.7' \
'-DINSTALL_SBINDIR=/usr/local/mysql5.7/bin' \
'-DINSTALL_BINDIR=/usr/local/mysql5.7/bin' \
'-DMYSQL_DATADIR=/usr/local/mysql5.7/data' \
'-DINSTALL_SCRIPTDIR=/usr/local/mysql5.7/bin' \
'-DWITH_INNOBASE_STORAGE_ENGINE=1' \
'-DWITH_PARTITION_STORAGE_ENGINE=1' \
'-DSYSCONFDIR=/usr/local/mysql5.7/etc' \
'-DDEFAULT_CHARSET=utf8mb4' \
'-DDEFAULT_COLLATION=utf8mb4_general_ci' \
'-DWITH_EXTRA_CHARSETS=all' \
'-DENABLED_LOCAL_INFILE=1' \
'-DMYSQL_TCP_PORT=3306' \
'-DMYSQL_UNIX_ADDR=/tmp/mysql.sock' \
'-DCURSES_LIBRARY=/usr/lib/x86_64-linux-gnu/libncurses.so' \
'-DCURSES_INCLUDE_PATH=/usr/include' \
'-DDOWNLOAD_BOOST=1' \
'-DWITH_BOOST=./boost' \
'-DWITH_ARCHIVE_STORAGE_ENGINE=1' \
'-DWITH_BLACKHOLE_STORAGE_ENGINE=1' \
'-DWITH_PERFSCHEMA_STORAGE_ENGINE=1' \
'-DWITH_FEDERATED_STORAGE_ENGINE=1'
make; make install
cd /usr/local/mysql5.7
mkdir logs tmp data
touch /usr/local/mysql5.7/logs/mysqld_safe.err
cd /usr/local/
chown -R mysql:mysql mysql5.7
## ํผ๋ฏธ์
๋ณ๊ฒฝ
chown -R mysql:mysql /usr/local/mysql5.7
## ์ฌ๋ณผ๋ฆญ ๋งํฌ ์ฌ์ฉ
cd /usr/local
ln -s mysql5.7 mysql
## MySQL ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ฑ๋ก
root@ip-10-0-7-218:/usr/local# cat /etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf
root@ip-10-0-7-218:/usr/local# ldconfig
include /usr/local/mysql/lib
## ํ๊ฒฝ๋ณ์์ PATH ์ถ๊ฐ
vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile
vim /etc/my.cnf
[mysql]
no-auto-rehash
show-warnings
prompt=\u@\h:\d_\R:\m:\\s>
pager="less -n -i -F -X -E"
[mysqld]
server-id=1
port = 3306
bind-address = 0.0.0.0
basedir = /usr/local/mysql
datadir= /usr/local/mysql/data
tmpdir=/usr/local/mysql/data
socket=/tmp/mysql.sock
user=mysql
skip_name_resolve
#timestamp
explicit_defaults_for_timestamp = TRUE
### MyISAM Spectific options
key_buffer_size = 100M
### INNODB Spectific options
default-storage-engine = InnoDB
innodb_buffer_pool_size = 384M
#User Table Datafile
innodb_data_home_dir = /usr/local/mysql/data/
innodb_data_file_path = ib_system:100M:autoextend
innodb_file_per_table=ON
innodb_log_buffer_size = 8M
innodb_log_files_in_group = 3
innodb_log_file_size=200M
innodb_log_files_in_group=4
#innodb_log_group_home_dir = /usr/local/mysql/data/redologs
#innodb_undo_directory = /usr/local/mysql/data/undologs
innodb_undo_tablespaces = 1
### Connection
back_log = 100
max_connections = 1000
max_connect_errors = 1000
wait_timeout= 60
### log
# Error Log
log_error=/usr/local/mysql/logs/mysqld.err
log-output=FILE
general_log=0
slow-query-log=0
long_query_time = 5
# 5 sec
slow_query_log_file = /usr/local/mysql/logs/slow_query.log
pid-file=/usr/local/mysql/tmp/mysqld.pid
###chracterset
character-set-client-handshake=OFF
skip-character-set-client-handshake
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
[mysqld_safe]
log_error=/usr/local/mysql/logs/mysqld_safe.err
pid-file=/usr/local/mysql/tmp/mysqld.pid
### 1. DB ์์ฑ
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
root@ip-10-0-7-218:/usr/local/mysql/bin# ls -al /usr/local/mysql/data/
total 931908
drwxr-xr-x 5 mysql mysql 4096 Jan 25 04:21 .
drwxr-xr-x 13 mysql mysql 4096 Jan 25 04:17 ..
-rw-r----- 1 mysql mysql 56 Jan 25 04:21 auto.cnf
-rw------- 1 mysql mysql 1680 Jan 25 04:21 ca-key.pem
-rw-r--r-- 1 mysql mysql 1112 Jan 25 04:21 ca.pem
-rw-r--r-- 1 mysql mysql 1112 Jan 25 04:21 client-cert.pem
-rw------- 1 mysql mysql 1680 Jan 25 04:21 client-key.pem
-rw-r----- 1 mysql mysql 436 Jan 25 04:21 ib_buffer_pool
-rw-r----- 1 mysql mysql 209715200 Jan 25 04:21 ib_logfile0
-rw-r----- 1 mysql mysql 209715200 Jan 25 04:21 ib_logfile1
-rw-r----- 1 mysql mysql 209715200 Jan 25 04:21 ib_logfile2
-rw-r----- 1 mysql mysql 209715200 Jan 25 04:21 ib_logfile3
-rw-r----- 1 mysql mysql 104857600 Jan 25 04:21 ib_system
drwxr-x--- 2 mysql mysql 4096 Jan 25 04:21 mysql
drwxr-x--- 2 mysql mysql 4096 Jan 25 04:21 performance_schema
-rw------- 1 mysql mysql 1676 Jan 25 04:21 private_key.pem
-rw-r--r-- 1 mysql mysql 452 Jan 25 04:21 public_key.pem
-rw-r--r-- 1 mysql mysql 1112 Jan 25 04:21 server-cert.pem
-rw------- 1 mysql mysql 1680 Jan 25 04:21 server-key.pem
drwxr-x--- 2 mysql mysql 12288 Jan 25 04:21 sys
-rw-r----- 1 mysql mysql 10485760 Jan 25 04:21 undo001
### 2. MySQL DB ๊ธฐ๋
/usr/local/mysql/bin/mysqld_safe &
### ์์ ROOT ํจ์ค์๋ ํ์ธ
root@ip-10-0-7-218:/usr/local/mysql/bin# cd ../logs/
root@ip-10-0-7-218:/usr/local/mysql/logs# cat mysqld.err | grep generated
2021-01-25T04:21:28.256460Z 1 [Note] A temporary password is generated for root@localhost: /j0ercg;h9l
/j0ercg;h9lD
###
root@ip-10-0-7-218:/usr/local/mysql/bin# ./mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
root@localhost:(none)_04:23:09>
### ALTER USER 'root'@'localhost' IDENTIFIED BY 'ํจ์ค์๋';
root@localhost:(none)_04:23:13>ALTER USER 'root'@'localhost' IDENTIFIED BY 'dkagh1.';
Query OK, 0 rows affected (0.00 sec)
root@localhost:(none)_04:24:01>COMMIT;
Query OK, 0 rows affected (0.00 sec)
root@localhost:(none)_04:24:03>FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
root@localhost:(none)_04:24:07>exit
Bye
- DB ์ค์ง (์๋น์ค ๋ฑ๋ก์ ์ํด์)
root@ip-10-0-7-218:/usr/local/mysql/bin# ./mysqladmin -u root -p shutdown
Enter password:
2021-01-25T04:24:43.508787Z mysqld_safe mysqld from pid file /usr/local/mysql/tmp/mysqld.pid ended
[1]+ Done mysqld_safe
- Service ์์ฑ
vim /lib/systemd/system/mysqld.service
[Unit]
Description=Mysql Community Server
After=syslog.target
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
[Install]
WantedBy=multi-user.target
- ๋๋ชฌ reload ๋ฐ DB ์์
systemctl daemon-reload
systemctl enable mysqld.service
systemctl restart mysqld
root@ip-10-0-7-218:/usr/local/mysql/bin# systemctl status mysqld
โ mysqld.service - Mysql Community Server
Loaded: loaded (/lib/systemd/system/mysqld.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-01-25 04:25:36 UTC; 3s ago
Process: 11302 ExecStart=/usr/local/mysql/support-files/mysql.server start (code=exited, status=0/SUCCESS)
Main PID: 11322 (mysqld_safe)
Tasks: 28 (limit: 2348)
CGroup: /system.slice/mysqld.service
โโ11322 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/tmp/mysql
โโ11882 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local
Jan 25 04:25:35 ip-10-0-7-218 systemd[1]: Starting Mysql Community Server...
Jan 25 04:25:35 ip-10-0-7-218 mysql.server[11302]: Starting MySQL
Jan 25 04:25:36 ip-10-0-7-218 mysql.server[11302]: . *
Jan 25 04:25:36 ip-10-0-7-218 systemd[1]: Started Mysql Community Server.
- test
root@ip-10-0-7-218:/usr/local/mysql/bin# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31 Source distribution
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
root@localhost:(none)_04:26:14>status
--------------
mysql Ver 14.14 Distrib 5.7.31, for Linux (x86_64) using EditLine wrapper
Connection id: 2
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: less -n -i -F -X -E
Using outfile: ''
Using delimiter: ;
Server version: 5.7.31 Source distribution
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /tmp/mysql.sock
Uptime: 40 sec
Threads: 1 Questions: 6 Slow queries: 0 Opens: 108 Flush tables: 1 Open tables: 101 Queries per second avg: 0.150
--------------
- ์ฃผ์์ฌํญ : NLB DNS ์ฃผ์๊ฐ ๊ธธ๋ฉด workers.properties๊ฐ ์ธ์์ ํ์ง ๋ชปํ๋ค. NLB ์ฃผ์๋ ์งง๊ฒ ์ ์งํ๋ค.
- mod_jk ์ค์น
cd /usr/local/src
wget http://apache.tt.co.kr/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.48-src.tar.gz
tar zxvf tomcat-connectors-1.2.48-src.tar.gz
apt-get install apache2-dev
which apxs
/usr/bin/apxs
cd tomcat-connectors-1.2.48-src/native/
./configure --with-apxs=/usr/bin/apxs
make; make install
mv apache-2.0/mod_jk.so /usr/local/apache2.4/modules/
-
Apache ์ค์ ํ์ผ ์์
-
httpd.conf์ mod_jk.conf ์ถ๊ฐ
-
mod_jk.conf ํ์ผ ์ค์
-
workers.properties ํ์ผ ์ค์
-
uriworkermap.properties ํ์ผ ์ค์
## 1. httpd.conf ์์
root@ip-10-0-3-171:/usr/local/apache2.4/conf# tail httpd.conf
# Note: The following must must be present to support
# starting without SSL on platforms with no /dev/random equivalent
# but a statically compiled-in mod_ssl.
#
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
## ๋งจ ์๋์ ์๋ ๋ด์ฉ ์ถ๊ฐ!
Include conf/mod_jk.conf
## 2. mod_jk.conf ํ์ผ ์ถ๊ฐ
root@ip-10-0-3-171:/usr/local/apache2.4/conf# cat mod_jk.conf
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkShmFile logs/mod_jk.shm
JkLogFile logs/mod_jk.log
JkLogLevel info
JKMountFile conf/uriworkermap.properties
JKLogStampFormat "[%a %b %d %H:%M:%s %Y]"
JKRequestLogFormat "%w %V %T"
## 3. workers.properties ํ์ผ ์ถ๊ฐ
root@ip-10-0-3-171:/usr/local/apache2.4/conf# cat workers.properties
##### workers.properties ##
worker.list=worker1
worker.worker1.type=ajp13
worker.worker1.host=w-lb-c44f0579003043f8.elb.ap-northeast-2.amazonaws.com
worker.worker1.port=8009
## 4. uriworkermap.properties ํ์ผ ์ถ๊ฐ
root@ip-10-0-3-171:/usr/local/apache2.4/conf# cat uriworkermap.properties
/*=worker1
!/*.html=worker1
root@ip-10-0-3-171:/usr/local/apache2.4/conf# ls
extra httpd.conf magic mime.types mod_jk.conf original uriworkermap.properties workers.properties
- tomcat ์ค์ ํ์ผ (server.xml) ์์
- mod_jk protocol port ๊ฐ๋ฐฉ
vim server.xml
..
..
<Connector protocol="AJP/1.3"
address="0.0.0.0"
port="8009"
secretRequired="false"
URIEncoding="UTF-8"
redirectPort="8443" />
- Test
- Browser์์ external_alb ์ถ๋ ฅ
- Browser์์ external_alb/index.jsp ์ถ๋ ฅ
- mod_proxy๋ 8080 Port๋ฅผ ํตํด ์ฐ๋ํ๋ ๋ฐฉ๋ฒ์ด๋ค.
root@localhost:(none)_00:01:15>CREATE DATABASE test_db default character set utf8;
Query OK, 1 row affected (0.00 sec)
root@localhost:(none)_00:03:59>CREATE USER 'hello_user'@'%' IDENTIFIED BY 'passw0rd!';
Query OK, 0 rows affected (0.00 sec)
root@localhost:(none)_00:04:34>GRANT ALL PRIVILEGES ON test_db.* to 'hello_user'@'%' IDENTIFIED BY 'passw0rd!';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Warning (Code 1287): Using GRANT statement to modify existing user's properties other than privileges is deprecated and will be removed in future release. Use ALTER USER statement for this operation.
root@localhost:(none)_00:05:09>FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
root@localhost:(none)_00:05:42>exit
Bye
ubuntu@ip-10-0-7-113:~$ mysql -u hello_user -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.31-log Source distribution
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
hello_user@localhost:(none)_00:05:54>SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test_db |
+--------------------+
2 rows in set (0.00 sec)
hello_user@localhost:(none)_00:07:03>USE test_db;
Database changed
hello_user@localhost:test_db_00:07:15>SHOW TABLES;
Empty set (0.00 sec)
hello_user@localhost:test_db_00:07:23>CREATE TABLE test_table(name varchar(30));
Query OK, 0 rows affected (0.02 sec)
hello_user@localhost:test_db_00:07:44>insert into test_table values('test_value');
Query OK, 1 row affected (0.01 sec)
hello_user@localhost:test_db_00:08:16>select * from test_table;
+------------+
| name |
+------------+
| test_value |
+------------+
1 row in set (0.00 sec)
hello_user@localhost:test_db_00:08:22>commit;
Query OK, 0 rows affected (0.00 sec)
- JDBC Driver ์ค์น
cd /usr/local/src
wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.48.tar.gz
## tar ์์ถ ํด์
tar xzf mysql-connector-java-5.1.48.tar.gz
cd /usr/local/src/mysql-connector-java-5.1.48
cp mysql-connector-java-5.1.48-bin.jar $JAVA_HOME/lib
vim /etc/profile
..
..
## CLASSPATH ์ถ๊ฐ
CLASSPATH=$JAVA_HOME/lib/mysql-connector-java-5.1.48-bin.jar
export JAVA_HOME CATALINA_HOME PATH CLASSPATH
source /etc/profile
- test.jsp ์์ฑ
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>DB Connection Test</title>
</head>
<body>
<%
String DB_URL = "jdbc:mysql://10.0.7.113:3306/test_db";
String DB_USER = "hello_user";
String DB_PASSWORD = "passw0rd!";
Connection conn;
Statement stmt;
PreparedStatement ps;
ResultSet rs;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
stmt = conn.createStatement();
/* SQL ์ฒ๋ฆฌ ์ฝ๋ ์ถ๊ฐ ๋ถ๋ถ */
conn.close();
out.println("MySQL JDBC Driver Connection Test Success!!!");
/* ์์ธ ์ฒ๋ฆฌ */
} catch (Exception e) {
out.println(e.getMessage());
}
%>
</body>
</html>
- Master ์๋ฒ์ ์ฅ์ ๊ฐ ์๊ฒผ์ ๊ฒฝ์ฐ Slave ์๋ฒ๋ก ๋ณ๊ฒฝํ์ฌ ์ฌ์ฉํ ์ ์๋ค.
- Master : my.cnf์์ server-id๋ฅผ 1๋ก ์ค์
- Master : mysql ๋ฐ๋ชฌ์ ์ฌ์์ ํ Master ์๋ฒ ์ ๋ณด๋ฅผ ํ์ธํ๋ค.
- Slave : my.cnf์์ server-id๋ฅผ 2๋ก ์ค์ , ๋ณต์ ํ db๋ฅผ ์ค์ (๋ชจ๋ db๋ฅผ ๋ณต์ ํ ๊ฒฝ์ฐ ์ง์ ํด์ฃผ์ง ์์๋ ๋๋ค.)
- Slave : Master์ Endpoint, Port, user์ password, user_id, ip, log_position, log_file ๋ฑ์ ๊ธฐ์ ํด์ค๋ค.
- MySQL ๋ฐ๋ชฌ์ ์ฌ์์ ํ start slave; ๋ช ๋ น์ด๋ฅผ ๊ธฐ์ ํด์ค๋ค.
- ๋ณต์ ๊ฐ ๋๋์ง ํ์ธํ๋ค.
- mysql -u root -p๋ก ์ ์ ํ db ์์ฑ, ๊ณ์ ์์ฑ, ๊ถํ ๋ถ์ฌ, ..
## DB ์์ฑ
mysql> create database repl_db default character set utf8;
## ๊ณ์ ์์ฑ
mysql> create user user1@'%' identified by 'test123';
##๊ถํ๋ถ์ฌ
mysql> grant all privileges on repl_db.* to user1@'%' identified by 'test123';
## ๋ฆฌํ๋ฆฌ์ผ์ด์
๊ณ์ ์์ฑ
mysql> grant replication slave on *.* to 'repl_user'@'%' identified by 'test456'
## my.cnf ์ค์
vi /etc/my.cnf
[mysqld]
log-bin=mysql-bin
server-id=1
..
## mysqld ์ฌ์์
systemctl restart mysqld
## Master ์ ๋ณด ํ์ธ
root@localhost:(none)_07:36:13>show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 | 154 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
## File : MySQL ๋ก๊ทธํ์ผ
## Position : ๋ก๊ทธ ํ์ผ๋ด ์ฝ์ ์์น
## Binlog_Do_DB : ๋ฐ์ด๋๋ฆฌ(Binary)๋ก๊ทธ ํ์ผ(๋ณ๊ฒฝ๋ ์ด๋ฒคํธ ์ ๋ณด๊ฐ ์์ด๋ ํ์ผ)
## Binlog_Ignore_DB : ๋ณต์ ์ ์ธ ์ ๋ณด
- DB ์์ฑ
## mysql -u root -p๋ก ์ ์
## DB ์์ฑ
mysql> create database repl_db default character set utf8;
## ๊ณ์ ์์ฑ
mysql> create user user1@'%' identified by 'test123';
## ๊ถํ ๋ถ์ฌ
mysql> grant all privileges on repl_db.* to user1@'%' identified by 'test123';
## my.cnf ์ค์
# vi /etc/my.cnf
[mysqld]
server-id=2
replicate-do-db='repl_db'
## Master ์๋ฒ๋ก ์ฐ๊ฒฐํ๊ธฐ ์ํ ์ค์
## mysql -u root -p๋ก ์ ์
mysql> stop slave;
mysql> change master to
master_host='10.0.7.113',
master_user='repl_user',
master_password='test456',
master_log_file='mysql-bin.000003',
master_log_pos=154;
mysql> start slave;
# MASTER_HOST : Mster ์๋ฒ IP ์
๋ ฅ
# MASTER_USER : ๋ฆฌํ๋ฆฌ์ผ์ด์
ID
# MASTER_PASSWORD : ๋ฆฌํ๋ฆฌ์ผ์ด์
PW
# MASTER_LOG_FILE : MASTER STATUS ๋ก๊ทธํ์ผ๋ช
# MASTER_LOG_POS : MASTER STATUS์์ position ๊ฐ
# Slave_IO_State, Slave_IO_Running, Slave_SQL_Running์ด
# ์๋์ ๊ฐ์ด ๋ ์ผ ์ ์์ด๋ค.
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.7.113
Master_User: repl_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 154
Relay_Log_File: ip-10-0-8-237-relay-bin.000003
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: repl_db
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
..
..
..
## mysql ์ฌ์์
systemctl restart mysqld
-
Test
-
Master์์ repl_db๋ก ์ ์ํ์ฌ tables๋ฅผ ํ์ธ ํ student_db๋ฅผ ์์ฑํ๋ค.
ํ์ show tables; ๋ฅผ ํด๋ดค์ ๋ student_db๊ฐ ์์์ ํ์ธํ ์ ์๋ค.
root@localhost:(none)_07:36:20>use repl_db;
Database changed
root@localhost:repl_db_07:40:02>show tables;
Empty set (0.00 sec)
root@localhost:repl_db_07:40:04>CREATE TABLE `student_tb` (
-> `sno` int(11) NOT NULL,
-> `name` char(10) DEFAULT NULL,
-> `det` char(20) DEFAULT NULL,
-> `addr` char(80) DEFAULT NULL,
-> `tel` char(20) DEFAULT NULL,
-> PRIMARY KEY (`sno`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.03 sec)
root@localhost:repl_db_07:40:06>show tables;
+-------------------+
| Tables_in_repl_db |
+-------------------+
| student_tb |
+-------------------+
1 row in set (0.01 sec)
- Slave์์ repl_db;์ ์ ์ํ์ฌ ์ฒ์์ tables๋ฅผ ์กฐํํ์ ๋ ์๋ฌด๊ฒ๋ ์์ง๋ง Master์์ table์ ์์ฑํ ์ดํ ์ฑ๊ณต์ ์ผ๋ก ๋ณต์ ๊ฐ ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
root@localhost:(none)_07:39:23>use repl_db;
Database changed
root@localhost:repl_db_07:39:49>show tables;
Empty set (0.00 sec)
root@localhost:repl_db_07:39:50>show tables;
+-------------------+
| Tables_in_repl_db |
+-------------------+
| student_tb |
+-------------------+
1 row in set (0.00 sec)
-
Master์ Bin Log File ํน์ Position ๊ฐ์ด ๋ฐ๋๋ ๊ฒฝ์ฐ
SHOW MASTER STATUS; ๋ก ๋ฐ๋ ๊ฐ์ ํ์ธํ๋ค.
- SLAVE์ ์ ์ํ์ฌ ๋ฐ๋ ๊ฐ๋ค์ ์์ ํด์ค๋ค.
> stop slave;
> change master to
master_host='10.0.7.113',
master_user='repl_user',
master_password='test456',
master_log_file='mysql-bin.000008',
master_log_pos=154;
> start slave;
- Master์ Bin_log ํ์ผ or Position ๊ฐ์ด ์์ ๋ ๊ฒฝ์ฐ
mysql> stop slave;
mysql> change master to \
master_host='10.0.7.113', \
master_user='repl_user', \
master_password='test456', \
master_log_file='mysql-bin.000003', \
master_log_pos=154;
mysql> start slave;
- Slave_IO_State๊ฐ Waiting for master to send event๋ก ๋ฐ๋๊ฒ ๋๋ค.