Dec 29, 2016

토렌트 다운로드 완료 후 토렌트 리스트 자동삭제


토렌트 다운로드 후 토렌트 리스트에서 제거하는 방법


*아래 파일을 아무리 수정해도 데몬을 재시작하면 파일이 수정 전으로 돌아간다. 이 문제때문에 한시간을 소비해서 찾은 답은.. 간단했다.
파일 수정하기 전에 데몬은 stop하고 수정하면 된다.
jkpark@cactus:/storages/storage1/public/torrent$ sudo service transmission-daemon stop
꼭 데몬은 stop한 후 아래 작업을 수행한다.


/etc/transmission-daemon/settings.json 파일을 열어 다음과 같이 수정한다.

    "script-torrent-done-enabled": true,
    "script-torrent-done-filename": "/storages/storage1/public/torrent/auto_delete.sh",



/storages/storage1/public/torrent/auto_delete.sh 파일을 만들고 아래 내용을 입력한다.

#!/bin/sh
# Transmission script to remove torrent from lists

# The file for logging events from this script
LOGFILE=/storages/storage1/public/torrent/auto_delete_log

# Remote login details.
TR_HOST="9091 --auth=아이디:비밀번호"

echo "`date '+%Y-%m-%d %H:%M:%S'`  removed from list : $TR_TORRENT_NAME" >> $LOGFILE
transmission-remote $TR_HOST -t $TR_TORRENT_ID --remove


저장 후 권한설정
jkpark@cactus:/storages/storage1/public/torrent$ chmod 777 auto_delete.sh
jkpark@cactus:/storages/storage1/public/torrent$ sudo chown debian-transmission:debian-transmission auto_delete.sh


데몬 시작
jkpark@cactus:/storages/storage1/public/torrent$ sudo service transmission-daemon start



다운로드가 완료되면 리스트에서 토렌트가 제거되고 다음과 같이 로그가 남는다.

jkpark@cactus:/storages/storage1/public/torrent$ cat auto_delete_log
2016-12-29 22:05:48  removed from list : 제거된토렌트명
jkpark@cactus:/storages/storage1/public/torrent$

토렌트 서버 구축 (Transmission-daemon)


1. 다운로드 디렉토리 생성

downloads, incomplete 디렉토리 생성


jkpark@cactus:/storages/storage1/public/torrent$ ls -al
합계 16
drwxrwxr-x  4 jkpark jkpark  4096 10월 29 01:26 .
drwxrwxrwx 13 nobody nogroup 4096 12월 28 21:43 ..
drwxrwxrwx 12 jkpark jkpark  4096 12월 28 12:51 downloads
drwxrwxrwx  2 jkpark jkpark  4096 10월 29 01:26 incomplete
jkpark@cactus:/storages/storage1/public/torrent$

원래 목적은 incomplete 디렉토리에 토렌트용 HDD를 마운트하고 이 위치에 다운로드해서 저장소의 부담을 줄이고 싶었지만 토렌트용 HDD가 고장났는지 인식이 안된다..
그러므로 다운로드를 downloads 디렉토리에 하도록 설정한다.


jkpark@cactus:/storages/storage1/public/torrent$ sudo apt-get install transmission-daemon
[sudo] password for jkpark:
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다
상태 정보를 읽는 중입니다... 완료
The following additional packages will be installed:
  transmission-cli
다음 새 패키지를 설치할 것입니다:
  transmission-cli transmission-daemon
0개 업그레이드, 2개 새로 설치, 0개 제거 및 12개 업그레이드 안 함.
606 k바이트 아카이브를 받아야 합니다.
이 작업 후 3,104 k바이트의 디스크 공간을 더 사용하게 됩니다.
계속 하시겠습니까? [Y/n] y


2. 설정파일이 생성되도록 데몬을 한번 실행하고 중지한다.

jkpark@cactus:/storages/storage1/public/torrent$ sudo service transmission-daemon start
jkpark@cactus:/storages/storage1/public/torrent$ sudo service transmission-daemon stop


3. 설정

"cache-size-mb": 256,
 캐쉬 사이즈를 높게 설정할수록 IO작업이 줄어든다. 너무 높게 설정하면 RAM에 부담이 되므로 적당히 설정하자.

"download-dir": "/storages/storage1/public/torrent/downloads",
다운로드할 위치

"download-queue-enabled": true,
"download-queue-size": 4,
한번에 몇개의 다운로드를 진행할 것인지


"incomplete-dir": "/sotrages/storage1/public/torrent/incomplete",
"incomplete-dir-enabled": false,
앞에서 말했듯이 토렌트용HDD가 고장나서 비활성화 한다.


"rpc-password": "비밀번호",
"rpc-username": "아이디",

"rpc-whitelist-enabled": false,
아무곳에서나 접속할 수 있게

"umask": 0,
디폴트는 18인데 삼바에서 파일 엑세스 시 오류나서 0으로 바꿈

기타 설정방법은 https://github.com/transmission/transmission/wiki/Editing-Configuration-Files 을 보고 참고한다.

*로그인 없이 접속하고 싶으면 "rpc-authentication-required"를 false



4. 실행

jkpark@cactus:/etc/transmission-daemon$ sudo service transmission-daemon start

인터넷 브라우저에서 확인한다.

아이디/비밀번호 입력


동작되는 것을 확인할 수 있다.





* 안드로이드용 앱도 있다.

Dec 28, 2016

hdd 마운트



1. HDD 인식되는지 확인


jkpark@cactus:~$ sudo fdisk -l


Disk /dev/sdb: 1.8 TiB, 2000365289472 bytes, 3906963456 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00021365

Device     Boot Start        End    Sectors  Size Id Type
/dev/sdb1        4096 3906963455 3906959360  1.8T 83 Linux


새HDD의 경우 파티션설정과 포맷을 해야하지만,
이미 파일시스템이 있는 HDD를 인식한 것이기 때문에 파티션설정과 포맷은 생략한다.




