웹사이트 검색

Nginx로 Askbot을 설치하고 CentOS 8에서 Lets Encrypt로 보안하는 방법


이 페이지에서

  1. 전제 조건
  2. 필수 종속성 설치\n
  3. PostgreSQL 설치 및 구성
  4. Askbot 설치 및 구성
  5. uWSGI 설치 및 구성
  6. uWSGI용 시스템 서비스 파일 생성
  7. Nginx 설치 및 구성
  8. Lets Encrypt SSL로 Askbot 보안 유지
  9. 방화벽 및 SELinux 구성\n
  10. Askbot 액세스
  11. 결론

Askbot은 Python 및 Django로 작성된 무료 오픈 소스의 고도로 사용자 정의 가능한 질문 및 답변 포럼 소프트웨어입니다. 간단하고 가벼우며 다른 포럼 소프트웨어 StackOverflow 및 YahooAnswers와 매우 유사합니다. Askbot은 태그 및 카테고리, 이메일 알림, 카르마 기반 시스템, 투표, 콘텐츠 조정 등을 포함한 수많은 기능을 제공합니다.

이 튜토리얼에서는 Lets Encrypt SSL을 사용하여 CentOS 8에 Askbot 포럼 소프트웨어를 설치하는 방법을 보여줍니다.

전제 조건

  • CentOS 8을 실행하는 서버.\n
  • 서버에 루트 비밀번호가 설정되어 있습니다.\n

필수 종속성 설치

시작하기 전에 시스템에 몇 가지 필수 종속 항목을 설치해야 합니다.

먼저 다음 명령을 사용하여 "개발 도구\를 설치합니다.

dnf group install 'Development Tools'

다음으로 다음 명령을 사용하여 EPEL 리포지토리 및 기타 Python 종속 항목을 설치합니다.

dnf install epel-release -y
dnf install python2-pip python2-devel python2-six -y

필요한 모든 패키지가 설치되면 다음 단계로 진행할 수 있습니다.

PostgreSQL 설치 및 구성

Askbot은 PostgreSQL을 사용하여 데이터를 저장합니다. 따라서 시스템에 설치해야 합니다. 다음 명령으로 설치할 수 있습니다.

dnf install postgresql-server postgresql-devel postgresql-contrib -y

설치가 완료되면 다음 명령을 사용하여 데이터베이스를 초기화합니다.

postgresql-setup initdb

다음 출력이 표시되어야 합니다.

WARNING: using obsoleted argument syntax, try --help
WARNING: arguments transformed to: postgresql-setup --initdb --unit postgresql
 * Initializing database in '/var/lib/pgsql/data'
 * Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log

그런 다음 PostgreSQL 서비스를 시작하고 다음 명령을 사용하여 시스템 재부팅 후 시작되도록 활성화합니다.

systemctl start postgresql
systemctl enable postgresql

그런 다음 다음 명령을 사용하여 PostgreSQL 셸에 로그인합니다.

su - postgres
[ ~]$ psql

산출:

psql (10.6)
Type "help" for help.
postgres=# 

다음으로 다음 명령을 사용하여 Askbot에 대한 데이터베이스와 사용자를 생성합니다.

postgres=# create database askbot;
postgres=# create user askbot with password 'password';

그런 다음 다음 명령을 사용하여 askbot에 모든 권한을 부여합니다.

postgres=# grant all privileges on database askbot to askbot;

마지막으로 다음 명령을 사용하여 PostgreSQL 셸을 종료합니다.

postgres=# \q

다음으로 PostgreSQL에 대한 로컬 사용자 인증을 구성해야 합니다. pg_hba.conf 파일을 편집하면 됩니다.

nano /var/lib/pgsql/data/pg_hba.conf

다음 줄에서 피어를 md5로 바꿉니다.

local   all             all                                    md5  
host    all             all             127.0.0.1/32           md5  
host    all             all             ::1/128                md5  

완료되면 파일을 저장하고 닫습니다. 그런 다음 PostgreSQL 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart postgresql

Askbot 설치 및 구성

Askbot을 설치하기 전에 Askbot에 대한 사용자를 생성해야 합니다. 다음 명령을 사용하여 새 Askbot 사용자를 생성하고 비밀번호를 설정할 수 있습니다.

useradd -m -s /bin/bash askbot
passwd askbot

