지금까지 이런 경우가 없었던것 같은데 계속 nginx의 proxy_cache설정을 해도 캐시가 MISS난다.
원인을 찾다보니...

proxy_buffering off;

설정이 include한 파일에 들어가 있어서....

AWS의 Lightsail을 하나 쓰고 있는데, 전과는 다른 이유로 갑자기 SSH 로그인이 되지 않는 문제가 발생했다.

This account is currently not available

음... 이건... /etc/passwd에서 로그인을 안되게 해 설정해 놓은 경우 그러던데..
그런데 내가 만지지도 않았던거 같은데 왜??

전에 비슷한 경험을 한 게 있어 큰 당황 없이 해결해 본다.

1. 스냅샷을 뜬다.
2. 스냅샷으로 새 인스턴스를 생성하며, 시작스크립트에 다음처럼 명령을 넣는다. (그렇게 되면 인스턴스가 새로 시작될때 루트 권한으로 해당 명령이 실행된다. 해당 명령은 ubuntu 계정의 쉘을 bash로 세팅해서 로그인이 가능하게 하는 명령이다.)

3. 새 인스턴스에 SSH가 로그인이 되는것을 확인한 후 기존 인스턴스를 지운다.
4. 기존 인스턴스에 설정된 고정아이피를 새 인스턴스에 할당한다.

해결은 잘 됐다..

그런데... 왜 자꾸 이런 일이 일어나지? 설마 누가 자꾸 만지나??? 

구글에서 최근에 64비트를 지원하지 않은 앱을 64비트 지원하도록 업데이트 하라는 메일을 보내왔는데,
스토어에 올려진 앱 소스코드를 찾지 못했다.

앱 자체는 간단한 프로그램이라 금방 다시 개발하면 됐지만,
앱에 서명을 같은 키스토어로 해야 업로드가 되는데 키스토어는 어쩔수가 없었다.

그래서 안드로이드 스튜디오에서 새로 키스토어 파일을 생성한 후,
아래 명령으로 pem 파일로 변환하였다. (구글에 신규 키스토어 제출시 pem파일로 전달해야 함, 빨간색 부분은 각자 변경해서 사용하세요. )

 keytool -export -rfc -alias alias -file newkeystore.pem -keystore keystore.file

그리고 나서, 아래 페이지에 접속해 간단히 설명후 키스토어 pem파일을 첨부하여 접수하면
약 2~3일 후 신규 키스토어를 사용해 앱을 업로드할 수 있게 된다.

https://support.google.com/googleplay/android-developer/contact/otherbugs

 

일반적인 문제 - Play Console 고객센터

 

support.google.com

 

개인적으로, 업무적으로 AWS를 사용하고, 그중에 이번에 문제가 발생한 것은 Lightsail 이었다.

거의 아마존 EC2와 비슷한 시스템인데 EC2에 비해 단순하게 만들어진 시스템인것 같다.


아무튼, Lightsail에 생성한 인스턴스 중에서 알 수 없는 이유로 SSH접속을 할수 없는 게 하나 있었는데 바쁜 업무때문에 손도 못대고 있었다.

Connection closed by xx.xxx.xxx.xxx port 22


그러다 어제 문득 돈내고 쓰는 상품을 이렇게 방치해야되나 싶은 생각이 들어서 AWS 지원센터에 물어봤더니...

결국 오늘 돌아온 대답은 SSH포트를 방화벽에서 열었냐는..

지금까지 SSH 잘 접속했었는데?? 그리고 설마 그것도 확인 안해봤을까...


구글링을 열심히 해봤는데 특별한 답을 못찾았다가.. 결국 찾았다.

https://forums.aws.amazon.com/thread.jspa?threadID=251943


과정을 간단하게 설명하면 이렇다.


1. 문제가 생긴 인스턴스를 스냅샷을 뜬다.

2. 스냅샷을 이용해서 인스턴스를 생성하는데, 생성된 인스턴스 시작시에 openssh를 새로 설치하는 명령을 실행하도록 한다.
   (캡쳐를 깜빡했는데 중간쯤에 열어서 입력하는 부분이 있음)

#!/bin/bash
sudo apt-get remove openssh-client openssh-server
sudo apt-get install openssh-client openssh-server

3. 완료.


결국... 접속됨. 잘됨.


