유돌이

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

2019. 9. 18. 12:00 유닉스*리눅스*SE

1. CentOS MariaDB 10.1.9 설치
 1.1. vi /etc/yum.repos.d/MariaDB.repo 아래내용 입력후 저장
   => [mariadb]
      name = MariaDB
      baseurl = http://yum.mariadb.org/10.1/centos7-amd64
      gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
      gpgcheck=1
 1.2. yum install -y MariaDB MariaDB-server MariaDB-client
 1.3. mysql --version (mariaDB 버전확인)
 1.4. Mariadb 상태 변경 및 확인
   => systeomctl start mariadb  (시작)
   => systeomctl enable mariadb  (부팅시 자동실행 설정)
   => systeomctl status mariadb  (상태확인)
   => systeomctl stop mariadb    (정지)
   => systeomctl restart mariadb    (재시작)
 1.5. mysql_secure_installation  (root 비번설정)
=======================================================================
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set 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.

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.

Disallow root login remotely? [Y/n] y       // 원격접속
 ... Success!

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.

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!
=======================================================================

posted by 유돌이
2019. 9. 17. 10:38 유닉스*리눅스*SE

[pip 설치]
sudo yum install python-pip

posted by 유돌이
2019. 9. 17. 10:38 유닉스*리눅스*SE

# parser.py
import requests
import urllib3
urllib3.disable_warnings()
import subprocess

# HTTP GET Request
req = requests.get('웹페이지 url')

# HTML source
html = req.text
# HTTP Header
header = req.headers
# HTTP Status
status = req.status_code
# HTTP  (True/False)
is_ok = req.ok

print(status)
print(is_ok)

posted by 유돌이
2019. 9. 16. 09:44 유닉스*리눅스*SE