다음으로 sudo 명령 액세스를 위해 휠 그룹에 Askbot 사용자를 추가합니다.

usermod -a -G wheel askbot

다음으로 다음 명령을 사용하여 python virtualenv 패키지를 설치합니다.

pip2 install virtualenv six

설치가 완료되면 사용자를 askbot으로 변경하고 다음 명령을 사용하여 Askbot에 대한 새 가상 환경을 만듭니다.

su - askbot
virtualenv askbot

다음 출력이 표시되어야 합니다.

created virtual environment CPython2.7.16.final.0-64 in 663ms
  creator CPython2Posix(dest=/home/askbot/askbot, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/tmp/tmp9YFr7B/seed-app-data/v1)
  activators PythonActivator,CShellActivator,FishActivator,PowerShellActivator,BashActivator

그런 다음 디렉터리를 askbot으로 변경하고 다음 명령을 사용하여 가상 환경을 활성화합니다.

cd askbot
source bin/activate

산출:

(askbot) [ askbot]$

다음으로 다음 명령을 사용하여 Askbot 및 기타 필수 종속 항목을 설치합니다.

pip2 install six==1.10.0
pip2 install askbot psycopg2

다음으로 애플리케이션을 위한 새 디렉토리를 생성하고 디렉토리를 애플리케이션으로 변경한 후 다음 명령을 사용하여 Askbot을 설정합니다.

mkdir myapp
cd myapp
askbot-setup

다음 출력이 표시되어야 합니다.

Deploying Askbot - Django Q&A forum application
Problems installing? -> please email 

To CANCEL - hit Ctr-C at any time

Enter directory path (absolute or relative) to deploy
askbot. To choose current directory - enter "."
> .

"."를 입력하고 Enter 키를 눌러 계속하십시오. 다음 출력이 표시되어야 합니다.

Please select database engine:
1 - for postgresql, 2 - for sqlite, 3 - for mysql, 4 - oracle
type 1/2/3/4: 1

1을 입력하여 postgresql 데이터베이스 엔진을 선택하고 Enter 키를 눌러 계속합니다. 다음 출력이 표시되어야 합니다.

Please enter database name (required)
> askbot

Please enter database user (required)
> askbot

Please enter database password (required)
> password

Askbot 데이터베이스 세부 정보를 제공하고 Enter 키를 누릅니다. 설치가 완료되면 다음 출력이 표시됩니다.

Copying files: 
* __init__.py 
* manage.py 
* urls.py 
* django.wsgi 
Creating settings file
settings file created

copying directories:  * doc
* cron
* upfiles

Done. Please find further instructions at http://askbot.org/doc/

다음으로 다음 명령을 사용하여 Askbot Django 정적 파일 및 데이터베이스를 생성합니다.

python manage.py collectstatic
python manage.py syncdb

아래와 같이 원하는 관리자 사용자 이름, 이메일 및 비밀번호를 제공하십시오.

You have installed Django's auth system, and don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'askbot'): askbotadmin
Email address: 
Password: 
Password (again): 
Superuser created successfully.

uWSGI 설치 및 구성

다음으로 시스템에 uWSGI를 설치해야 합니다. uWSGI는 Python 기반 웹 애플리케이션을 실행하는 데 사용되는 소프트웨어 도구입니다. 다음 명령으로 설치할 수 있습니다.

pip2 install uwsgi

uWSGI를 설치한 후 다음 명령을 사용하여 uWSGI용 새 디렉토리를 생성합니다.

mkdir -p /etc/uwsgi/sites

다음으로 아래와 같이 새 uWSGI 구성 파일을 만듭니다.

nano /etc/uwsgi/sites/askbot.ini

다음 줄을 추가합니다.

[uwsgi]

chdir = /home/askbot/askbot/myapp
home = /home/askbot/askbot
static-map = /m=/home/askbot/askbot/myapp/static
wsgi-file = /home/askbot/askbot/myapp/django.wsgi
master = true
processes = 5
# Askbot will running under the sock file
socket = /run/uwsgi/askbot.sock
chmod-socket = 664
uid = askbot
gid = nginx
vacuum = true
# uWSGI Log file
ogto = /var/log/uwsgi.log

uWSGI용 Systemd 서비스 파일 생성

다음으로 uWSGI 서비스를 관리하기 위해 systemd 서비스 파일을 생성해야 합니다. 다음 명령으로 만들 수 있습니다.