잊지 않겠다. AWS...

종종 SFTP를 이용해 서버에 파일을 업로드 하는데 갑자기 클라이언트에서 Connection timeout으로 접속이 되지 않는 문제가 발생.


서버에 로그를 확인해보니, 연결되자 마자 클라이언트에서 연결을 끊는다.

  
    $ tail -f /var/log/secure

    Accepted password for heisice from x.x.x.x port x ssh2
    pam_unix(sshd:session): session opened for user heisice by (uid=0)
    Received disconnect from x.x.x.x port x:11: disconnected by user
    Disconnected from x.x.x.x port x
    pam_unix(sshd:session): session closed for user heisice

그래서 클라이언트에서 command line sftp클라이언트에 -v 옵션을 주어 실행해보니,

  
    $ sftp -i ~/.ssh/key -v heisice@server.com

    ...

    debug2: fd 5 setting TCP_NODELAY
    debug2: client_session2_setup: id 0
    debug1: Sending environment.
    debug1: Sending env LANG = ko_KR.UTF-8
    debug2: channel 0: request env confirm 0
    debug1: Sending subsystem: sftp
    debug2: channel 0: request subsystem confirm 1
    debug2: channel_input_open_confirmation: channel 0: callback done
    debug2: channel 0: open confirm rwindow 0 rmax 32768
    debug2: channel 0: rcvd adjust 2097152
    debug2: channel_input_status_confirm: type 99 id 0
    debug2: subsystem request accepted on channel 0
    Received message too long 1315927840
    debug2: channel 0: read<=0 rfd 6 len 0
    debug2: channel 0: read failed
    debug2: channel 0: close_read
    debug2: channel 0: input open -> drain
    debug2: channel 0: ibuf empty
    debug2: channel 0: send eof
    debug2: channel 0: input drain -> closed
    debug2: channel 0: write failed
    
    ...


Received message too long 이라는 메세지가 보였다.


그래서 구글링 해보니 ssh 접속시 나오는 메세지 때문에 그런경우가 있다고 한다.
얼마전에 ~/.bashrc 파일에 추가해둔 초기화 명령에서 출력되는 메세지 때문에 그런듯 하다.

그래서 그 부분을 출력하지 않게 했더니 문제가 해결되었다.


리눅스상에서 웹 호출 문제를 디버깅 하고 싶을 때 mysql 서버 로그를 봐도 부족하고 그럴 때는 패킷을 캡쳐해서 분석할 수 있다.

If you want to debug web call problems on Linux, you may not be able to view the mysql server logs, and you can capture and analyze the packets in such cases.


tpcdump는 기본으로 설치가 안되어 있으니 설치를 해야 한다.

tcpdump can not be installed by default.


그리고 루트 계정으로 실행해야 한다.

and, should run it as root.



tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | perl -e '

while(<>) { chomp; next if /^[^ ]+[ ]*$/;

    if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL)/i)

    {

        if (defined $q) { print "$q\n"; }

        $q=$_;

    } else {

        $_ =~ s/^[ \t]+//; $q.=" $_";

    }

}'



리눅스상에서 웹 호출 문제를 디버깅 하고 싶을 때 웹서버 로그를 봐도 부족하고 그럴 때는 패킷을 캡쳐해서 분석할 수 있다.

If you want to debug web call problems on Linux, you may not be able to view the web server logs, and you can capture and analyze the packets in such cases.


tpcdump는 기본으로 설치가 안되어 있으니 설치를 해야 한다.

tcpdump can not be installed by default.


그리고 루트 계정으로 실행해야 한다.

and, should run it as root.



tcpdump -A -s 10240 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' | egrep --line-buffered "^........(GET |HTTP\/|POST |HEAD )|^[A-Za-z0-9-]+: " | sed -r "s/^........(GET |HTTP\/|POST |HEAD )/\n\1/g"


기본적으로 CentOS는 패키지관리자(yum)으로 프로그램을 설치하면 오래된 버전의 프로그램들이 설치되고,
When CentOS installs the program as a package manager (yum), older versions of the programs are installed.

최신 프로그램은 없는 경우가 있습니다. 그런 경우 EPEL, IUS, Remi 등의 저장소를 추가해주면 신버전의 프로그램을 설치할 수 있습니다.
And there is no latest program. In that case, you can install new versions of programs by adding repositories such as EPEL, IUS, and Remi.