[운영체제 버전확인]
cat /etc/*release*

[리눅스 커널버전 확인]
cat /proc/version

[리눅스 시스템 비트확인 (x86, x86_64)]
arch

[cpu정보 확인]
cat /proc/cpuinfo

[메모리 정보]
cat /proc/meminfo

[파티션 정보 확인]
cat /proc/partitions

posted by 유돌이
2019. 9. 16. 09:44 유닉스*리눅스*SE

아래는 webroot plugin 방식을 통해 설정하는 방법입니다.

1. certbot 설치

apt-get에 certbot저장소를 추가해줍니다.
$ sudo add-apt-repository ppa:certbot/certbot
패키치 목록을 업데이트해주고 certbot을 설치합니다.
$ sudo apt-get update $ sudo apt-get install python-certbot-nginx
간혹 업데이트와 업그레이드가 되지 않는 경우가 있는데 그러면 직접 아래처럼 업그레이드를 해줍니다. 업데이트가 자주 바뀌며 지원되는게 달라지기 때문에 certbot 최신 버전을 설치하시길 추천드립니다.
$ sudo add-apt-repository ppa:certbot/certbot

2. 인증서 발급받기

Let’s Encrypt는 다양한 plugin들을 통해서 SSL 인증서를 제공합니다. 아파치를 제외한 대부분의 실치 플러그인들은 발급만 해주고 나머지 설정을 들을 직접 해주어야합니다.
본문에서는 webroot plugin을 통해서 인증서를 발급해 보겠습니다.

Webroot Plugin 사용하기

Webroot Plugin은 /.well-known이라는 폴더에 파일을 추가해서 Let’s Encrypt 서버가 접속할 수 있도록 합니다.
우선, /etc/nginx/sites-available/에 있는 conf 파일들 중에서 추가하고자 하는 파일을 열어줍니다. 여기서는 default conf 파일을 통해 설정해보도록 하겠습니다.
$ sudo vim /etc/nginx/sites-available/default


이제 해당 파일의 server 블럭 안에 다음을 추가합니다.
server { . . . location ~ /.well-known { allow all; } . . . }


nginx의 설정 파일이 문법이 제대로 되었는지 확인하고 재시작합니다.
$ sudo nginx -t $ sudo service nginx restart


이제 server block에서 root설정이 어디인지 알아보고 인증서를 발급해보겠습니다. 인증서를 발급하기 위해서는 webroot-path라는 부분에 server block의 root 경로를 지정해줘야 발급이 가능하다고 합니다.
다음 명령어를 통해서 설정파일에 들어갑니다. 이번에도 역시 /etc/nginx/sites-available/에 있는 default를 이용하겠습니다.
$ vim /etc/nginx/sites-available/default


문서의 server block을 보시면 아래처럼 나와있는 root에 설정된 경로를 기억해주시면됩니다. 다른 설정을 하지 않았다면 기본으로 /usr/share/nginx/html으로 나와있습니다.
server { . . . root /usr/share/nginx/html; # 이 경로를 기억해야합니다. . . . }


이제 인증서를 발급해봅시다. --webroot-path에 위에 있던 root로 설정된 폴더 경로를(여기서는 /usr/share/nginx/html), -d 옵션을 통해서 지정하고자 하는 도메인명을 넣어줍니다. 여러 도메인을 적용하고 싶다면 최상위 도메인부터 앞에서부터 적어주어야 합니다. 만약 본문처럼 example.com과 dev.example.com 둘다 하고 싶다면 아래처럼 적용하면 됩니다.
$ sudo certbot certonly --webroot --webroot-path=/usr/share/nginx/html -d example.com -d dev.example.com


처음 적용하는거라면 Email과 Terms of Service에 동의해야 합니다. 입력하고 동의를 하고 나면 다음처럼 성공적으로 완료되었다는 창이 나오며 인증서들과 키가 어떤 경로에 위치한다는 정보와 만기일이 나옵니다. 다음 아래 내용은 How To Secure Nginx with Let’s Encrypt on Ubuntu 14.04에 있는 결과를 가져왔습니다.
IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/example.com/fullchain.pem. Your cert will expire on 2017-07-26. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - If you lose your account credentials, you can recover through e-mails sent to sammy@example.com. - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - 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

Certificate 파일

webroot plugin을 통해 잘 발급을 받았다면 아래와 같은 4개의 파일들이 생성됩니다.
cert.pem: 도메인의 인증서
chain.pem: Let’s Encrypt chain 인증서
fullchain.pem: cert.pem + chain.pem
privkey.pem: 인증서의 개인키


위의 파일들은 /etc/letsencrypt/archive에 위치하며 /etc/letsencrypt/live/[your_domain_name]에서 가장 최근의 인증서들에 대해 symbolic link를 가지고 있습니다. 이 위치에서 가장 최신의 인증서를 가지고 있기 때문에 인증서와 키들을 참조할 때 /etc/letsencrypt/live/[your_domain_name] 폴더를 이용해야 합니다.
다음 아래의 명령어를 통해 해당 4개의 파일들이 존재하는지 확인할 수 있습니다.
$ sudo ls -l /etc/letsencrypt/live/your_domain_name

디프-헬만 그룹 추가하기

보안을 위해서 디프-헬만 그룹을 추가해야한다고 합니다. 아래의 명령어를 통해 실행해줍니다. 화면에 여러 점들이 찍히면서 진행이되며 시간이 다소 몇분 소요됩니다
$ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
다 생성이 되면 /etc/ssl/certs/에서 dhparam.pem 파일을 확인 할 수 있습니다.

3. TLS/SSL 설정하기

이제 Nginx의 server block들을 처리해서 TLS/SSL 설정을 하도록 하겠습니다. nginx에서 default 파일을 수정합시다.
$ sudo vim /etc/nginx/sites-available/default


server block에서 80포트에 대한 기본정보가 아래처럼 나와 있을텐데 지워줍니다.
server{ ... listen 80 default_server; listen [::]:80 default_server ipv6only=on; ... }


이제 SSL 관련 설정 세팅을 시작해봅시다. server block안에 다음 내용들을 추가합니다. 여기서 [domain]은 등록하신 도메인을 입력해야합니다!
server{ ... listen 443 ssl; server_name [domain] [another_domain]; ssl_certificate /etc/letsencrypt/live/[domain]/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/[domain]/privkey.pem; ... }


위의 작업이 끝났다면 아래의 내용도 그대로 server block에 추가합니다.
server{ ... ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_dhparam /etc/ssl/certs/dhparam.pem; ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA'; ssl_session_timeout 1d; ssl_session_cache shared:SSL:50m; ssl_stapling on; ssl_stapling_verify on; add_header Strict-Transport-Security max-age=15768000; ... }


마지막으로 아래에 다음과 같은 새로운 server block을 추가합니다.
해당 block은 해당 도메인에 대한 http의 요청을 https로 redirect 해주는 block입니다.
server { listen 80; server_name example.com www.example.com; return 301 https://$host$request_uri; }


자, 이제 설정이 다 끝났습니다. 다음처럼 문법을 확인하고 재시작해줍시다. 아래와 같은 스크린샷이 나오면 정상적으로 작동하는겁니다.
$ sudo nginx -t $ sudo service nginx restart or $ sudo /etc/init.d/nginx restart # sudo service nginx restart가 실행되지 않으면 위의 명령어로도 실행 가능합니다.

추가로! 다음 아래 사이트에서 마지막 d=에 설정하신 도메인을 넣어주시면 ssl 설정이 완료되었는지 등급이 어느정도인지 알 수 있습니다. 제대로 따라오셨다면 A+가 나와야합니다.
https://www.ssllabs.com/ssltest/analyze.html?d=[domain]

4. 갱신 자동화하기

Let’s Encrypt는 3개월간 유효하며 이를 자동적으로 갱신을 해야하는데 crontab을 통해서 그 일을 자동화시켜 보겠습니다.
다음 명령어를 통해서 crontab을 엽니다.
$ sudo crontab -e


텍스트 에디터로 열리면 아래의 명령어를 파일의 끝에 추가해줍니다.
. . . 15 3 * * * /usr/bin/certbot renew --quiet --renew-hook "/usr/sbin/service nginx reload"
간단히 설명을 하면
15 3 * * * : 매일 3:15 AM에 실행하겠다는 의미입니다.
/usr/bin/certbot : 실행하는 파일이며
renew : 자동으로 certbot이 인증서들을 보고 갱신이 필요하면 갱신을 진행해줍니다.
–quiet : 사용자에게 output을 전달하지 않고 실행합니다.(백그라운드)
–renew-hook “/usr/sbin/service nginx reload” : 파일이 새로 갱신되었다면 nginx를 reload해줍니다.


출처 : https://twpower.github.io/44(set-free-https-by-using-letsencrypt)

posted by 유돌이
2019. 9. 16. 09:43 유닉스*리눅스*SE

php --ini | grep php.ini


[php 위치 찾기]
which php

posted by 유돌이
2019. 9. 14. 23:21 유닉스*리눅스*SE

============
1 2 3 4 5 6
* * * * * 명령어
============

1. 분 설정 ( 0 ~ 59 )
2. 시 설정 ( 0 ~23 )
3. 일 ( 0 ~ 31 )
4. 월 ( 1 ~ 12 )
5. 요일 ( 0,7 : 일요일, 1 : 월, 2 : 화, 3 : 수, 4:목:, 5 : 금, 6 : 토 )
6. 명령어 : 실행할 명령을 한줄로 작성한다.

(예시)
[N분마다 수행]
*/N * * * * 명령어