2. 마운트할 UUID 확인

jkpark@cactus:~$ ls -l /dev/disk/by-uuid/
합계 0

lrwxrwxrwx 1 root root 10 12월 28 21:00 6defc19e-35d6-43a9-92c4-7240a90cc914 -> ../../sdb1


3. 마운트할 경로
jkpark@cactus:~$ sudo mkdir /storages
jkpark@cactus:~$ cd /storages/
jkpark@cactus:/storages$ sudo mkdir storage1


4. fstab 편집


jkpark@cactus:/storages$ sudo vi /etc/fstab

...
# /storages/storage1 was pm /dev/sdb1, jkpark mounted
UUID=6defc19e-35d6-43a9-92c4-7240a90cc914       /storages/storage1      ext4    defaults        0       1

5. 마운트 확인
jkpark@cactus:/storages$ sudo mount -a
jkpark@cactus:/storages$ ls storage1/
public
jkpark@cactus:/storages$

6. 권한변경
jkpark@cactus:/storages$ sudo chown jkpark:jkpark storage1/
jkpark@cactus:/storages$ ls -al
합계 12
drwxr-xr-x  3 root   root   4096 12월 28 21:11 .
drwxr-xr-x 25 root   root   4096 12월 28 21:10 ..
drwxr-xr-x  3 jkpark jkpark 4096 11월 16 16:35 storage1
jkpark@cactus:/storages$

7. 확인

jkpark@cactus:/storages$ df -h
Filesystem      Size  Used Avail Use% Mounted on
...
/dev/sdb1       1.8T  199G  1.6T  12% /storages/storage1
jkpark@cactus:/storages$

Nov 22, 2016

Rename Files In Android Studio


1. Select file + Shift + F6
2. Select file with right click + Refactor + Rename


Nov 16, 2016

Resilio (구버전: btsync, BitTorrent Sync) 를 이용한 안드로이드, 아이폰, 서버, 데스크탑 동기화

스마트폰에서 찍은 사진을 서버에 백업하고
다른 스마트폰과 공유하기 위해 동기화 프로그램이 필요하였다.
구글 드라이브같은 클라우드 서비스를 이용하면 간단하게 동기화를 할 수 있지만,
3자에게 정보를 공유해야하고 용량 제한, 업로드 속도 등 여러가지 제약이 많다.
Resilio Sync는 device to device 동기화이기 때문에 이번 기회에 사용해보고 싶었다.


다른 싱크프로그램도 많지만 아이폰, 안드로이드 뿐만 아니라 리눅스, 윈도우 모든 OS에서 동작하는 싱크프로그램이 필요하기 때문에 Resilio를 택했다.

또한 Resilio Sync는 bitTorrent Sync 의 새로운 버전이고 토렌트방식으로 동기화를 한다.


이 포스트를 통해 다음을 진행할 것이다.

1. Ubuntu16.04에 Resilio 설치
2. Windows 10 desktop 에 Resilio 설치
3. 우분투와 윈도우간의 동기화 테스트
4. 안드로이드폰에 Resilio 설치 및 동기화 테스트
5. 아이폰에 Resilio 설치, 테스트





Step 1: Ubuntu 16.04에 Resilio 설치

이 스텝은 https://help.getsync.com/hc/en-us/articles/206178924 의 가이드를 참고 하였다.

1. resilio-sync.list 파일 생성 및 내용 추가
jkpark@cactus:~$ sudo vi /etc/apt/sources.list.d/resilio-sync.list

아래 내용추가
deb http://linux-packages.resilio.com/resilio-sync/deb resilio-sync non-free



공개키 추가
jkpark@cactus:~$ wget -qO - https://linux-packages.resilio.com/resilio-sync/key.asc | sudo apt-key add -
OK
jkpark@cactus:~$

설치
jkpark@cactus:~$ sudo apt-get update
jkpark@cactus:~$ sudo apt-get install resilio-sync

설정
jkpark@cactus:~$ sudo systemctl enable resilio-sync
Synchronizing state of resilio-sync.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install enable resilio-sync

jkpark@cactus:~$ sudo vi /etc/resilio-sync/config.json

자신의 아이피로 설정


실행
jkpark@cactus:~$ sudo systemctl start resilio-sync


확인

setting - preferences 에서 default folder location 과 언어를 변경



서비스 재시작
jkpark@cactus:~$ sudo systemctl restart resilio-sync

확인


Step 2: Windows 10에 Resilio 설치
https://www.resilio.com/individuals/ 페이지에서 free download 를 눌러 설치파일을 다운로드한다.

설치





Step 3: 동기화 테스트

우분투에서 폴더 추가 버튼을 눌러 동기화할 폴더를 선택후 열기버튼 클릭

알맞게 설정 후 X버튼


읽기 및 쓰기 키를 복사



윈도우에서 키 또는 링크를 입력 버튼 클릭

복사한 키 붙여넣고 다음 클릭

폴더 선택을 하면 다음과 같이 온라인 상태인 피어에 1of 1이라고 뜬다.
우분투와 윈도우가 동기화 상태가 되었다.


아무 파일이나 동기화폴더인 sync_test_window 에 넣어보니
우분투의 test 폴더에 파일이 생성되었다.


Step 4: 안드로이드폰에 Resilio 설치 및 동기화 테스트

테스트한 기종은 V20 입니다.
설치 후 테스트를 할 목적이었지만 방법이 어렵지 않기때문에
주목적이었던 사진 폴더 동기화를 바로 진행하였다.

설치

이름 설정

폴더 만들기 클릭

위치 지정 (카메라 기본 위치 선택함)

완료.
우측의 info 아이콘 클릭

권한 : 읽기 및 쓰기 (서버에서 삭제/추가 가능하도록)
링크 만료 : 절대 안함



선택적 동기화 해제 후 공유하기 클릭
(공유링크를 카카오톡으로 보냄)