하지만 별도로 설치하는 저장소의 패키지는 기존 시스템과 맞지 않을 수 있습니다. 제 경우엔 그런 문제는 없었지만.
However, the package of the repository that you install separately may not match the existing system. I did not have that problem in my case.

EPEL 저장소 설치 (Install the EPEL repository)


일반적으로 아래 명령을 실행하면 EPEL저장소를 사용하게 됩니다.

Generally, the following command will use the EPEL repository.

sudo yum install epel-release


하지만 설치가 안되는 경우 아래 명령을 참고하세요.
But if you can not install it please refer to the following command.


- CentOS and Red Hat Enterprise Linux 5.x

sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-5.noarch.rpm

- CentOS and Red Hat Enterprise Linux 6.x

sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

- CentOS and Red Hat Enterprise Linux 7.x

sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm



IUS 저장소 설치 (Install the IUS repository)


- CentOS 5.x

sudo rpm -Uvh https://centos5.iuscommunity.org/ius-release.rpm

- CentOS 6.x

sudo rpm -Uvh https://centos6.iuscommunity.org/ius-release.rpm

- CentOS 7.x

sudo rpm -Uvh https://centos7.iuscommunity.org/ius-release.rpm

- Redhat 5.x

sudo rpm -Uvh https://rhel5.iuscommunity.org/ius-release.rpm

- Redhat 6.x

sudo rpm -Uvh https://rhel6.iuscommunity.org/ius-release.rpm

- Redhat 7.x

sudo rpm -Uvh https://rhel7.iuscommunity.org/ius-release.rpm


Remi 저장소 추가 (Install the Remi repository)


- CentOS and Red Hat Enterprise Linux 5.x

sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

- CentOS and Red Hat Enterprise Linux 6.x

sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

- CentOS and Red Hat Enterprise Linux 7.x

sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm


Remi 저장소 활성화 (Enable the Remi repository)

# 패키지 설치시 파라메터로 임시로 활성화
# Temporarily activate as a parameter when installing packages

sudo yum --enablerepo=remi install [패키지명]


# 저장소 파일을 수정하여 영구적으로 활성화
# Modify the repository file to permanently activate it

vi /etc/yum.repos.d/remi.repo

enabled 값을 1로 설정.
Set the enabled value to 1


업데이트 방법.

안드로이드를 디버그 모드로 연결한다.

아래 명령으로 부트로더로 진입한다.
adb reboot bootloader

아래 URL에서 맞는 factory image를 다운받은 후
https://developers.google.com/android/nexus/images

압축을 풀고, 그 안에 있는 flash_all.sh를 실행한다.

맨처음에 뭘 unlock할거냐고 화면에 뜨는데, (oem 언락?)
Yes에다 두고 전원버튼을 한번 눌러주면 된다.


집에서 돌리고 있는 리눅스머신을 프린터 서버로 쓰려고 했는데,

프린터 서버를 세팅하던 중, CUPS에 내가 쓰고 있는 프린터(FUJI XEROX DocuPrint P205b)가 없어서 당황..

이것저것 비슷한 모델로 바꿔보고 테스트 해봤다.


일단 맥에서 다이렉트로 프린트할때는, Xerox에서 제공하는 맥용 드라이버를 쓰면 된다.

리눅스가 문제인데...


리눅스머신 USB에 연결되어 있는 프린터는 일단 인식이 됬고..


드라이버를 선택할 때 "Xerox DocuPrint P1202 - CUPS+Gutenprint v5.2.8-pre1"로 설정했고,

맥에서 프린터 추가할 때 드라이버를 Xerox에서 제공하는 드라이버로 설정하고 프린트하니 정상 동작하였다.


혹시나 다른분에게도 도움이 될까 해서 적어둔다.


나도 또 잊어먹을까봐.. 도 있고...


추가: 위에것 다 잊으시고... 여기 참조하세요: http://foo2hbpl.rkkda.com/

nc와 tar을 이용해 원격으로 폴더/파일 전체 복사하기

자꾸 헷깔려서 여기에 메모한다. 

 파일을 복사시킬 대상 서버에, 


 nc -l 4000 | tar xvf - 


 이렇게 수신 대기 시키고(4000번은 포트번호) 

 원본 서버에서는, 


 tar -cf - . | nc 192.168.0.10 4000 


 이렇게 해서 파일을 tar로 압축하며 nc로 파이프로 보낸다.


SSH로 서버 모니터링하는 스크립트 작성하는 데...

좋은 모듈이 있어 설치하려다가 python 2.7버전 윈도우용 모듈이 없어 귀찮게 빌드해야 하나 생각하는데

어떤 외쿡분이 고맙게도 미리 빌드해줘서 백업용으로 블로그에 올림.

 

paramiko라는 모듈인데 pycrypto하고도 의존성이 있음.

 

pycrypto-2.4.1.win32-py2.7.exe 

paramiko-1.7.7.1.win32_Jaraco_patch.exe

#ruby 모듈 중 httparty를 설치하려는데 오류

# sudo gem install httparty

ERROR:  Error installing httparty:
        multi_json requires RubyGems version >= 1.3.6

gems 버전이 낮다는데 help를 봐도 자기 자신을 업데이트 하는 건 없나보다.
구글링 해보니까..

# sudo gem install rubygems-update

Successfully installed rubygems-update-1.8.19
1 gem installed
Installing ri documentation for rubygems-update-1.8.19...
Installing RDoc documentation for rubygems-update-1.8.19...

이런식으로 요놈 -> rubygems-update 을 설치해주고

/var/lib/gems/(특정버전)/bin/update_rubygems

를 실행해주니 업데이트 되더라는...

 

그리고 json 모듈 설치하려니까..

# sudo gem install json

Fetching: json-1.6.5.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing json:
        ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.8 extconf.rb
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
        from extconf.rb:1


Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/json-1.6.5 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/json-1.6.5/ext/json/ext/parser/gem_make.out

이런 오류... 아 뭐야 -_-;; 에러가 직관적이지 않아!

결국 sudo apt-get install ruby1.8-dev 로 ruby1.8-dev를 설치해줘서 해결.. -_-ㅋ

보여주기만 할 휘발성 데이터를 바쁜 DB서버에서 그때그때 불러와 보여주는 건 낭비다.

그래서 그 정보들을 메모리에 넣어두고 보여주면 응답속도도 빠를 뿐 아니라 DB부하도 획기적으로 줄일 수 있다.


회사 서비스용 서버가 CentOS로 되어 있어 memcached를 설치해보았다.


1. libevent설치.

일단 memcached는 libevent라는 라이브러리를 이용한다. 먼저 설치해야 한다.

wget https://github.com/downloads/libevent/libevent/libevent-2.0.16-stable.tar.gz --no-check-certificate

tar xvzf libevent-2.0.16-stable.tar.gz

cd libevent-2.0.16-stable

./configure --prefix=/usr

make; make install 

대충 이런 과정을 거쳤다.


2. memcached 설치.

이제 설치하려던 놈을 설치한다.

 wget http://memcached.googlecode.com/files/memcached-1.4.10.tar.gz

tar xvzf memcached-1.4.10.tar.gz

cd memcached-1.4.10

./configure

make; make install


3. php 모듈 설치

회사 서비스가 php로 만들어져 있다. php에서 memcache에 접근할 수 있는 php 모듈을 설치해준다.

 wget http://pecl.php.net/get/memcache-3.0.6.tgz

tar xvzf memcache-3.0.6.tgz

cd memcache-3.0.6

phpize

./configure

make; make install

phpize명령이 실행이 안된다면, yum install php-devel명령으로 개발도구를 설치하고 다시 해본다.


다 설치가 되면 /etc/php.ini 파일을 열어 적당한 위치에 다음 라인을 추가한다.

 extension=memcache.so


이제 아파치를 재시작하고, 사용해보면 된다.

어쩌다 데비안까지 쓰게 됬다 -_-..

근데 데비안은 기본 에디터를 요상한 것으로 해놔서 자꾸자꾸 힘든상황이 ㅠㅠ

vi 에디터에 길들여진 나에게는 완전 곤욕이었다;

특히 크론 스케줄 수정할 때 ㅠㅠ


그래서!! 데비안 기본 에디터 변경하기..

# vi ~/.bashrc

export VISUAL=vi  <- 추가

# source ~/.bashrc


웰컴투 데비안..

+ Recent posts