๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์„œ๋ฒ„/AWS

[EC2] MySQL & Tomcat ์„ค์น˜ - Ubuntu

by yunamom 2022. 11. 26.
๋ฐ˜์‘ํ˜•

 

1. MySQL ์„ค์น˜ํ•˜๊ธฐ

2. stand-alone tomcat ์„ค์น˜&์‹คํ–‰

 


- EC2 Ubuntu ์„œ๋ฒ„์— MySQL ์„ค์น˜

 

1. MySQL ์„ค์น˜

ubuntu:~$ sudo apt update #ํŒจํ‚ค์ง€ ์ •๋ณด ์—…๋ฐ์ดํŠธ

ubuntu:~$ sudo apt install mysql-server #mysql ์„œ๋ฒ„ ์„ค์น˜ ๋ช…๋ น

ubuntu:~$ dpkg -l | grep mysql-server #์„ค์น˜ํ™•์ธ ๋ช…๋ น

ii  mysql-server                    8.0.31-0ubuntu0.22.04.1                 all          MySQL database server (metapackage depending on the latest version)
ii  mysql-server-8.0                8.0.31-0ubuntu0.22.04.1                 amd64        MySQL database server binaries and system database setup
ii  mysql-server-core-8.0           8.0.31-0ubuntu0.22.04.1                 amd64        MySQL database server binaries

2. ์‹คํ–‰

ubuntu:~$ service mysql status #mysql ์„œ๋ฒ„ ์ƒํƒœํ™•์ธ

โ— mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: ena>
     Active: active (running) since Fri 2022-11-25 21:57:18 KST; 4min 55s ago
    Process: 15465 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exit>
   Main PID: 15473 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 1143)
     Memory: 358.4M
        CPU: 2.058s
     CGroup: /system.slice/mysql.service
             โ””โ”€15473 /usr/sbin/mysqld

Nov 25 21:57:17 ip-172-31-12-203 systemd[1]: Starting MySQL Community Server...
Nov 25 21:57:18 ip-172-31-12-203 systemd[1]: Started MySQL Community Server.
ubuntu:~$ sudo service mysql start #์‹œ์ž‘

ubuntu:~$ sudo service mysql stop #์ข…๋ฃŒ

ubuntu:~$ sudo service mysql restart #์žฌ์‹œ์ž‘

3. root ๊ณ„์ • ํ™œ์„ฑํ™” & ๋น„๋ฐ€๋ฒˆํ˜ธ ์‹ ๊ทœ ๋“ฑ๋ก

ubuntu:~$ sudo mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.31-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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.

mysql> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye
ubuntu:~$ mysqladmin -u root password
New password: 
Confirm new password: 
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
ubuntu:~$ sudo service mysql restart

ubuntu:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.31-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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.

mysql>

 

- EC2 Ubuntu ์„œ๋ฒ„์— stand-alone tomcat ์„ค์น˜

 

Apache Tomcat์€ ์˜คํ”ˆ์†Œ์Šค ์ž๋ฐ” ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋ฒ„์ด๋‹ค.

tomcat์€ Java ์–ธ์–ด๋กœ ๊ฐœ๋ฐœ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์—, JVM(Java Virtual Machine) ์—์„œ ์‹คํ–‰๋œ๋‹ค.

 

๋จผ์ € AWS ๋ณด์•ˆ ์ธ๋ฐ”์ธ๋“œ๊ทœ์น™์—์„œ 8080ํฌํŠธ๋ฅผ ์—ด์–ด์ฃผ์ž

1. tomcat9 ์„œ๋ฒ„ ์„ค์น˜

ubuntu:~@ sudo apt install tomcat9

์„ค์น˜๋œ tomcat ์„œ๋ฒ„๋Š” ๋ฐฑ๊ทธ๋ผ์šด๋“œ ์„œ๋น„์Šค๋กœ ์‹คํ–‰๋œ๋‹ค.

background service : ํ™”๋ฉด์„ ์ฐจ์ง€ํ•˜์ง€ ์•Š๊ณ , ๋’ค์—์„œ ์‹คํ–‰๋˜๋Š” ํ”„๋กœ์„ธ์Šค

foreground process : ํ™”๋ฉด์„ ์ฐจ์ง€ํ•˜๊ณ  ์‹คํ–‰๋˜๋Š” ํ”„๋กœ์„ธ์Šค

 

