How to Disable snap/snapd services in Ubuntu 20.04.1 LTS (& How to Uninstall/Remove snap)

The Issue
We want to disable snapd service on system startup/prevent snapd services startup automatically on system boot on Ubuntu or remove Snap completely

The Fix
1 Disable snap services
1.1 Bring up the terminal or login via SSH

1.2 E1xecute following commands to disable snap services

sudo systemctl disable snapd.service
sudo systemctl disable snapd.socket
sudo systemctl disable snapd.seeded
sudo systemctl disable snapd.snap-repair.timer

1.3 Restart the system

sudo reboot

1.4 Now the snap service will not start on system startup

2 Removing Snap

To uninstall snap (If necessary), we need to make sure snap is not used at all.

If we want to uninstall/remove snap just follow the below steps

2.1 List all snaps

snap list

2.2 If there is any installed snap pckage e.g. bashtop, remove all of them one by one

sudo snap remove bashtop

2.3 Find the snap core service directory ID

df

From the output, under the “Mounted on” column, find the ones with “/snap/core/xxxx”

2.4 Unmount the snap core service

sudo umount /snap/core/xxxx

2.5 Remove all snapd package

sudo apt purge snapd

2.6 Remove all directories (If necessary), be careful with the rm command, we will lose data if done incorrectly

rm -rf ~/snap
sudo rm -rf /snap
sudo rm -rf /var/snap
sudo rm -rf /var/lib/snapd

서버에서 주기적으로 Ping 하고 이메일 알람 전송

다음과 같은 스크립트 추가 후,

crontab 에

* * * * * 사용자 실행

추가

#!/bin/sh
HOSTS=”SERVER ADDRESS”
COUNT=1
EMAIL=”EMAIL ADDRESS”

pingtest(){
  for myhost in “$@”
  do
    echo “host ping : $HOSTS”
    ping -c “$COUNT” “$HOSTS” -w 5 && return 1
  done
  return 0
}
pingtest $HOSTS
if [ $? -eq 1 ]
then
  #echo “Everyting is fine” | mail -s “Server is OK ” $EMAIL
  echo “Everyting is fine”
else
  echo “Server ($HOSTS) Pint Test Failed at $(date)” | mail -s “Server is down from KPOPMART DB” $EMAIL
  echo “Host ($HOSTS) is down (PING failed) at $(date)”
fi

how to upgrade openssl for apache 2.2.29 – still using old 0.9.8 version

I am running a 10.04LTE server where I do want to upgrade openssl for apache.

Therefore I downloaded openssl 1.0.2c and apache 2.2.29 and compiled both. The server is starting, but is using the old ssl version:

curl --head http://localhost
HTTP/1.1 200 OK
Date: Mon, 22 Jun 2015 06:00:06 GMT
Server: Apache/2.2.29 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8k
Last-Modified: Sun, 18 Mar 2012 19:56:07 GMT

However, Openssl is installed in new version:

/usr/local/ssl/bin/openssl version
OpenSSL 1.0.2c 12 Jun 2015

While the original version stayes in place:

openssl version
OpenSSL 0.9.8k 25 Mar 2009

I compiled apache with:

./configure --with-included-apr --prefix=/usr/local/apache2 --enable-so     
--enable-rewrite --with-ssl=/usr/local/ssl --enable-ssl=shared
--enable-deflate --enable-expires --enable-headers 

Apache did not start before I included:

LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so

According to the mod ssl website this is only available for apache 1.x

Not sure what is going wrong here. Thank you for any help!

1 Answer
1

The problem is that your Apache installation is unable to link the shared libraries of your new OpenSSL installation. Run the command ldd /usr/local/apache/modules/mod_ssl.so (with the apporpriate path to your mod_ssl.so). You’ll see that mod_ssl.so is not linking to the libraries in /usr/local/ssl/lib

You have a couple options to fix the problem:

Option #1 – Link in the libraries:

Open /etc/ld.so.conf.d/local.conf for editing and add the following line: /usr/local/openssl/lib

Re-compile Apache (remember to make clean) and it should work.

If that doesn’t work. You could also try specifying LDFLAGS directly with your configure command:

LDFLAGS=-L/usr/local/ssl/lib \ ./configure --with-included-apr --prefix=/usr/local/apache2 --enable-so     
--enable-rewrite --with-ssl=/usr/local/ssl --enable-ssl=shared
--enable-deflate --enable-expires --enable-headers

Option #2 – Upgrade the system OpenSSL:

Re-install OpenSSL with the config line ./config --prefix=/usr --openssldir=/usr/local/openssl shared

When the prefix is not specified in your config line, the OpenSSL installer will default to /usr/local/ssl.

Quick install instructions:

cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.0.2-latest.tar.gz
tar -zxf openssl-1.0.2*
cd openssl-1.0.2*
./config --prefix=/usr --openssldir=/usr/local/openssl shared
make
make test
make install

아파치 SSL 로 구동시 키 비밀번호 없애기 – Some of your private key files are encrypted for security reasons.

SSL 인증서 생성시 인증키 값을 넣을경우
아파치 구동시 키 비밀번호를 입력하지 않으면 구동되지 않는다.



Apache/2.2.13 mod_ssl/2.2.13 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.


Server test.com:443: (RSA)
Enter pass phrase:



서버를 관리하는 입장에서는 비밀번호를 입력하지 않고 자동으로 웹서버를
구동하여야할때가 있다.
 
인증서 생성시 이미 넣어버린 키는 아래와 같이 하면 간단하게 없앨 수 있다.
단, 당연한 이야기지만 기존 비밀번호는 알고있어야한다.-.-;


cp server.key server.key.org
openssl rsa -in server.key.org -out server.key

다시 아파치를 restart 해본다.

Apache SSL 인증서 설치 / 적용 가이드

원문 : https://www.securesign.kr/guides/Apache-SSL-Certificate-Install

사전 구성 환경

  • OpenSSL 라이브러리 http://www.openssl.org/ : openssl 1.0.1 이상 권장
  • Apache w/mod_ssl http://www.modssl.org/ : http.conf 에서 mod_ssl 모듈 활성화 (LoadModule ssl_module modules/mod_ssl.so)
  • TLS / SHA-2(sha256) 암호화 지원 모듈 구성/활성 확인 필수
  • MD5, RC4 등 국제 보안 기구에서 해제를 권장하는 취약한 암호화 모듈 비활성화
  • SSL 2.0, 3.0 및 TLS 1.0 1.1 프로토콜 접속 허용 해제. 최신 TLS 1.2 1.3 설정 권장

진행 과정

  1. 개인키(Private Key) 생성
  2. CSR(Certificate Signing Request) 생성
  3. 인증서 발급 신청 제출
  4. 인증서 발급 완료 (발급내역서/파일설명서 PDF 참조)
  5. 인증서 설치 적용 – 신규,갱신,재발급,도메인추가
  6. 서버 정상 적용 완료 테스트
  7. 웹페이지에 https:// 링크 적용

개인키(Private Key) 생성


– SSL 인증서 발급 신청서 작성시, CSR 입력 단계에서 온라인 “CSR 자동생성” 이용을 권장합니다. (현재 과정 필요 없음)
– CSR 자동생성 발급 완료시, “개인키, 서버인증서, 체인인증서, 루트인증서” PEM 파일이 모두 포함되어 있습니다.
– 추가 포함된 “pfx / jks” 패키지에는, “개인키+서버인증서+체인인증서+루트인증서” 가 모두 통합되어 있습니다.
openssl genrsa -des3 -out private.key 2048
  • -des3 : 개인키 암호화 수준 DES3 (Windows Apache 환경은 해당 옵션 제외)
  • -out private.key : 개인키를 저장할 파일명 지정. 개인키 파일은 분실하지 않도록 잘 보관해야 합니다.
  • 2048 : bit

Result


Loading ‘screen’ into random state – done
Generating RSA private key, 2048 bit long modulus
……………………..+++
……………………………………………..
…………………+++
e is 65537 (0x10001)
Enter pass phrase for pri.kery: (개인키 파일 암호 입력)
Verifying – Enter pass phrase for pri.kery: (개인키 파일 암호 입력)

CSR(Certificate Signing Request) 생성 예


– SSL 인증서 발급 신청서 작성시, CSR 입력 단계에서 온라인 “CSR 자동생성” 이용을 권장합니다. (현재 과정 필요 없음)
– CSR 자동생성 발급 완료시, “개인키, 서버인증서, 체인인증서, 루트인증서” PEM 파일이 모두 포함되어 있습니다.
– 추가 포함된 “pfx / jks” 패키지에는, “개인키+서버인증서+체인인증서+루트인증서” 가 모두 통합되어 있습니다.
openssl req -new -key private.key -out out.csr -config “../share/openssl.cnf”


또는
openssl req -new -key private.key -out out.csr -subj “/C=KR/ST=Seoul/L=Gang-nam/O=SecureSign.KR/OU=Dev Team/CN=example.com”
  • -key private.key : 앞서 생성한 개인키 파일 지정
  • -outout.csr : 생성될 CSR 파일명 지정
  • -config “../share/openssl.cnf” : cnf 위치를 확인하지 못하는 경우 cnf 파일 경로 지정
  • -subj : CSR 생성시 입력이 필요한 정보 지정
    • C : ISO 국가 코드 KR, US, CN, JP (대문자)
    • ST : 시,도
    • L : 구,군
    • O : 기관명, 회사명
    • OU : 조직명
    • CN : 도메인명, 일반이름. IP 주소는 CN 으로 사용할수 없습니다.
    • 위 항목은 모두 영문입력을 해야 합니다. 특수문자를 사용하면 안됩니다.

  • (예제에 사용된 옵션 값 등은 예제용이므로, 실제 해당 도메인 정보로 지정하시기 바랍니다)

Single

CN : sub.example.com 처럼 FQDN 도메인 형식 이어야 합니다.

Wildcard

CN : *.example.com 과 같은 패턴 이어야 합니다.

MultiDomain

CN : example.com 대표성을 가진 FQDN 도메인 1개만 입력 합니다.
SAN : 인증서에 포함될 나머지 FQDN 도메인은, 신청서 작성중 DCV 설정 단계에서 추가 입력합니다.

Multi-Wildcard

CN : example.com 대표 루트 도메인 1개을 CN으로 입력 합니다.
SAN : *.example.com 형식의 와일드카드 도메인은, 신청서 작성중 DCV 설정 단계에서 추가 입력합니다.

Result


Enter pass phrase for pri.kery: (개인키 패스워드 입력)
Loading ‘screen’ into random state – done
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 (국가코드 C)
State or Province Name (full name) [Some-State]:Seoul (시,도 ST)
Locality Name (eg, city) []:Gang-nam (구,군 L)
Organization Name (eg, company) [Internet Widgits Pty Ltd]:SecureSign.KR (기관명 O)
Organizational Unit Name (eg, section) []:Dev Team (조직명 OU)
Common Name (eg, YOUR name) []:example.com (도메인명 CN)
Email Address []:webmaster@example.com (이메일)

Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []: enter (설정 X)
An optional company name []: enter (설정 X)

생성된 CSR 예제


– SSL 인증서 발급 신청서 작성시, CSR 입력 단계에서 온라인 “CSR 자동생성” 이용을 권장합니다. (현재 과정 필요 없음)
– CSR 자동생성 발급 완료시, “개인키, 서버인증서, 체인인증서, 루트인증서” PEM 파일이 모두 포함되어 있습니다.
– 추가 포함된 “pfx / jks” 패키지에는, “개인키+서버인증서+체인인증서+루트인증서” 가 모두 통합되어 있습니다.
-----BEGIN CERTIFICATE REQUEST-----
MIIC5TCCAc0CAQAwgZ8xCzAJBgNVBAYTAktSMQ4wDAYDVQQIEwVTZW91bDERMA8G
A1UEBxMIR2FuZy1uYW0xGDAWBgNVBAoTD1NlY3VyZUxheWVyIEluYzERMA8GA1UE
-- 중략 --
wxd+87gwsvAC2dyK8I4N1ttXDRJcDPCDe1BGqWvYYAZN7FbvnbHCM7y/SN++pxbS
jbnkoe8uStQvfCo6DW5MZHUli5+lRU/UpA==
-----END CERTIFICATE REQUEST-----

앞서 생성한 CSR 파일은 Base64 포맷의 PEM Text 이며, 텍스트 편집기를 이용하여 파일을 오픈합니다. -----BEGIN ~ REQUEST----- 까지 포함하여 내용 전체를 복사하여 신청서에 입력합니다. (—– 를 누락하거나, 새로운 빈출이 추가되지 않도록 주의하세요)

인증서 발급 완료 및 참고 사항

– 발급 완료 후에는, 메일첨부 또는 주문상세의 압축파일(zip)에 인증서 파일이 포함되어 있습니다.
– 서버 적용에 필요한 파일들에 대해서, 발급 내역서 PDF 및 루트/체인 설명 PDF를 통해서 미리 숙지해야 합니다.
– 이후 과정 부터는, 서버에 SSL 인증서 설치/적용/확인 절차 입니다. (인터넷에 공개된 설정법과 차이 없음)

– 서버이름표시(SNI) 지원되는 서버의 경우, SSL 인증서 마다 각 포트 구분없이 모두 443 포트 적용가능합니다.
– SNI 설정으로 하는 경우, 클라이언트에서 SNI 미지원 하는 경우 접속 호환성 문제가 있으므로 미리 검토해야 합니다.

VirtualHost 적용 예제 (서버 인증서 발급 받은 후)

<VirtualHost *:443>

ServerName “아래 지정한 서버 인증서에 포함된 DNS Name 중에 있어야 함 ”
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3 또는 TLSv1 TLSv1.1 TLSv1.2 (서버 환경에 따라서 선택적 적용)
SSLCertificateKeyFile /인증서파일경로/개인키 ex. domain_xxxxx.key.pem
SSLCertificateFile /인증서파일경로/서버인증서 ex. domain_xxxxx.crt.pem
SSLCertificateChainFile /인증서파일경로/체인인증서ex. chain-bundle.pem
SSLCACertificateFile /인증서파일경로/루트인증서 ex. AAACertificateServicesRoot.crt.pem

</VirtualHost>

* 루트/체인 인증서는 상품별로 차이가 있으므로, 발급 완료시 첨부된 파일 내역에서 확인 가능합니다.
* chain-bundle.pem 은 체인인증서가 여러개인 경우 1개 파일로 통합한 PEM Text 파일입니다.
* CSR 자동 생성 이용시, 개인키에는 패스워드가 지정되지 않습니다. (별도 지정 필요시 변환 매뉴얼 참조)
* 예제에 포함되어 있지 않은 나머지 Property 는 공식 매뉴얼 또는 현재 서버 설정값을 사용하시기 바랍니다. (/conf/extra/httpd-ssl.conf 참조)

VirtualHost 적용 예제 – Apache 2.4.8 + (서버 인증서 발급 받은 후)

<VirtualHost *:443>

ServerName “아래 지정한 서버 인증서에 포함된 DNS Name 중에 있어야 함 ”
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3 또는 TLSv1 TLSv1.1 TLSv1.2 (서버 환경에 따라서 선택적 적용)
SSLCertificateKeyFile /인증서파일경로/개인키 ex. domain_xxxxx.key.pem
SSLCertificateFile /인증서파일경로/서버+체인 PEM 통합된 파일 ex. domain_unified.pem
SSLCACertificateFile /인증서파일경로/루트인증서 ex. AAACertificateServicesRoot.crt.pem

</VirtualHost>

* 루트/체인 인증서는 상품별로 차이가 있으므로, 발급 완료시 첨부된 파일 내역에서 확인 가능합니다.
* 통합 pem 파일 생성 : cat domain_xxxxx.crt.pem chain-bundle.pem > unified.domain.pem (cat, type 명령어 사용)
* 통합된 domain_unified.pem 파일을 Text 편집기로 열어서, PEM 내용간 구분되어 있는지 꼭 확인해야 합니다.
* CSR 자동 생성 이용시, 개인키에는 패스워드가 지정되지 않습니다. (별도 지정 필요시 변환 매뉴얼 참조)
* 예제에 포함되어 있지 않은 나머지 Property 는 공식 매뉴얼 또는 현재 서버 설정값을 사용하시기 바랍니다. (/conf/extra/httpd-ssl.conf 참조)

설치 적용 확인 및 변환

* 서버에 SSL 설정 적용 후, 웹서버를 재시작하여 시작시 오류 또는 경고가 있는지 콘솔/데몬 로그를 필히 확인해야 합니다. (필수 확인 사항)
* SSL 발급 도메인 웹페이지에 https:// 링크 적용을 별도 진행해야 최종적으로 SSL 암호화가 적용됩니다. (개발자,웹디자이너)
* PC 및 스마트폰의 “Chrome / Firefox / IE / Edge” 각 웹브라우져에서 “루트,체인,SSL,TLS” 경고가 발생 하는지 확인해야 합니다.

SSL 설치/적용 트러블슈팅
SSL 설치 적용 확인 하기
체인인증서 적용 확인 방법
인증서 포맷 변환 방법
TrustLogo 적용 방법

리눅스 파일 검색/찾기, 파일 내부 문자열 찾기/검색

# 리눅스 파일명으로 검색하는법.

사용법

find [찾을위치] -name [파일명]

예) 최상위 폴더부터 하위로 ‘apache’로 시작하는 파일 찾기.

find / -name ‘apache*’

예) usr 폴더부터 하위로 ‘apa’로 시작하는 파일 찾기.

find /usr/ -name ‘apa*’

 

# 리눅스 파일 내부 문자열 검색하는법.

grep 을 이럴때 유용하게 쓸 수 있습니다.

사용법

grep -r [찾을 문자열] [대상파일들]

예) 현재 폴더에 있는 test.log 파일내부에 ‘apache’ 라는 문자열 찾기.

grep -r ‘apache’ ./test.log

예) ‘var’ 폴더부터 하위 모든 파일내부에서 ‘apache’ 라는 문자열 찾기.

grep -r ‘apache’ /var/* [–include ‘*.conf’] (include 옵션으로 특정 확장자에서만 검색도 가능하다)

 

# 파일 내부 문자열 검색 다른 방법 (Feat. 강조색)

find . -type f -print | xargs grep -i “phpMyAdmin” /dev/null

현재위치부터 하위폴더의 모든 파일중에서 ‘phpMyAdmin’ 이라는 문자열을 검색한다.

find . -name ‘*.conf’ | xargs grep -r –color=auto -n 2>dev/null ‘phpMyAdmin’

현재 부터 하위 모두를 검색하되,

conf 라는 확장자를 가진 파일중에서 ‘phpMyAdmin’ 이라는 문자열을 검색한다.

그리고 일치 문자열은 강조색으로 표시!

How do I enable core dumps for everybody (모든 사용자 계정에 core dump 파일 활성화 하기)

Overview

In most Linux Distributions core file creation is disabled by default for a normal user. However, it can be necessary to enable this feature for an application (e.g. Oracle). For example, if you encounter an ORA-7445 error in Oracle, then it must be possible to write a core file for the user«oracle».

To enable writing core files you use the ulimit command, it controls the resources available to a process started by the shell, on systems that allow such control.

If you try to enable writing core files, usually you run in the following problem. Normally SSH is used to logon to the server.

ssh oracle@ora-server
$ ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
pending signals                 (-i) 1024
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65536
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 16384
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Nowtry (not as user root) to change the core file size to unlimited

ulimit -c unlimited
-bash: ulimit: core file size: cannot modify limit: Operation not permitted

Solution

  1. Check Environment for ulimit

    The first step is to check, that you don’t set ulimit -c 0 in any shell configuration files for this user, for example in $HOME/.bash_profile or $HOME/.bashrc. Uncomment it if you have such an entry.

    #
    # Do not produce core dumps
    #
    # ulimit -c 0
     

  2. Globally enable Core Dumps

    This must be done as user root, usually in /etc/security/limits.conf

    # /etc/security/limits.conf
    #
    #
     Each line describes a limit for a user in the form:
    #
    #
     <domain> <type> <item> <value>
    #

    *  soft  core  unlimited

     

  3. Logoff and Logon again and set ulimit

    ssh oracle@ora-server
    $ ulimit -c
    0

    Try to set the limit as user root first

    su –
    ulimit -c unlimited

    ulimit -c
    unlimited

    Now you can set ulimit also for user oracle

    su – oracle
    ulimit -c unlimited
    ulimit -c
    unlimited

Perhaps the last step number 3 is not necessary, but we have figured out, that this is the way which always work. The core file size limitation is usually also set in different configuration files. If you want to enable cores, you can uncomment them.

In /etc/profile (Redhat)

# No core files by default
# ulimit -S -c 0 > /dev/null 2>&1

In /etc/init.d/functions (Redhat)

# make sure it doesn’t core dump anywhere unless requested
# ulimit -S -c ${DAEMON_COREFILE_LIMIT:-0} >/dev/null 2>&1

Now, from this current shell you can generate the core, so check ulimit before.

$ ulimit -a

core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
pending signals                 (-i) 1024
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65536
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 16384
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

lsyncd + rsync로 디렉토리 실시간 백업하기

lsyncd + rsync로 디렉토리 거의 실시간 백업하기
실시간 동기화 라고 할 수도 있지만.. 실제로는 원본 디렉토리에 파일이 생성된 직후 rsync가 실행되어 백업 서버로 동기화 하기 때문에 파일이 copy되는 동안의 시간차 발생함.
1. rsync 설치, 설치 확인 (백업서버)
[root@vm2 sdir]# yum install rsync
[root@vm2 sdir]# rpm -qa | grep rsync
rsync-3.0.6-4.el5_7.1
2. rsync 활성화 (백업서버)
[root@vm2 data]# vi /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = –daemon
log_on_failure += USERID
}
3. rsyncd.conf 설정 (백업서버)
[root@vm2 data]# vi /etc/rsyncd.conf
[data_sync]
path=/data/sdir <– 접근을 허용할 디렉토리(백업디렉토리)
hosts allow=192.168.122.20 <– 접근을 허용할 서버 IP, 여러대를 동기화 할 경우 , 로 IP 추가
uid=0
gid=0
use chroot=yes
read only=no
[root@vm2 data]# mkdir /data/sdir
[root@vm2 data]#
[root@vm2 data]# /etc/init.d/xinetd restart
xinetd 를 정지 중: [ OK ]
xinetd (을)를 시작 중: [ OK ]
[root@vm1 data]#
4. lsyncd 설치 (원본서버)
[root@vm1 yum.repos.d]# yum install lsyncd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.daum.net
* extras: ftp.daum.net
* rpmforge: ftp.riken.jp
* updates: ftp.daum.net
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package lsyncd.i386 0:2.0.4-1.el5.rf set to be updated
–> Processing Dependency: lua for package: lsyncd
–> Running transaction check
—> Package lua.i386 0:5.1.4-2.el5.rf set to be updated
–> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================
Installing:
lsyncd i386 2.0.4-1.el5.rf rpmforge 149 k
Installing for dependencies:
lua i386 5.1.4-2.el5.rf rpmforge 242 k
Transaction Summary
====================================================================================================================================
Install 2 Package(s)
Upgrade 0 Package(s)
Total download size: 391 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): lsyncd-2.0.4-1.el5.rf.i386.rpm | 149 kB 00:00
(2/2): lua-5.1.4-2.el5.rf.i386.rpm | 242 kB 00:00
————————————————————————————————————————————
Total 243 kB/s | 391 kB 00:01
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : lua 1/2
Installing : lsyncd 2/2
Installed:
lsyncd.i386 0:2.0.4-1.el5.rf
Dependency Installed:
lua.i386 0:5.1.4-2.el5.rf
Complete!
[root@vm1 yum.repos.d]#
– yum 으로 실치가 불가능할 경우 아래와 같이 rpmforge의 레포지터리를 추가하거나, rpm 파일을 다운로드 받아서 설치
[root@vm1 yum.repos.d]# cat /etc/yum.repos.d/rpmforge.repo
[rpmforge]
name = Red Hat Enterprise $releasever – RPMforge.net – dag
#baseurl = http://apt.sw.be/redhat/el5/en/$basearch/dag
mirrorlist = http://apt.sw.be/redhat/el5/en/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 1
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 0
5. lsyncd.conf 파일 생성 (원본서버)
settings = {
logfile = “/var/log/lsyncd.log”, <– 로그파일 경로 설정
statusFile = “/var/log/lsyncd-status.log”, <– lsyncd 상태 로그 경로
delay = 1,
}
sync{
default.rsync,
source= “/data/sdir”, <– 동기화 할 원본 디렉토리
rsyncOpts= “-avz”,
target= “192.168.122.184::data_sync” <– backup 경로, rsyncd.conf 파일에 지정된 서비스명
}
sync{
default.rsync,
source= “/data/sdir”, <– 동기화 할 원본 디렉토리
rsyncOpts= “-avz”,
target= “192.168.122.150::data_sync”, <– backup 경로, rsyncd.conf 파일에 지정된 서비스명
}
==============================================
– 백업서버가 2EA 이상일 경우, 아래와 같은 형식으로 작성해도 됨.
[root@vm1 sdir]# cat /etc/lsyncd.conf
settings = {
logfile = “/var/log/lsyncd.log”, <– 로그파일 경로 설정
statusFile = “/var/log/lsyncd-status.log”, <– lsyncd 상태 로그 경로
delay = 1,
}
targetlist = {
“192.168.122.184::data_sync”, <– backup 경로, rsyncd.conf 파일에 지정된 서비스명
“192.168.122.150::data_sync” <– backup 경로, rsyncd.conf 파일에 지정된 서비스명
}
for _, server in ipairs(targetlist) do
sync{ default.rsync,
source=”/data/sdir/”, <– 동기화 할 원본 디렉토리
target=server,
rsyncOpts= “-avz”,
}
end
6. lsyncd 데몬 실행 (원본서버)
[root@vm1 sdir]# /etc/init.d/lsyncd restart
lsyncd (을)를 시작 중: [ OK ]
7. 동기화 테스트
– 원본 서버의 source 디렉토리(/data/sdir) 에서 파일을 생성/삭제하면서, 백업서버의 target 디렉토리가 정상적으로 동기화 되는지 확인
8. 여러대의 서버를 서로 상호간 동기화 설정을 하기 위해서는
– 원본 서버에 백업서버와 동일하게 rsyncd.conf 파일을 생성하여 백업서버에서 접근이 가능하도록 설정
– 백업서버에 원본과 동일하게 lsyncd를 실행하고 백업 디렉토리에 생성/삭제된 파일이 원본서버로 동기화 되도록 설정

How to install asterisk and freepbx on ubuntu 16.04

출처 : https://schooloffreelancing.blogspot.com/2017/11/asterisk-freepbx-install-into-ubuntu.html

apt-get -y autoremove
apt-get -y update
apt-get -y upgrade
# Some Utils
apt-get install -y curl vim-nox
# PJSIP
apt-get install -y make gcc g++ binutils sudo git
cd /usr/src
git clone https://github.com/asterisk/pjproject.git
cd /usr/src/pjproject
CFLAGS=’-DPJ_HAS_IPV6=1′ ./configure –prefix=/usr –enable-shared –disable-sound –disable-resample –disable-video –disable-opencore-amr
make dep 
make
make install
ldconfig
ldconfig -p | grep pj
# Asterisk 13
apt-get install -y libtool pkg-config libnewt-dev subversion
apt-get install -y libncurses5-dev uuid-dev libjansson-dev libxml2-dev libsqlite3-dev
apt-get install -y libmysqlclient-dev 
apt-get install -y unixodbc-dev libmyodbc
apt-get install -y libssl-dev libcurl4-openssl-dev libgnutls28-dev libsrtp0-dev
apt-get install -y bison flex
apt-get install -y sox lame flac mpg123 libmpg123-dev libogg-dev libvorbis-dev libspeex-dev libspeexdsp-dev libasound2-dev
apt-get install -y libiksemel-dev libiksemel-utils 
apt-get install -y libspandsp-dev
apt-get install -y libical-dev libneon27-dev 
cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-13-current.tar.gz
tar zxvf asterisk-13-current.tar.gz
cd asterisk-*
# contrib/scripts/install_prereq install
contrib/scripts/get_mp3_source.sh
./configure
make menuselect.makeopts
menuselect/menuselect –enable-category MENUSELECT_ADDONS menuselect.makeopts
menuselect/menuselect –enable CORE-SOUNDS-EN-GSM –enable MOH-OPSOUND-WAV –enable EXTRA-SOUNDS-EN-GSM –enable cdr_mysql menuselect.makeopts
menuselect/menuselect –disable app_mysql –disable app_setcallerid –disable func_audiohookinherit menuselect.makeopts
make
make install
make config
make samples
ldconfig
ldconfig -p | grep asterisk
systemctl disable asterisk.service
cd /var/lib/asterisk/sounds
wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-core-sounds-en-wav-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-extra-sounds-en-wav-current.tar.gz
tar xvf asterisk-core-sounds-en-wav-current.tar.gz
rm -f asterisk-core-sounds-en-wav-current.tar.gz
tar xfz asterisk-extra-sounds-en-wav-current.tar.gz
rm -f asterisk-extra-sounds-en-wav-current.tar.gz
# Wideband Audio download 
wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-core-sounds-en-g722-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-extra-sounds-en-g722-current.tar.gz
tar xfz asterisk-extra-sounds-en-g722-current.tar.gz
rm -f asterisk-extra-sounds-en-g722-current.tar.gz
tar xfz asterisk-core-sounds-en-g722-current.tar.gz
rm -f asterisk-core-sounds-en-g722-current.tar.gz
useradd -m asterisk
chown asterisk. /var/run/asterisk
chown -R asterisk. /etc/asterisk
chown -R asterisk. /var/{lib,log,spool}/asterisk
chown -R asterisk. /usr/lib/asterisk
# FreePBX 13
export DEBIAN_FRONTEND=noninteractive
apt-get install -y apache2 mysql-server mysql-client php5 php5-curl php5-cli php5-mysql php5-gd php-pear unixodbc
rm /var/www/html/index.html
sed -i ‘s/\(^upload_max_filesize = \).*/\120M/’ /etc/php5/apache2/php.ini
cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf_orig
sed -i ‘s/^\(User\|Group\).*/\1 asterisk/’ /etc/apache2/apache2.conf
sed -i ‘s/AllowOverride None/AllowOverride All/’ /etc/apache2/apache2.conf
service apache2 restart
cat >> /etc/odbcinst.ini << EOF
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
FileUsage = 1
 
EOF
cat >> /etc/odbc.ini << EOF
[MySQL-asteriskcdrdb]
Description=MySQL connection to ‘asteriskcdrdb’ database
driver=MySQL
server=localhost
database=asteriskcdrdb
Port=3306
Socket=/var/run/mysqld/mysqld.sock
option=3
 
EOF
cd /usr/src
wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-13.0-latest.tgz
tar vxfz freepbx-13.0-latest.tgz
rm -f freepbx-13.0-latest.tgz
cd /usr/src/freepbx
rm /etc/asterisk/*.conf
./start_asterisk start
./install -n
cat >> /etc/systemd/system/freepbx.service << EOF
[Unit]
Description=FreePBX VoIP Server
After=mysql.service
 
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/fwconsole start
ExecStop=/usr/sbin/fwconsole stop
 
[Install]
WantedBy=multi-user.target
 
EOF
systemctl enable freepbx.service
systemctl start freepbx.service
systemctl status freepbx.service
fwconsole chown
fwconsole reload
fwconsole moduleadmin installall
fwconsole moduleadmin upgradeall
fwconsole chown
fwconsole reload
fwconsole moduleadmin uninstall dahdiconfig
fwconsole moduleadmin delete dahdiconfig
fwconsole moduleadmin uninstall sipstation
fwconsole moduleadmin delete sipstation
fwconsole moduleadmin uninstall digium_phones
fwconsole moduleadmin delete digium_phones
fwconsole moduleadmin uninstall cxpanel
fwconsole moduleadmin delete cxpanel
fwconsole moduleadmin uninstall firewall
fwconsole moduleadmin delete firewall
fwconsole moduleadmin upgradeall
fwconsole chown
fwconsole reload
fwconsole chown

MySQL 외부 접속 (root / user) 가능하도록 설정

원격 접속 가능한 호스트 및 사용자 확인

[root@company bin]# mysql uroot p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 561388
Server version: 5.0.51log Source distribution
 
 
 
mysql> select HOST, USER, Password FROM mysql.user;
+—————–+——-+——————————————-+
| HOST            | USER  | Password                                  |
+—————–+——-+——————————————-+
| localhost       | root  | *(생략)                           | 
| company         | root  |                                           | 
| 127.0.0.1       | root  |                                           | 
| localhost       |       |                                           | 
| company         |       |                                           | 
| localhost       | news  | *(생략)                                | 
| 211.200.200.200 | news  | (생략)                                     | 
| 100.200.100.100 | news  | (생략)                                      | 
| 192.168.100.110 | news  | (생략)                                      | 
+—————–+——-+——————————————-+
 
9 rows in set (0.02 sec)

위 경우 HOST에 명시된 호스트에서만 접속 가능.

따라서 사용자 추가.

mysql> show databases;
+——————–+
| Database           |
+——————–+
| information_schema | 
| mysql              | 
| company            | 
+——————–+
3 rows in set (0.01 sec)
 
mysql> use mysql
Database changed
 
mysql> insert into user (host,user,password) 
values(‘%’,‘news’,password(‘newspasswd’));
Query OK, 0 rows affected (0.02 sec)
 
mysql> GRANT all privileges on *.* to ‘news’@‘%’ 
identified by ‘newspasswd’ ;
Query OK, 0 rows affected (0.02 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
 
 
mysql> select HOST, USER, Password FROM mysql.user;
+—————–+——-+——————————————-+
| HOST            | USER  | Password                                  |
+—————–+——-+——————————————-+
| localhost       | root  | *7540F67EE4(생략)                         | 
| company         | root  |                                           | 
| 127.0.0.1       | root  |                                           | 
| localhost       |       |                                           | 
| company         |       |                                           | 
| localhost       | news  | *7540F67EE4                               | 
| 211.200.200.200 | news  | 49d7                                      | 
| 100.200.100.100 | news  | 49d7                                      | 
| 192.168.100.110 | news  | 49d7                                      | 
| %  | news  | *7540F67EE4                               | 
+—————–+——-+——————————————-+
10 rows in set (0.02 sec)
 


단 MySQL 5.7에서는 Insert 명령어를 아래와 같이 변경해야 함.
insert into user(host,user,authentication_string,ssl_cipher,x509_issuer,x509_subject) values (‘%’, ‘news’, password(‘password’),”,”,”);


호스트를 %로 할경우 어떤 호스트에서든 접속 가능.

이렇게 하고도… 외부에서 접속이 안될 경우

1. OS 방화벽 (리눅스 방화벽 확인 ) 해제 – ufw disable
2. MySQL 설정 파일 “my.cnf” (mysqld.cnf) 에, bind-address=127.0.0.1 로 되어 있는 것을 “0.0.0.0” 으로 변경 후, 
3. MySQL 재시작