nano /etc/systemd/system/uwsgi.service

다음 줄을 추가합니다.

[Unit]
Description=uWSGI service

[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown askbot:nginx /run/uwsgi'
ExecStart=/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target

완료되면 파일을 저장하고 닫습니다. 그런 다음 다음 명령을 사용하여 systemd 데몬을 다시 로드합니다.

systemctl daemon-reload

Nginx 설치 및 구성

다음으로 Askbot 애플리케이션을 제공하기 위해 Nginx를 설치 및 구성해야 합니다.

먼저 다음 명령을 사용하여 Nginx 웹 서버를 설치합니다.

dnf install nginx -y

설치가 완료되면 Askbot에 대한 새 가상 호스트 구성 파일을 만듭니다.

nano /etc/nginx/conf.d/askbot.conf

다음 줄을 추가합니다.

server {
         listen 80;
         server_name askbot.linuxbuz.com;
         location / {
         include         uwsgi_params;
         uwsgi_pass	 unix:/run/uwsgi/askbot.sock;
    }
 }

파일을 저장하고 닫습니다. 그런 다음 Nginx 및 uWSGI 서비스를 시작하고 다음 명령을 사용하여 시스템 재부팅 후 시작할 수 있도록 활성화합니다.

systemctl start nginx
systemctl enable nginx
systemctl start uwsgi
systemctl enable uwsgi

Lets Encrypt SSL로 Askbot 보호

다음으로 Lets Encrypt SSL for Askbot 도메인을 다운로드하고 설치하려면 시스템에 Certbot 유틸리티를 설치해야 합니다.

다음 명령을 사용하여 Certbot 클라이언트를 설치할 수 있습니다.

wget https://dl.eff.org/certbot-auto
mv certbot-auto /usr/local/bin/certbot-auto
chown root /usr/local/bin/certbot-auto
chmod 0755 /usr/local/bin/certbot-auto

다음으로 다음 명령을 사용하여 Askbot 도메인에 대한 SSL 인증서를 가져와 설치합니다.

certbot-auto --nginx -d askbot.linuxbuz.com

위의 명령은 먼저 서버에 필요한 모든 종속성을 설치합니다. 설치가 완료되면 아래와 같이 이메일 주소를 제공하고 서비스 약관에 동의하라는 메시지가 표시됩니다.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for askbot.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/askbot.conf

다음으로 아래와 같이 HTTP 트래픽을 HTTPS로 리디렉션할지 여부를 선택합니다.

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

2를 입력하고 Enter를 눌러 계속하십시오. 설치가 완료되면 다음 출력이 표시됩니다.

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/askbot.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://askbot.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=askbot.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/askbot.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/askbot.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-06-11. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again with the "certonly" option. To non-interactively renew *all*
   of your certificates, run "certbot-auto renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

방화벽 및 SELinux 구성

다음으로 외부 네트워크에서 HTTP 및 HTTPS 서비스를 허용하는 방화벽 규칙을 생성해야 합니다. 다음 명령으로 허용할 수 있습니다.

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

기본적으로 SELinux는 CentOS 8에서 활성화되어 있습니다. Askbot이 제대로 작동하려면 비활성화하는 것이 좋습니다. /etc/selinux/config 파일을 편집하여 비활성화할 수 있습니다.

nano /etc/selinux/config

다음 줄을 찾으십시오.

SELINUX=enforcing

그리고 다음 줄로 바꿉니다.

SELINUX=disabled

파일을 저장하고 닫습니다. 그런 다음 시스템을 다시 시작하여 변경 사항을 적용하십시오.

Askbot에 액세스

이제 웹 브라우저를 열고 URL https://askbot.linuxbuz.com을 입력하십시오. 다음 화면으로 리디렉션됩니다.

로그인 버튼을 클릭합니다. 다음 화면에 Askbot 로그인 페이지가 표시되어야 합니다.

Askbot 관리자 사용자 이름과 비밀번호를 제공하고 로그인 버튼을 클릭합니다. 다음 화면에 Askbot 대시보드가 표시되어야 합니다.

결론

축하합니다! CentOS 8에 Askbot 포럼을 성공적으로 설치 및 구성하고 Lets Encrypt SSL로 보호했습니다. 이제 Askbot으로 질문 및 답변 만들기를 시작할 수 있습니다.