윈도우로 돌아와서 


폴더 추가 옆 + 버튼 클릭 - 키 또는 링크를 입력 클릭
공유 링크 붙여넣기

저장 위치 지정



승인 대기 중...


스마트폰으로 돌아와서
우측상단에 알림아이콘 클릭

승인


승인이 완료되면 동기화를 시작한다.
우측하단 ↑11.4 MB/s 는 현재 업로드 속도를 표시한 것이다.

윈도우로 돌아와서
공유 지정 폴더를 보면 아래와 같이 사진이 동기화 되었다.

물론 쓰기 권한이 있기 때문에 추가/수정/삭제가 가능하고
동기화 폴더에 변화가 있으면 자동으로 스마트폰에서 동기화를 시작한다.


Step 5: 아이폰에 Resilio 설치, 테스트

설치 방법 및 일반 폴더 동기화 방법은 안드로이드와 동일하다.

하지만 예상과는 달리 아이폰의 카메라 같은 경우 읽기모드만 지원하기때문에
서버에 백업은 했지만 서버에서 추가/수정/삭제가 불가능하다.
또한 동기화가 필요한 경우 어플을 실행해야하는 불편함이 있다.



Nov 9, 2016

LEMP stack 에 WordPress 설치방법

Drupal 8 설치 후 테마, 모듈 수가 너무 적어서 Drupal 7을 설치하려고 했지만 WordPress를 설치하여 차이를 느껴보고 싶었다.


WordPress vs Joomla vs Drupal


설치 방법은
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-lemp-on-ubuntu-16-04 와
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-nginx-on-ubuntu-14-04 를 참고하였다.



설치 전 :
WordPress를 설치하기 전에 LEMP stack 이 설치되어있어야 하고, SSL가 활성화되어있어야 한다. 우분투 버전은 16.04 에서 진행하였다.

LEMP stack 설치 방법


Step1: WordPress를 위한 Database 생성 및 유저 생성

jkpark@cactus:/var/www/html$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1405
Server version: 10.0.27-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on wordpress.* to wordpressuser@localhost identified by 'your_passsword';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye
jkpark@cactus:/var/www/html$

Step2: Nginx 설정

  4     root /var/www/html/wordpress;
  5     index index.html index.htm index.php;
  6     server_name 192.168.0.102;
  7     location / {
  8         index index.php;
  9         try_files $uri $uri/ /index.php$is_args$args;
 10 #try_files $uri $uri/ =404;
 11     }

테스트 & 재시작

jkpark@cactus:/var/www/html$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
jkpark@cactus:/var/www/html$ sudo systemctl restart nginx
jkpark@cactus:/var/www/html$

Step3: WordPress 다운로드

jkpark@cactus:/tmp$ curl -O https://wordpress.org/latest.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 7774k  100 7774k    0     0   465k      0  0:00:16  0:00:16 --:--:--  218k
jkpark@cactus:/tmp$
jkpark@cactus:/tmp$ tar xzvf latest.tar.gz

jkpark@cactus:/tmp$ cp wordpress/wp-config-sample.php wordpress/wp-config.php

wp-config-sample.php 샘플설정 파일의 대부분의 설정은 알맞게 되어있어므로 복사하여 기본 설정 파일로 만들어주었다.


jkpark@cactus:/tmp$ mkdir /tmp/wordpress/wp-content/upgrade

upgrade 디렉토리를 생성하고 WordPress를 업그레이드하면 upgrade 디렉토리안에 업그레이드에 필요한 파일들이 설치된다.

/tmp/wordpress 를 /var/www/html/wordpress 로 복사한다.
jkpark@cactus:/tmp/wordpress$ sudo cp -a /tmp/wordpress /var/www/html/wordpress

Step4: 소유권과 권한 설정

여기서 하는 작업은 타당한 접근 권한과 소유권을 설정하는 것이다. 일반유저가 파일을 쓸 수 있어야하고, web server가 파일과 디렉토리에 접근, 조작할 수 있어야한다.

1. 파일의 소유권은 sudo 유저로 한다.

jkpark@cactus:/var/www/html$ sudo chown -R jkpark:www-data /var/www/html/wordpress
[sudo] password for jkpark:
jkpark@cactus:/var/www/html$ ls -al
합계 24
drwxr-xr-x 4 www-data www-data 4096 11월  9 21:53 .
drwxr-xr-x 3 root     root     4096 11월  9 14:24 ..
drwxr-xr-x 8 www-data www-data 4096 11월  2 18:08 drupal
-rwxr-xr-x 1 www-data www-data  612 11월  8 22:06 index.nginx-debian.html
-rwxr-xr-x 1 www-data www-data   20 11월  8 23:58 info.php
drwxr-xr-x 5 jkpark   www-data 4096 11월  9 21:44 wordpress
jkpark@cactus:/var/www/html$

2. 각각의 디렉토리에 setgid 설정으로 새로 생성되는 파일들은 www-data 그룹을 상속받게 한다. 이 설정으로 web server가 생성된 파일들의 group ownership을 가지고 있게 한다.

