[Linux]Ubuntu에서 Nginx + jdk + MariaDB + MongoDB 설치

2024. 2. 20. 10:17리눅스(Linux)

 

 

Ubuntu에서 Nginx 1.24.0 + jdk 11.0.22 + MariaDB 10.11 + MongoDB 6.0 설치하기

 

 

 

1. Nginx 1.24.0 설치(최신버전)

  • OS 버전 확인
cat /etc/os-release

PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

 

  • 패키지 업데이트

    설치되어 있는(Installed) 패키지를 업데이트 하는 것이 아니라 설치 가능한(Available) 리스트를 업데이트 하는 것
apt-get update

 

  • 필수 패키지 설치
apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring

 

  • apt에서 패키지 신뢰성을 확인할 수 있도록 공식적인 nginx 서명 키를 가져오기
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1561  100  1561    0     0   1423      0  0:00:01  0:00:01 --:--:--  1424

 

  • 다운로드한 파일에 적절한 키가 포함되어 있는지 확인
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg

# 출력에는 다음과 같이 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62가 포함되어야한다.
pub   rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
      573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid                      nginx signing key <signing-key@nginx.com>

 

  • nginx 패키지 설치를 위해  stable 버전 apt 레포지토리 설정
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx"     | sudo tee /etc/apt/sources.list.d/nginx.list

 

  • nginx 설치
apt update

apt install nginx

nginx -V
nginx version: nginx/1.24.0
built by gcc 11.2.0 (Ubuntu 11.2.0-19ubuntu1) 
built with OpenSSL 3.0.2 15 Mar 2022
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -ffile-prefix-map=/data/builder/debuild/nginx-1.24.0/debian/debuild-base/nginx-1.24.0=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'

 

  • 서비스 시작/자동시작
systemctl start nginx
systemctl enable nginx

 

  • 사이트 접속 확인(http://IP주소:80)

 

 

 

* 참고 URL : https://nginx.org/en/linux_packages.html#Debian

 

nginx: Linux packages

nginx: Linux packages Supported distributions and versions nginx packages are available for the following Linux distributions and versions: RHEL and derivatives Version Supported Platforms 7.4+ x86_64, aarch64/arm64 8.x x86_64, aarch64/arm64, s390x 9.x x86

nginx.org

 

 

 

 


 

 

2. jdk 11.0.22 소스 설치

* 소스 파일 다운로드 : 

https://www.openlogic.com/openjdk-downloads?field_java_parent_version_target_id=406&field_operating_system_target_id=426&field_architecture_target_id=391&field_java_package_target_id=396

 

OpenJDK Downloads | Download Java JDK 8, 11 & 17 | OpenLogic

The JDK is the platform for building and deploying Java applications. It is comprised of the JRE (Java Runtime Environment), the JVM (Java Virtual Machine), core class libraries, compilers, debuggers, and documentation.

www.openlogic.com

 

  • 소스 다운로드 & 압축 해제
# 소스 파일은 보통 /usr/local/src에서 다운로드 받는다.
cd /usr/local/src

wget https://builds.openlogic.com/downloadJDK/openlogic-openjdk/11.0.22+7/openlogic-openjdk-11.0.22+7-linux-x64.tar.gz

tar -xvf openlogic-openjdk-11.0.22+7-linux-x64.tar.gz

mv openlogic-openjdk-11.0.22+7-linux-x64 /usr/local/jdk11

 

  • 환경변수 설정
    환경변수를 설정하면 어느 위치에서든 java/bin 디렉토리 안에 있는 exe 파일을 실행할 수 있다. 
    어느 위치에서든지 자바를 인식할 수 있도록 하는 것이 목적이다.

    PATH는 /usr/local/jdk/bin 아래에 있는 명령어를 아무데서나 쓸 수 있도록 해준다.
vim /etc/profile

JAVA_HOME=/usr/local/jdk11
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME PATH

# source 명령어로 /etc/profile 적용
# 구문오류가 있으면 오류를 발생시켜주고 오류가 없으면 아무 반응도 없는 것처럼 나온다.
# etc/profile 설정 파일은 재부팅 시 반영된다. 바로 반영하기 위해서 source /etc/profile 사용하는 것
source /etc/profile

# 환경 변수 잘 설정됐는지 확인
echo $JAVA_HOME

 

 

 

 


 

 

3. MariaDB 10.11 설치

  • 필수 패키지 설치
apt install curl software-properties-common dirmngr ca-certificates apt-transport-https -y

 

  • MariaDB 10.11 GPG 키 및 레포지토리 가져오기
curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version=10.11

apt update

 

  • MariaDB 설치
apt install mariadb-server mariadb-client -y

mariadb --version

 

  • MariaDB 서비스 시작/자동 시작
systemctl start mariadb
systemctl enable mariadb

 

  • mariadb 초기 세팅
mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

# 설정된 root 패스워드가 없기 때문에 엔터
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

# 유닉스 소켓이라는 인증 방식으로 전환할 것인지
Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

# root 패스워드를 변경할건지
Change the root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

# 익명 사용자를 제거할건지
# 'y'를 하면 'mysql -u root'로 로그인해야된다.
# 'n'을 하면 'mysql'로도 로그인된다. 그렇기 때문에 보안상 지워준다.
Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

# localhost IP가 아닌 곳에서 root로 로그인이 가능하게 할건지
# 'y'를 하면 원격 로그인이 안된다.
# 로컬에서만 사용할거면 'y' 권장
Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

# test 데이터베이스 삭제할건지
Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

# 지금까지 설정한 권한 정보 적용 여부
Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

 

  • MariaDB 외부 접근 허용
vim /etc/mysql/mairadb.conf.d/50-server.cnf

# bind-address = 127.0.0.1 주석하고 0.0.0.0 으로 수정
bind-address = 0.0.0.0

systemctl restart mariadb
systemctl status mariadb

 

  • 확인

bind-address = 127.0.0.1 일 때
bind-address = 0.0.0.0 일 때

 

 

 

 


 

 

4. MongoDB 6.0 설치

  • 필수 패키지 설치
apt update
apt install wget curl gnupg2 software-properties-common apt-transport-https ca-certificates lsb-release

 

  • MongoDB 공개 GPG 키 가져오기
curl -fsSL https://www.mongodb.org/static/pgp/server-6.0.asc|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/mongodb-6.gpg

 

  • MongoDB 용 목록 파일 만들기
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

 

  • MongoDB 설치
apt update

apt install mongodb-org

systemctl start mongod
systemctl enable mongod
systemctl status mongod

 

  • MongoDB 버전 확인
mongod --version

 

  • MongoDB 외부 접근 허용
vim /etc/mongod.conf

# bindIp: 127.0.0.1 에서 0.0.0.0 으로 수정
bindIp: 0.0.0.0

systemctl restart mongod

 

 

 

* 참고 URL : https://www.mongodb.com/docs/v6.0/tutorial/install-mongodb-on-ubuntu/

 

Install MongoDB Community Edition on Ubuntu — MongoDB Manual

Docs Home → MongoDB Manual MongoDB AtlasMongoDB Atlas is a hosted MongoDB service option in the cloud which requires no installation overhead and offers a free tier to get started.Use this tutorial to install MongoDB 6.0 Community Edition on LTS (long-te

www.mongodb.com