[6시간마다 수행]
0 */6 * * * 명령어

posted by 유돌이
2019. 9. 14. 23:21 유닉스*리눅스*SE

[명령어]
ps -ef | grep 프로세스명 | awk '{print $2}' | xargs kill -9

[참고 : 특정 프로세스 죽이기]
 kill -9 PID

[참고 : 프로세스 확인하기]
명령어 : 'top' or 'ps -ax' 확인 가능

'유닉스*리눅스*SE' 카테고리의 다른 글

php.ini의 위치  (0) 2019.09.16
[crontab]크론탭 설정 방법  (0) 2019.09.14
[리눅스] 특정파일 삭제  (0) 2019.09.12
[centos7] yum 명령어 안될시~  (0) 2019.09.12
[우분투 16.04] SSD 마운트 하기  (0) 2019.09.11
posted by 유돌이
2019. 9. 12. 23:37 유닉스*리눅스*SE

find 대상폴더 -name 파일명 -exec rm -f {} \;

예시) 홈 디렉토리에 png파일 만 삭제
=> find /home -name *.png -exec rm -f {} \;

posted by 유돌이
2019. 9. 12. 23:37 유닉스*리눅스*SE

해결법

# vi /etc/sysconfig/network-scripts/ifcfg-en*

ONBOOT=no 를 yes로 바꿔주고 저장

# dhclient

# yum update

posted by 유돌이
prev 1 2 3 4 next