jkpark@cactus:/var/www/html/wordpress$ sudo find . -type d -exec chmod g+s {} \;
jkpark@cactus:/var/www/html/wordpress$ ls -al
합계 196
drwxr-sr-x  5 jkpark   www-data  4096 11월  9 21:44 .
drwxr-xr-x  4 www-data www-data  4096 11월  9 21:53 ..
-rw-r--r--  1 jkpark   www-data   418  9월 25  2013 index.php
-rw-r--r--  1 jkpark   www-data 19935  3월  6  2016 license.txt
-rw-r--r--  1 jkpark   www-data  7344  8월 17 05:39 readme.html
-rw-r--r--  1 jkpark   www-data  5456  5월 25 06:02 wp-activate.php
drwxr-sr-x  9 jkpark   www-data  4096  9월  7 23:58 wp-admin
-rw-r--r--  1 jkpark   www-data   364 12월 19  2015 wp-blog-header.php
-rw-r--r--  1 jkpark   www-data  1477  5월 24 01:44 wp-comments-post.php
-rw-r--r--  1 jkpark   www-data  2853 12월 16  2015 wp-config-sample.php
-rw-r--r--  1 jkpark   www-data  2853 11월  9 21:44 wp-config.php
drwxr-sr-x  5 jkpark   www-data  4096 11월  9 21:47 wp-content
-rw-r--r--  1 jkpark   www-data  3286  5월 25  2015 wp-cron.php
drwxr-sr-x 17 jkpark   www-data 12288  9월  7 23:58 wp-includes
-rw-r--r--  1 jkpark   www-data  2382  5월 24 01:44 wp-links-opml.php
-rw-r--r--  1 jkpark   www-data  3353  4월 15  2016 wp-load.php
-rw-r--r--  1 jkpark   www-data 34057  6월 15 06:51 wp-login.php
-rw-r--r--  1 jkpark   www-data  7786  7월 13 21:37 wp-mail.php
-rw-r--r--  1 jkpark   www-data 13920  8월 14 01:02 wp-settings.php
-rw-r--r--  1 jkpark   www-data 29890  5월 25 05:44 wp-signup.php
-rw-r--r--  1 jkpark   www-data  4035 12월  1  2014 wp-trackback.php
-rw-r--r--  1 jkpark   www-data  3064  7월  6 21:40 xmlrpc.php
jkpark@cactus:/var/www/html/wordpress$


3. 아래 명령어로 group write permission을 부여하여 web interface 가 theme 와 plugin 변경 가능하도록 한다.

jkpark@cactus:/var/www/html/wordpress$ sudo chmod g+w wp-content
jkpark@cactus:/var/www/html/wordpress$ sudo chmod -R g+w wp-content/themes
jkpark@cactus:/var/www/html/wordpress$ sudo chmod -R g+w wp-content/plugins
jkpark@cactus:/var/www/html/wordpress$
jkpark@cactus:/var/www/html/wordpress$ ls -al wp-content/
합계 24
drwxrwsr-x 5 jkpark www-data 4096 11월  9 21:47 .
drwxr-sr-x 5 jkpark www-data 4096 11월  9 21:44 ..
-rw-r--r-- 1 jkpark www-data   28  1월  9  2012 index.php
drwxrwsr-x 3 jkpark www-data 4096  9월  7 23:59 plugins
drwxrwsr-x 5 jkpark www-data 4096  9월  7 23:59 themes
drwxrwsr-x 2 jkpark www-data 4096 11월  9 21:47 upgrade
jkpark@cactus:/var/www/html/wordpress$


Step 5: WordPress 환경설정


WordPress main configuration 파일을 열었을 때 제일 먼저 해야할 일은 보안키를 설정하는 것이다. WordPress가 제공하는 secure generator를 이용하여 키 값을 만들 수 있다.


jkpark@cactus:/var/www/html/wordpress$ curl -s https://api.wordpress.org/secret-key/1.1/salt/
define('AUTH_KEY',         '(@p -;LQVf1$wxO1 pt&이 글을 복사하지 마세요MhU6+9z2');
define('SECURE_AUTH_KEY',  ')+SoyfkO!HX=vRC(fhb6이 글을 복사하지 마세요Bo&f]KmO');
define('LOGGED_IN_KEY',    'IFBwv/%~3Jwk?(rP,]1C이 글을 복사하지 마세요E ,b]u0V');
define('NONCE_KEY',        '|fHfPA!U,Yh*F:HfZ9[r이 글을 복사하지 마세요eQ?=3>#B');
define('AUTH_SALT',        '|:+NB@<h98|--t)a-dW/이 글을 복사하지 마세요cUx;)x/1');
define('SECURE_AUTH_SALT', 'ZVj.^eMKAtY:5+g:xhu1이 글을 복사하지 마세요T px,TY(');
define('LOGGED_IN_SALT',   'Uv5786a=D%R(~H.zWDJB이 글을 복사하지 마세요Q$XyRWsR');
define('NONCE_SALT',       '$:!yP|#[i8w|FQSBP&&D이 글을 복사하지 마세요4A2=Zp>E');
jkpark@cactus:/var/www/html/wordpress$

생성된 키들을 WordPress 환경설정 파일에 복사한다.
jkpark@cactus:/var/www/html/wordpress$ vi wp-config.php

아래 라인에 위에서 생성한 key들을 붙여넣는다.

 49 define('AUTH_KEY',         'put your unique phrase here');
 50 define('SECURE_AUTH_KEY',  'put your unique phrase here');
 51 define('LOGGED_IN_KEY',    'put your unique phrase here');
 52 define('NONCE_KEY',        'put your unique phrase here');
 53 define('AUTH_SALT',        'put your unique phrase here');
 54 define('SECURE_AUTH_SALT', 'put your unique phrase here');
 55 define('LOGGED_IN_SALT',   'put your unique phrase here');
 56 define('NONCE_SALT',       'put your unique phrase here');


Database 설정

 23 define('DB_NAME', 'wordpress');
 24
 25 /** MySQL database username */
 26 define('DB_USER', 'wordpressuser');
 27
 28 /** MySQL database password */
 29 define('DB_PASSWORD', '비밀번호');
 30
 31 /** MySQL hostname */
 32 define('DB_HOST', 'localhost');
 33
 34 /** Database Charset to use in creating database tables. */
 35 define('DB_CHARSET', 'utf8');
 36
 37 /** The Database Collate type. Don't change this if in doubt. */
 38 define('DB_COLLATE', '');

save and close the file


Step 6: Web Interface를 이용하여 설치를 완료한다.






*: 업그레이드 방법

WordPress의 업그레이드가 가능할 경우 현재 권한으로는 업그레이드를 진행할 수 없다.

