본문 바로가기
it

Centos7 최소설치 후 Nginx, php71, MariaDB, Openssl 1.0.2, firewall, http/2 YUM으로 셋팅하기

by 빅파워 2017. 8. 9.

Centos7 최소설치 후 Nginx, php71, MariaDB, Openssl 1.0.2, firewall, http/2 YUM으로 셋팅하기

 

1. 네트워크 설정이 안되어 있을 때

 

# yum -y install net-tools
# nmtui

 

 


 

 

 

2. nginx + openssl 1.0.2 yum 설치

nginx와 openssl 1.0.2를 동시에 설치하는 방법 $ yum -y install yum-utils $ vi /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1 $ yum -y install nginx $ systemctl start nginx $ systemctl enable nginx # nginx 버전 확인 $ nginx -v nginx version: nginx/1.12.1 built with OpenSSL 1.0.2k 26 Jan 2017

 

 

3. 무료 SSL인 Certbot 설치

 

참고문서:


https://brendaniel.github.io/2017/06/10/CentOS7-LEMP-Stack-%EC%A0%81%EC%9A%A9/

 

$ yum install epel-release $ yum -y install certbot # 인증 $ certbot certonly --standalone -d example.com -d www.example.com # 갱신 확인 $ certbot renew --dry-run # 갱신하면서 nginx 재부팅 # 이 명령어를 적절히 cron에 넣어주자. $ certbot renew --pre-hook="systemctl stop nginx" --post-hook="systemctl start nginx" $ cd /etc/letsencrypt/live/example.com/ $ openssl dhparam -out dhparams.pem 2048 or 4096


 

4. firewall 설치 및 설정

 

# firewall 설치 및 부팅 후 자동실행 yum install firewalld systemctl start firewalld systemctl enable firewalld # firewall 서비스 추가 (기본 zone은 public, 기본 zone은 생략가능) # --permanent 옵션이 있어야 저장함 firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https firewall-cmd --permanent --zone=public --add-service=ssh firewall-cmd --permanent --zone=public --add-service=ftp # firewall 서비스 삭제 firewall-cmd --permanent --zone=public --remove-service=http # firewall 재시작 firewall-cmd --reload # firewall 적용된 설정 확인 firewall-cmd --list-services --zone=public

 

5. mysql 설치 및 설정

 

# yum install -y mariadb mariadb-server # 설정파일을 복사한다. # cp /usr/share/mysql/my-medium.cnf /etc/my.cnf # UTF-8 설정 # vim /etc/my.cnf [client] port = 3306 socket = /var/lib/mysql/mysql.sock default-character-set=utf8 [mysqld] port = 3306 socket = /var/lib/mysql/mysql.sock skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M collation-server = utf8_unicode_ci init-connect='SET NAMES utf8' character-set-server = utf8 log-bin=mysql-bin binlog_format=mixed server-id = 1 innodb_data_home_dir = /var/lib/mysql innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = /var/lib/mysql innodb_buffer_pool_size = 4G innodb_log_file_size = 500M innodb_log_buffer_size = 8M #innodb_flush_log_at_trx_commit = 1 #innodb_lock_wait_timeout = 50 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash default-character-set=utf8 [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout

# 시작
# systemctl start mariadb
# systemctl enable mariadb

# 기본설정
# mysql_secure_installation

Enter current password for root (enter for none):  // 그냥 엔터
Change the root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y  // root를 살릴려면 n
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

# 재시작
# systemctl restart mariadb

# mariadb 확인
# mysql -u root -p  // 초기 생성한 암호 입력

 

 

6. php71 설치

 

$ yum install -y epel-release $ rpm -ivh http://rpms.remirepo.net/enterprise/remi-release-7.rpm $ yum --enablerepo=remi update remi-release $ yum --enablerepo=remi-php71 install php php-fpm php-mysql php를 설치하면 아파치 httpd가 설치됩니다. 주의합시다. $ systemctl stop httpd $ systemctl disable httpd 마지막으로 공통모듈들을 설치하도록 합시다. 물론 필요 없는 모듈은 설치 안하셔도 됩니다.

yum --enablerepo=remi,remi-php71 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml


 

 

7. nginx + php-fpm 연동

 

“vi /etc/nginx/conf.d/default.conf” 파일을 열고 아래를 참고로 적용합니다.

# HTTP
server {
    listen 80;
    server_name example.com www.example.com;

    # 80 접속시 443으로 redirect
    location / {
       return 301 https://$server_name$request_uri;
    }
}

# HTTPS
server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  server_name example.com www.example.com;
  root /var/nginx/www/public;
  index index.php index.html;

  # 지저분한 보안 옵션은 추천옵션이니 넣어주자.
  ssl on;
  ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
  ssl_trusted_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  ssl_session_timeout 1d;
  ssl_session_cache shared:SSL:50m;
  ssl_session_tickets off;

  #ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_protocols TLSv1.2;
  ssl_ciphers EECDH+AESGCM:EECDH+AES;
  ssl_ecdh_curve secp384r1;
  ssl_prefer_server_ciphers on;

  ssl_stapling on;
  ssl_stapling_verify on;

  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }

  location ~ \.php {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    fastcgi_index index.php;
    fastcgi_pass 127.0.0.1:9000;
  }

  location ~ /\.ht {
    deny all;
  }

  # 캐싱할 데이터가 있다면 추가
  location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|woff)$ {
    expires 1M;
    add_header Cache-Control "public";
  }

  location ~* \.(?:css|js)$ {
    expires 7d;
    add_header Cache-Control "public";
  }
}    

이제 nginx 웹서버를 재시작 하도록 합시다.
#systemctl restart nginx

 

 

8. php-fmp 설정 (memcached 설정)

 

다음으로 PHP 설정 파일 “/etc/php-fpm.d/www.conf”을 열어서 내용을 수정하도록 합시다.

 

user = apache 를 user = nginx 로 변경
group = apache 를 group = nginx 로 변경
listen.owner = nobody 를 listen.owner = nginx 로 변경
listen.group = nobody 를 listen.owner = nginx 로 변경
listen = 127.0.0.1:9000을 주석처리 하고, listen = /var/run/php-fpm/php-fpm.sock 으로 추가.

# memcached 설정

php_value[session.save_handler] = memcached
php_value[session.save_path]    = 127.0.0.1:11211

 

이제 php-fpm, memcached 서비스를 재시작하고 부팅시 자동으로 시작하도록 등록해줍시다.

 

* php 수정사항은 /etc/php.ini을 수정해도 적용이 안됨. nginx는 /etc/php-fpm.d/www.conf에서 수정할 것.

 

 

/etc/php-fpm.d/www.conf 수정했다면 서비스 재시작

# systemctl start php-fpm.service
# systemctl enable php-fpm.service


# yum install memcached
# systemctl start memcached
# systemctl enable memcached


netstat -nap (열려 있는 모든 포트)
#netstat -l 또는 netstat -nap | grep LISTEN (LISTEN 되는 모든 포트)
#netstat -nap | grep ESTABLISHED | wc -l ( 모든 서비스 동시 접속자 수)
#netstat -nap | grep :80 | grep ESTABLISHED | wc -l ( 웹 동시 접속자 수)


9. vsftp 설치


# yum install vsftp

# vi /etc/vsftpd/vsftpd.conf


local_enable=YES

write_enable=YES
local_umask=022
dirmessage_enable=YES

xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES


댓글