2. tomcat9 ์‹คํ–‰ ์ƒํƒœ ํ™•์ธ

ubuntu:~@ service tomcat9 status
โ— tomcat9.service - Apache Tomcat 9 Web Application Server
     Loaded: loaded (/lib/systemd/system/tomcat9.service; enabled; vendor preset: e>
     Active: active (running) since Fri 2022-11-25 22:53:35 KST; 2min 51s ago
       Docs: https://tomcat.apache.org/tomcat-9.0-doc/index.html
    Process: 17664 ExecStartPre=/usr/libexec/tomcat9/tomcat-update-policy.sh (code=>
   Main PID: 17668 (java)
      Tasks: 28 (limit: 1143)
     Memory: 83.9M
        CPU: 4.705s
     CGroup: /system.slice/tomcat9.service
             โ””โ”€17668 /usr/lib/jvm/default-java/bin/java -Djava.util.logging.config.>

Nov 25 22:53:37 ip-172-31-12-203 tomcat9[17668]: OpenSSL successfully initialized [>
Nov 25 22:53:39 ip-172-31-12-203 tomcat9[17668]: Initializing ProtocolHandler ["htt>
Nov 25 22:53:39 ip-172-31-12-203 tomcat9[17668]: Server initialization in [3044] mi>
Nov 25 22:53:39 ip-172-31-12-203 tomcat9[17668]: Starting service [Catalina]
Nov 25 22:53:39 ip-172-31-12-203 tomcat9[17668]: Starting Servlet engine: [Apache T>
Nov 25 22:53:39 ip-172-31-12-203 tomcat9[17668]: Deploying web application director>
Nov 25 22:53:41 ip-172-31-12-203 tomcat9[17668]: At least one JAR was scanned for T>
Nov 25 22:53:41 ip-172-31-12-203 tomcat9[17668]: Deployment of web application dire>
Nov 25 22:53:41 ip-172-31-12-203 tomcat9[17668]: Starting ProtocolHandler ["http-ni>
Nov 25 22:53:41 ip-172-31-12-203 tomcat9[17668]: Server startup in [2422] milliseco>

  http://์„œ๋ฒ„IP์ฃผ์†Œ:8080 ์ ‘์†ํ›„ ์•„๋ž˜์™€ ๊ฐ™์€ ํ™”๋ฉด์ด ๋‚˜์˜ค๋ฉด ์™„๋ฃŒ

3. tomcat9 ์„œ๋ฒ„์— war ํŒŒ์ผ ์„ค์น˜

$ scp -i ํ‚คํŒŒ์ผ.pem ์—…๋กœ๋“œํŒŒ์ผ.war ubuntu@IP์ฃผ์†Œ:~
#๋กœ์ปฌPC ํŒŒ์ผ์„ ubuntu ์„œ๋ฒ„๋กœ ์—…๋กœ๋“œ ํ•˜๊ธฐ

EC2 ์„œ๋ฒ„์— ssh ์—ฐ๊ฒฐํ›„ ์—…๋กœ๋“œ๋œ .war ํŒŒ์ผ์„ /var/lib/tomcat9/webapps ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™

ubuntu:~$ sudo mv ์—…๋กœ๋“œํŒŒ์ผ.war /var/lib/tomcat9/webapps

.war ํŒŒ์ผ์€ ZIP ์••์ถ•ํŒŒ์ผ๋กœ ์•„๋ž˜ ํ™”๋ฉด์ฒ˜๋Ÿผ ์••์ถ•์ด ํ’€๋ฆฌ๋ฉด ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค. (logo.war -> logo)

ubuntu:~$ ls -l /var/lib/tomcat9/webapps
total 5312
drwxr-xr-x 3 root   root      4096 Nov 25 22:53 ROOT
drwxr-x--- 6 tomcat tomcat    4096 Nov 25 23:13 logo
-rw-r--r-- 1 ubuntu ubuntu 5429482 Nov 25 23:05 logo.war

 http://์„œ๋ฒ„IP์ฃผ์†Œ:8080/๋””๋ ‰ํ† ๋ฆฌ์ด๋ฆ„

์‹คํ–‰์™„๋ฃŒ ๐Ÿ‘

 

300x250

์ฝ”๋“œ