위에서 설정한 소유권과 권한으로 보안성이 높아져 소프트웨어가 스스로 update를 완료할 수는 없다.

따라서 업그레이드 시, 임시적으로 web server에게 소유권을 주어 업그레이드를 진행한다.
sudo chown -R www-data /var/www/html/wordpress

업그레이드 완료 시 다시 sudo user에게 소유권을 준다.
sudo chown -R jkpark /var/www/html/wordpress



How to install Drupal 8.2.2

https://www.drupal.org/download 에서 최신버전의 바이너리를 확인


jkpark@cactus:/var/www/html$ sudo wget https://ftp.drupal.org/files/projects/drupal-8.2.2.zip
--2016-11-09 14:26:53--  https://ftp.drupal.org/files/projects/drupal-8.2.2.zip
Resolving ftp.drupal.org (ftp.drupal.org)... 151.101.76.68
접속 ftp.drupal.org (ftp.drupal.org)|151.101.76.68|:443... 접속됨.
HTTP request sent, awaiting response... 200 OK
Length: 21205013 (20M) [application/zip]
Saving to: ‘drupal-8.2.2.zip’

drupal-8.2.2.zip            100%[===========================================>]  20.22M  6.32MB/s    in 3.7s

2016-11-09 14:26:58 (5.53 MB/s) - ‘drupal-8.2.2.zip’ saved [21205013/21205013]

jkpark@cactus:/var/www/html$ ls -al
합계 20728
drwxr-xr-x 2 www-data www-data     4096 11월  9 14:26 .
drwxr-xr-x 3 root     root         4096 11월  9 14:24 ..
-rw-r--r-- 1 root     root     21205013 11월  3 03:08 drupal-8.2.2.zip
-rwxr-xr-x 1 www-data www-data      612 11월  8 22:06 index.nginx-debian.html
-rwxr-xr-x 1 www-data www-data       20 11월  8 23:58 info.php
jkpark@cactus:/var/www/html$
jkpark@cactus:/var/www/html$ sudo unzip drupal-8.2.2.zip

jkpark@cactus:/var/www/html$ sudo mv drupal-8.2.2 drupal
jkpark@cactus:/var/www/html$ ls -al
합계 20732
drwxr-xr-x 3 www-data www-data     4096 11월  9 14:28 .
drwxr-xr-x 3 root     root         4096 11월  9 14:24 ..
drwxr-xr-x 8 root     root         4096 11월  2 18:08 drupal
-rw-r--r-- 1 root     root     21205013 11월  3 03:08 drupal-8.2.2.zip
-rwxr-xr-x 1 www-data www-data      612 11월  8 22:06 index.nginx-debian.html
-rwxr-xr-x 1 www-data www-data       20 11월  8 23:58 info.php
jkpark@cactus:/var/www/html$ sudo rm drupal-8.2.2.zip
jkpark@cactus:/var/www/html$

jkpark@cactus:/var/www/html$ sudo chown www-data: -R drupal
jkpark@cactus:/var/www/html$ ls -al
합계 20
drwxr-xr-x 3 www-data www-data 4096 11월  9 14:29 .
drwxr-xr-x 3 root     root     4096 11월  9 14:24 ..
drwxr-xr-x 8 www-data www-data 4096 11월  2 18:08 drupal
-rwxr-xr-x 1 www-data www-data  612 11월  8 22:06 index.nginx-debian.html
-rwxr-xr-x 1 www-data www-data   20 11월  8 23:58 info.php
jkpark@cactus:/var/www/html$ 

데이터베이스 생성
jkpark@cactus:/var/www/html$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 10.0.27-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database drupal;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on drupal.* to drupaluser@localhost identified by 'your_password';
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye
jkpark@cactus:/var/www/html$

확인

jkpark@cactus:/var/www/html$ mysql -u drupaluser -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 34
Server version: 10.0.27-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> exit
Bye
jkpark@cactus:/var/www/html$


drupal 접속을 위해 nginx default 설정파일을 수정한다.
jkpark@cactus:/etc/nginx/sites-available$ sudo vi default


  4     root /var/www/html/drupal;
  5     index index.html index.htm index.php;
  6     server_name 192.168.0.102;
  7     location / {
  8         index index.php;
  9         try_files $uri $uri/ /index.php$is_args$args;
 10 #try_files $uri $uri/ =404;
 11     }



테스트 & 재시작
jkpark@cactus:/etc/nginx/sites-available$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
jkpark@cactus:/etc/nginx/sites-available$ sudo systemctl restart nginx
jkpark@cactus:/etc/nginx/sites-available$

설정






php gd모듈과 xml 모듈 설치

jkpark@cactus:/etc/nginx/sites-available$ sudo apt-get install php7.0-gd php7.0-xml
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다
상태 정보를 읽는 중입니다... 완료
다음 새 패키지를 설치할 것입니다:
  php7.0-gd php7.0-xml
0개 업그레이드, 2개 새로 설치, 0개 제거 및 2개 업그레이드 안 함.
139 k바이트 아카이브를 받아야 합니다.
이 작업 후 613 k바이트의 디스크 공간을 더 사용하게 됩니다.
받기:1 http://kr.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0-gd amd64 7.0.8-0ubuntu0.16.04.3 [27.1 kB]
받기:2 http://kr.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0-xml amd64 7.0.8-0ubuntu0.16.04.3 [112 kB]
내려받기 139 k바이트, 소요시간 0초 (583 k바이트/초)
Selecting previously unselected package php7.0-gd.
(데이터베이스 읽는중 ...현재 212758개의 파일과 디렉터리가 설치되어 있습니다.)
Preparing to unpack .../php7.0-gd_7.0.8-0ubuntu0.16.04.3_amd64.deb ...
Unpacking php7.0-gd (7.0.8-0ubuntu0.16.04.3) ...
Selecting previously unselected package php7.0-xml.
Preparing to unpack .../php7.0-xml_7.0.8-0ubuntu0.16.04.3_amd64.deb ...
Unpacking php7.0-xml (7.0.8-0ubuntu0.16.04.3) ...
Processing triggers for php7.0-fpm (7.0.8-0ubuntu0.16.04.3) ...
php7.0-gd (7.0.8-0ubuntu0.16.04.3) 설정하는 중입니다 ...

Creating config file /etc/php/7.0/mods-available/gd.ini with new version
php7.0-xml (7.0.8-0ubuntu0.16.04.3) 설정하는 중입니다 ...

Creating config file /etc/php/7.0/mods-available/dom.ini with new version

Creating config file /etc/php/7.0/mods-available/simplexml.ini with new version

Creating config file /etc/php/7.0/mods-available/wddx.ini with new version

Creating config file /etc/php/7.0/mods-available/xml.ini with new version

Creating config file /etc/php/7.0/mods-available/xmlreader.ini with new version

Creating config file /etc/php/7.0/mods-available/xmlwriter.ini with new version

Creating config file /etc/php/7.0/mods-available/xsl.ini with new version
Processing triggers for php7.0-fpm (7.0.8-0ubuntu0.16.04.3) ...
jkpark@cactus:/etc/nginx/sites-available$ sudo systemctl restart php7.0-fpm.service
jkpark@cactus:/etc/nginx/sites-available$









설치 완료.

How To Install Nginx, MariaDB10, PHP7(LEMP stack) on Ubuntu16.04

LEMP Stack 이란

Linux, Nginx, MariaDB, PHP를 조합하여 줄인말이다.

Apache vs Nginx
Nginx(엔진X)는 Apache의 잘 사용하지 않는 기능을 제외하고 새로운 시대의 요청에 부응하여 만들어진 웹 서버이다.

https://news.netcraft.com/archives/2016/02/22/february-2016-web-server-survey.html

MariaDB 는 MySQL의 불확실한 라이선스 상태에 반발하여 만들어졌으며 MariaDB 5.5버전까지는 모든 MySQL의 특징을 가지고 있었다.
5.5버전 이후 MariaDB만의 색깔을 더 분명히 하고자 개발판을 10.x로 변경하였다.


Step1 : Nginx Web Server 설치

1. install Nginx

jkpark@cactus:~$ sudo apt-get install nginx
[sudo] password for jkpark:
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다
상태 정보를 읽는 중입니다... 완료
The following additional packages will be installed:
  nginx-common nginx-core
제안하는 패키지:
  fcgiwrap nginx-doc
다음 새 패키지를 설치할 것입니다:
  nginx nginx-common nginx-core
0개 업그레이드, 3개 새로 설치, 0개 제거 및 2개 업그레이드 안 함.
458 k바이트 아카이브를 받아야 합니다.
이 작업 후 1,482 k바이트의 디스크 공간을 더 사용하게 됩니다.
계속 하시겠습니까? [Y/n] y
받기:1 http://kr.archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx-common all 1.10.0-0ubuntu0.16.04.4 [26.6 kB]
받기:2 http://kr.archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx-core amd64 1.10.0-0ubuntu0.16.04.4 [428 kB]
받기:3 http://kr.archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx all 1.10.0-0ubuntu0.16.04.4 [3,498 B]
내려받기 458 k바이트, 소요시간 0초 (1,224 k바이트/초)
패키지를 미리 설정하는 중입니다...
Selecting previously unselected package nginx-common.
(데이터베이스 읽는중 ...현재 212073개의 파일과 디렉터리가 설치되어 있습니다.)
Preparing to unpack .../nginx-common_1.10.0-0ubuntu0.16.04.4_all.deb ...
Unpacking nginx-common (1.10.0-0ubuntu0.16.04.4) ...
Selecting previously unselected package nginx-core.
Preparing to unpack .../nginx-core_1.10.0-0ubuntu0.16.04.4_amd64.deb ...
Unpacking nginx-core (1.10.0-0ubuntu0.16.04.4) ...
Selecting previously unselected package nginx.
Preparing to unpack .../nginx_1.10.0-0ubuntu0.16.04.4_all.deb ...
Unpacking nginx (1.10.0-0ubuntu0.16.04.4) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu12) ...
nginx-common (1.10.0-0ubuntu0.16.04.4) 설정하는 중입니다 ...
nginx-core (1.10.0-0ubuntu0.16.04.4) 설정하는 중입니다 ...
nginx (1.10.0-0ubuntu0.16.04.4) 설정하는 중입니다 ...
Processing triggers for systemd (229-4ubuntu12) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
jkpark@cactus:~$


2. netstat, systemctl 또는 브라우저로 nginx 동작 확인 (디폴트 포트80)

jkpark@cactus:~$ sudo systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since 화 2016-11-08 22:06:57 KST; 3min 41s ago
 Main PID: 16028 (nginx)
   CGroup: /system.slice/nginx.service
           ├─16028 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
           ├─16029 nginx: worker process
           ├─16030 nginx: worker process
           ├─16031 nginx: worker process
           └─16032 nginx: worker process

11월 08 22:06:57 cactus systemd[1]: Starting A high performance web server and a reverse proxy server...
11월 08 22:06:57 cactus systemd[1]: Started A high performance web server and a reverse proxy server.
jkpark@cactus:~$



Step2 : HTTP/2.0 프로토콜 활설화

1. lastest release of Nginx binaries의 HTTP/2.0 프로토콜은 SSL과 함께 사용해야 동작된다.
jkpark@cactus:/etc/nginx/sites-available$ sudo mv default default.backup
jkpark@cactus:/etc/nginx/sites-available$ sudo vi default

아래 내용 복사하여 HTTP/2.0 을 활성화한다.
server_name는 자신의 IP주소를 적는다.

server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
root /var/www/html;
index index.html index.htm index.php;
server_name 192.168.0.102;
location / {
try_files $uri $uri/ =404;
}
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_dhparam  /etc/nginx/ssl/dhparam.pem;
ssl_session_cache shared:SSL:20m;
ssl_session_timeout 180m;
resolver 8.8.8.8 8.8.4.4;
add_header Strict-Transport-Security "max-age=31536000;
#includeSubDomains" always;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
server {
listen         80;
listen    [::]:80;
server_name    192.168.0.102;
return         301 https://$server_name$request_uri;
}




2. 위의 default 설정이 끝나면 SSL 사용을 위한 파일을 만든다.

jkpark@cactus:/etc/nginx$ sudo mkdir ssl
jkpark@cactus:/etc/nginx$ sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
Generating a 2048 bit RSA private key
..........................................................+++
............................................................................................+++
writing new private key to '/etc/nginx/ssl/nginx.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:KR
State or Province Name (full name) [Some-State]:.
Locality Name (eg, city) []:Seoul
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Indiecoders
Organizational Unit Name (eg, section) []:.
Common Name (e.g. server FQDN or YOUR name) []:.
Email Address []:jkparkr@indiecoders.org
jkpark@cactus:/etc/nginx$

5. DH(Diffie-Hellman)암호키를 만든다.
jkpark@cactus:/etc/nginx$ sudo openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
...................................................+.................................................................+.................................................+..............................................................................................................................................................+..............................................................................................................................+.............................................................................................................................+.........................+.........+...................................................................................................................................................................................+........................................................................+..............................................................................................................................+.......................................................................................................................................+.....+......+....................................................................................................................................................................................................................................................+...............................................................+.......................................+....................................................................+....................................................................................................................................................................................+....................+...+.............+......................................................................................................................................................................................................+...................................................................................+...................................+.................+....................................................................................+.................................+................................................................................................................................................................................................+.....................+................................................................................................................................................................+...............................................................................................................................................................................................+................................................................................................+.................................+....................................................................................................................................+.+..............................................................................................................................................................................................................+.........................+..............................................................................................................................................................................+...........................................................................................+................................................................................................................................................+...................+..........................................................+....+........................................................................+.............................................................................................................................................+....................................................................................+..........................................................................................................+........................................................+.................................................................+..........................................................................................................+...............................+............................................................................................+.................................................................+.......................+..............................+.............................................................+...............................................................................................................................................................................................................................+...........................................................................+.......................................................................+........+.....................................................................................+........................................................................................................................................................+..........................................................................................................................................................+...................................................................................................................................+........................................................+..........................................................................................................................................................................++*++*
jkpark@cactus:/etc/nginx$


3. DH암호키가 만들어졌다면 Nginx 설정이 제대로 되었는지 확인해본다.

jkpark@cactus:/etc/nginx$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
jkpark@cactus:/etc/nginx$
jkpark@cactus:/etc/nginx$ sudo systemctl restart nginx.service
jkpark@cactus:/etc/nginx$

4.  아래 명령어로 Nginx가 HTTP/2.0 프로토콜을 사용하고 있는지 확인할 수 있다.

jkpark@cactus:/etc/nginx$ openssl s_client -connect localhost:443 -nextprotoneg ''
CONNECTED(00000003)
Protocols advertised by server: h2, http/1.1
140205134509720:error:140920E3:SSL routines:ssl3_get_server_hello:parse tlsext:s3_clnt.c:1152:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 87 bytes and written 7 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
Next protocol: (2)
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : 0000
    Session-ID:
    Session-ID-ctx:
    Master-Key:
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1478612682
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)
---
jkpark@cactus:/etc/nginx$

Step3 : PHP7 설치

1. Nginx w/ FastCGI 세팅을 위해 PHP7과 PHP-FPM을 설치한다.

jkpark@cactus:~$ sudo apt install php7.0 php7.0-fpm

설치가 끝나면 PHP-FPM을 실행하고 체크해본다.

jkpark@cactus:~$ sudo systemctl start php7.0-fpm
jkpark@cactus:~$ sudo systemctl status php7.0-fpm
● php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since 화 2016-11-08 23:47:13 KST; 1min 14s ago
 Main PID: 23164 (php-fpm7.0)
   Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
   CGroup: /system.slice/php7.0-fpm.service
           ├─23164 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
           ├─23168 php-fpm: pool www
           └─23169 php-fpm: pool www

11월 08 23:47:13 cactus systemd[1]: Starting The PHP 7.0 FastCGI Process Manager...
11월 08 23:47:13 cactus systemd[1]: Started The PHP 7.0 FastCGI Process Manager.
jkpark@cactus:~$

Step2.1 에서 설정한 Nginx default 설정 파일에 아래 구문을 통해 이미 PHP FastCGI에 대한 설정을 하였다.

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

2. 아래 명령어를 통해 info.php 파일을 만들어 PHP 설정을 확인할 수 있다.
jkpark@cactus:~$ sudo su -c 'echo "<?php phpinfo(); ?>" |tee /var/www/html/info.php'
<?php phpinfo(); ?>
jkpark@cactus:~$


또한 $_SERVER['SERVER_PROTOCOL'] 항목에서 HTTP/2.0 프로토콜이 동작중인지 확인할 수 있다.

3. apt search php7.0 명령어를 통해 모듈을 검색할 수 있고
sudo apt install php7.0-**** 을 통해 모듈을 설치하였다면
PHP-FPM 데몬을 재시작하여 설치된 모듈을 등록할 수 있다.

sudo systemctl restart php7.0-fpm.service

Step4 : MariaDB 설치

1. 미지막으로 MariaDB를 설치하여 LEMP Stack을 완성시키자.

jkpark@cactus:~$ sudo apt install mariadb-server mariadb-client php7.0-mysql

설치 후 PHP-RPM 데몬 재시작한다.

jkpark@cactus:~$ sudo systemctl restart php7.0-fpm.service


2. mysql_secure_installation 스크립트를 실행하여 MariaDB의 root password를 설정한다.

jkpark@cactus:~$ sudo 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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

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

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

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!
jkpark@cactus:~$

3. 일반유저가 sudo 특권없이 Database에 접근하기 위해 아래 명령어를 입력한다.

jkpark@cactus:~$ sudo mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 48
Server version: 10.0.27-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> update user set plugin='' where User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> exit
Bye
jkpark@cactus:~$

이제 sudo 없이 mysql에 접근할 수 있다.

jkpark@cactus:~$ mysql -u root -p -e 'show databases'
Enter password:
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
jkpark@cactus:~$

4. 언어셋 설정
기본언어셋으로 utf8mb4_general_ci가 설정되어 있는데 이것을 utf8mb4_unicode_ci로 바꿔준다.
difference between utf8_general_ci and utf8_unicode_ci

jkpark@cactus:/etc/mysql/mariadb.conf.d$ sudo vi 50-server.cnf

105 character-set-server  = utf8mb4
106 #original
107 #collation-server      = utf8mb4_general_ci
108 #jkpark modified 2016-11-09
109 collation-server      = utf8mb4_unicode_ci



설정이 끝나면 mysql 데몬을 제시작하고 아래 명령어로 언어셋을 확인한다.

MariaDB [(none)]> show variables like "%character%";show variables like "%collation%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8mb4                    |
| character_set_connection | utf8mb4                    |
| character_set_database   | utf8mb4                    |
| character_set_filesystem | binary                     |
| character_set_results    | utf8mb4                    |
| character_set_server     | utf8mb4                    |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

+----------------------+--------------------+
| Variable_name        | Value              |
+----------------------+--------------------+
| collation_connection | utf8mb4_general_ci |
| collation_database   | utf8mb4_unicode_ci |
| collation_server     | utf8mb4_unicode_ci |
+----------------------+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]>

** collation_connection 은 utf8mb4_unicode_ci 로 설정이 안되는데 아시는분은 답글부탁드립니다.

이상으로 LEMP Stack 설치가 끝났다.

Nov 6, 2016

iptables 룰 영구적으로 저장



1. create /etc/network/if-pre-up.d/iptables file and put

#!/bin/sh
iptables-restore < /etc/iptables.rules
exit 0


2. create /etc/network/if-post-down.d/iptables file and put

#!/bin/sh
iptables-save -c > /etc/iptables.rules
if [ -f /etc/iptables.rules ]; then
    iptables-restore < /etc/iptables.rules
fi
exit 0



jkpark@cactus:~$ sudo chmod +x /etc/network/if-post-down.d/iptables
jkpark@cactus:~$ sudo chmod +x /etc/network/if-pre-up.d/iptables

Nov 5, 2016

How to setup vsftpd on ubuntu


jkpark@cactus:~$ sudo apt-get install vsftpd
다음 새 패키지를 설치할 것입니다:
  vsftpd
0개 업그레이드, 1개 새로 설치, 0개 제거 및 6개 업그레이드 안 함.
115 k바이트 아카이브를 받아야 합니다.
이 작업 후 336 k바이트의 디스크 공간을 더 사용하게 됩니다.
받기:1 http://kr.archive.ubuntu.com/ubuntu xenial/main amd64 vsftpd amd64 3.0.3-3ubuntu2 [115 kB]
내려받기 115 k바이트, 소요시간 0초 (974 k바이트/초)
패키지를 미리 설정하는 중입니다...
Selecting previously unselected package vsftpd.
(데이터베이스 읽는중 ...현재 211923개의 파일과 디렉터리가 설치되어 있습니다.)
Preparing to unpack .../vsftpd_3.0.3-3ubuntu2_amd64.deb ...
Unpacking vsftpd (3.0.3-3ubuntu2) ...
Processing triggers for systemd (229-4ubuntu11) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for man-db (2.7.5-1) ...
vsftpd (3.0.3-3ubuntu2) 설정하는 중입니다 ...
Processing triggers for systemd (229-4ubuntu11) ...
Processing triggers for ureadahead (0.100.0-19) ...
jkpark@cactus:~$

jkpark@cactus:~$ sudo vi /etc/vsftpd.conf

uncomment the below lines (line no:31, 35, 122, 123 and 125)
write_enable=YES
local_umask=022
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list

chroot_local_user에 대해..
FTP접속 시 홈 디렉토리의 상위 디렉토리 이동을 막기 위한 설정.
Default 상태(chroot_local_user=YES에 주석처리되어 있음)
- ftp접속 후 pwd 시 '/home/user1' 로 나옴. 상위 이동 가능
chroot_local_user=YES 설정
- FTP접속 후 pwd 시 '/'로 나옴. 상위 이동 불가능
chroot_list_enable=YES 설정
- FTP 접속 실패. 
chroot_list 파일 생성
- FTP 접속 시 '/'로 나옴. 상위 이동 불가능
chroot_list 파일 안에 user1 등록
- user1은 ftp 접속 시 '/home/user1'로 나옴. 상위 이동 가능
- user2는 ftp 접속 시 '/'로 나옴. 상위 이동 불가능

즉 chroot_local_user=YES 설정은 ftp 접속 시 홈 디렉토리를 root 디렉토리 처럼 인식하도록 하는 설정이다.
http://blog.naver.com/jbells/220416391250



Add the following lines to enable passive mode
pasv_enable=Yes
pasv_min_port=40000
pasv_max_port=40100

Add the following lines to enable utf8
utf8_filesystem=YES

Add the following lines to enable write permission on root directory
allow_writeable_chroot=YES

Restart vsftpd service
jkpark@cactus:~$ sudo service vsftpd restart


jkpark@cactus:~$ sudo iptables -I INPUT -p tcp --destination-port 40000:40100 -j ACCEPT

jkpark@cactus:~$ sudo iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere             tcp dpts:40000:40100