Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maketheworldwise/7922b6b875718182510d2a78e01c3a49 to your computer and use it in GitHub Desktop.
Save maketheworldwise/7922b6b875718182510d2a78e01c3a49 to your computer and use it in GitHub Desktop.
EC2 - Java 11, Jenkins, Nginx, MariaDB, MySQL 설치 명령어
EC2에 Java 11, Jenkins, Nginx, MariaDB, MySQL 설치시 필요한 명령어
$ sudo yum update
# Jenkins 설정에 경로 추가 필요
$ sudo yum install java-11-amazon-corretto.x86_64
$ java -version
$ javac -version
# 다른 버전과 함께 있을 경우 버전 선택 명령어
$ update-alternatives --config java
# 환경 변수 등록
$ which java
$ readlink -f /usr/bin/java
$ sudo vi /etc/profile
$ source /etc/profile
---
export JAVA_HOME=/usr/lib/jvm/java-11-amazon-corretto.x86_64/bin/java
$ sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
$ sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
$ sudo yum upgrade
$ sudo yum install jenkins
---
# JENKINS_PORT 설정
$ vi /etc/sysconfig/jenkins
---
# Jenkinx 히스토리 로그 삭제 (Jenkins 관리 > Script Console 이동 후 하단의 스크립트 실행)
# 모든 아이템의 빌드 히스토리 제거
item = Jenkins.instance.getAllItems().each() { item ->
item.builds.each() { build ->
build.delete()
}
item.updateNextBuildNumber(1)
}
# 특정 아이템의 빌드 히스토리 제거
item = Jenkins.instance.getItemByFullName("jobname")
item.builds.each() { build ->
build.delete()
}
item.updateNextBuildNumber(1)
---
# 참고 사이트
# - https://www.jenkins.io/doc/book/installing/linux/#red-hat-centos
# - https://pkg.jenkins.io/redhat-stable/
# - https://minholee93.tistory.com/entry/Jenkins-Gradle-Build (Post build task 플러그인)
$ sudo amazon-linux-extras install nginx1
---
# Reverse Proxy 설정
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# 해당 경로에 로그 생성
access_log /var/log/nginx/proxy/access.log
error_log /var/log/nginx/proxy/error.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
}
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
---
# location 설정 옵션
# - 'location = /' : 정확하게 일치
# - 'location /' : 지정한 패턴으로 시작
# - 'location /images/' : 지정한 패턴으로 시작
# - 'location ^~ /images/' : 지정한 패턴으로 시작 패턴이 일치하면 다른 패턴 탐색 중지
# - 'location ~ \.(gif|jpg|jpeg)$' : 정규식 표현 일치 (대소문자 구분)
# - 'location ~* \.(gif|jpg|jpeg)$' : 정규식 표현 일치 (대소문자 구분 안함)
$ sudo yum install -y mariadb-server
$ sudo systemctl start mariadb
---
# User 추가
$ USE mysql;
$ SELECT host, user, password FROM user;
$ CREATE USER 'root'@'192.168.94' IDENTIFIED BY 'password';
$ GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.94' IDENTIFIED BY 'password';
$ FLUSH PRIVILEGES;
$ sudo yum install https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
$ ls /etc/yum.repos.d
$ sudo amazon-linux-extras install epel -y
$ sudo yum -y install mysql-community-server
$ sudo systemctl enable mysqld
$ sudo systemctl start mysqld
$ sudo grep 'temporary password' /var/log/mysqld.log
$ sudo mysql_secure_installation -p
---
# MariaDB 삭제
$ sudo yum remove mariadb*
# MySQL 구동 실패 원인을 찾기 위한 로그 확인
# - 지원하지 않는 로그 포맷 문제 확인 (redo log format)
# - 이전에 MariaDB를 설치한 적이 있었을 경우, MariaDB에서 생성한 데이터 파일과 로그 파일이 남아있어 문제가 발생
$ sudo cat /etc/my.cnf | grep log-err
# 데이터 파일 저장 경로 확인
$ sudo cat /etc/my.cnf | grep datadir
# 이전에 설치한 데이터베이스에서 생성한 데이터 파일과 로그 파일 삭제 (해당 디렉토리는 구동시에 자동으로 생성되니 디렉토리 자체를 삭제해도 무관)
$ sudo rm -rf /var/lib/mysql
---
# MySQL에 접속 후 User를 추가하기 전에 비밀번호를 변경해주고 추가해줘야함
# 만약 비밀번호 정책에 민감할 필요가 없다면 LOW로 설정해주면 됨
$ SHOW VARIABLES LIKE 'validate_password%';
$ SET GLOBAL validate_password_policy=LOW;
$ ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
$ FLUSH PRIVILEGES;
---
# 참고
# - https://techviewleo.com/how-to-install-mysql-8-on-amazon-linux-2/
# - https://sparkdia.tistory.com/10
@maketheworldwise
Copy link
Author

maketheworldwise commented May 11, 2022

MySQL access_log, error_log 설정 시 해당 경로가 존재하야하며 권한 부여도 필요

@maketheworldwise
Copy link
Author

위와 같은 구성으로 진행했을 때 - Spring Boot를 80번 포트로 구동시키면 동작하지 않는 문제 발생

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment