Openstack Swift 사용 방법



swift 로 컨테이너(container) 생성, 파일 업로드, 다운로드, 파일삭제 하는 방법에 대해서 알아보자.


▶ container 만들기 (디렉토리 개념)


[root@virtualbox ~]# swift post testdir

[root@virtualbox ~]# swift list

testdir



▶ container 삭제


[root@virtualbox ~]# swift delete testdir

testdir

[root@virtualbox ~]# swift list

[root@virtualbox ~]#



▶ 파일 업로드


[root@virtualbox ~]# swift upload testdir ./100MB.bin

100MB.bin

[root@virtualbox ~]# swift list testdir

100MB.bin



▶ 파일 다운로드


[root@virtualbox ~]# swift download testdir 100MB.bin

100MB.bin [auth 10.922s, headers 16.455s, total 62.262s, 2.042 MB/s]



container1 에 디렉토리 전체 업로드 하기


[root@virtualbox ~]# mkdir test_dir

[root@virtualbox ~]# swift post container1

[root@virtualbox ~]# dd if=/dev/zero of=./test_dir/1MB.bin bs=1M count=1

1+0 records in

1+0 records out

1048576 bytes (1.0 MB) copied, 0.00143009 s, 733 MB/s

[root@virtualbox ~]# dd if=/dev/zero of=./test_dir/2MB.bin bs=1M count=2

2+0 records in

2+0 records out

2097152 bytes (2.1 MB) copied, 0.00208392 s, 1.0 GB/s

[root@virtualbox ~]# dd if=/dev/zero of=./test_dir/3MB.bin bs=1M count=3

3+0 records in

3+0 records out

3145728 bytes (3.1 MB) copied, 0.00284061 s, 1.1 GB/s

[root@virtualbox ~]# swift upload container1 test_dir

test_dir/1MB.bin

test_dir/3MB.bin

test_dir/2MB.bin

[root@virtualbox ~]# swift download container1 test_dir/1MB.bin -o 1mb.bin

test_dir/1MB.bin [auth 5.741s, headers 6.140s, total 7.448s, 0.614 MB/s]

[root@virtualbox ~]# ll

합계 111408

-rw-r--r--. 1 root root 104857600  5월 12 15:39 100MB.bin

-rw-r--r--. 1 root root   1048576  5월 12 16:39 1mb.bin

drwxr-xr-x. 2 root root        48  5월 12 16:40 test_dir


-o 옵션을 주면 다운로드 할 때 이름을 변경해서 저장이 가능하다.


컨테이너 전체 다운로드 하기


[root@conoha ~]# swift download container1

test_dir/3MB.bin [auth 0.361s, headers 0.464s, total 0.512s, 20.908 MB/s]

test_dir/2MB.bin [auth 0.634s, headers 0.739s, total 0.768s, 15.679 MB/s]

test_dir/1MB.bin [auth 0.996s, headers 1.140s, total 1.153s, 6.667 MB/s]


컨테이너를 삭제 하면 안에 들어있는 파일도 삭제가 된다.


[root@conoha ~]# swift delete testdir

100MB.bin

testdir

[root@conoha ~]# swift delete container1

test_dir/1MB.bin

test_dir/3MB.bin

test_dir/2MB.bin

container1


swift 클라이언트 설치 방법은 여기를 https://ivps.tistory.com/47 또는 https://ivps.tistory.com/54 참고하자.


CentOS 6.x 버전은 https://itrooms.blogspot.com/2016/05/centos-6x-openstack-swift-install.html 여기를 참고하자.


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

CentOS 7.x MySQL innoDB Disable 하는 방법



CentOS 7.x 부터는 MySQL 이 MariaDB 5.5 버전 이상이다.


▶ 5.5 버전부터 innodb 를 사용안함으로 설정하는 방법


# vi /etc/my.cnf

[mysqld]

skip-innodb

default-storage-engine=MyISAM


# systemctl restart mariadb.service



▶ 5.5 미만 innodb 를 사용안함으로 설정하는 방법


# vi /etc/my.cnf

[mysqld]

skip-innodb


# service mysql restart



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

Works Mobile 기업메일 MX 레코드 맞춤URL 설정하기



Works Mobile 에 기업메일 가입하고 나면 아래의 MX레코드를 연동하라고 나온다.


MX      10      kr1-aspmx1.worksmobile.com

MX      20      kr1-aspmx2.worksmobile.com


맞춤 URL hosts.worksmobile.com


리눅스 DNS 설정에서 MX와 CNAME을 연결하는 방법에 대해서 알아보자.



Works Mobile 맞춤 URL 설정Works Mobile 맞춤 URL 설정



# vi /var/named/chroot/var/named/example.com.zone


$TTL    86400

@       IN      SOA     ns.example.com.  root (

                                        2016050609      ; serial

                                        3H              ; refresh

                                        15M             ; retry

                                        1W              ; expire

                                        1D )            ; minimum

        IN      NS              ns.example.com.

        IN      MX      10      kr1-aspmx1.worksmobile.com.

        IN      MX      20      kr1-aspmx2.worksmobile.com.

        IN      A               111.111.111.111

ns      IN      A               111.111.111.111

www     IN      A               111.111.111.111

mail    IN      CNAME           hosts.worksmobile.com.


저장 후 service named restart


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

CentOS 7.x firewalld DDOS 차단하기



이전 iptables 에서 80 포트 디도스를 막는 방법이다.


# iptables -I INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 24 -j DROP


초당 24번 이상 접속은 drop 하라는 의미이다.



firewall-cmd 에서도 iptables 를 확장하여 사용할 수가 있다.


[root@conoha ~]# firewall-cmd --permanent --direct --add-passthrough ipv4 -I INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 24 -j DROP

success

[root@conoha ~]# firewall-cmd --reload

success

[root@conoha ~]# iptables -L | grep DROP

DROP       tcp  --  anywhere             anywhere             tcp dpt:http flags:FIN,SYN,RST,ACK/SYN #conn src/32 > 24


방화벽 룰이 추가된 것을 확인할 수 있다.


이번엔 룰을 지워보자.


[root@conoha ~]# firewall-cmd --permanent --direct --remove-passthrough ipv4 -I INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 24 -j DROP

success

[root@conoha ~]# firewall-cmd --reload

success

[root@conoha ~]# iptables -L | grep DROP

[root@conoha ~]#


룰이 지워진 것을 확인하였다.



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

CentOS 7.x postfix 설정하기



postfix 가 설치가 안되어 있다면 yum install postfix 로 설치를 해주자.


# vi /etc/postfix/main.cf 파일 수정


myhostname = mail.example.com

mydomain = example.com

inet_interfaces = all


위와 같이 자신의 도메인에 맞게 값을 적고 저장



# systemctl start postfix

# systemctl enable postfix


sendmail 설정 보다는 좀 간단하다.



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

CentOS 7.x php 설치 후에 정상적으로 동작하기 위해서 설정해야 되는 부분들이다.



# vi php.ini 수정


short_open_tag = On

allow_url_fopen = Off

post_max_size = 32M

upload_max_filesize = 5M

date.timezone = Asia/Seoul

session.gc_maxlifetime = 43200


short_open_tag : On으로 설정시 <?php 로 시작하지 않아도 된다. <? 로 시작할 수가 있다.

allow_url_fopen : Off 설정으로 외부에서 url 주소로 파일을 읽어들이는 것을 막아주자.

post_max_size : default 8M 정도면 큰문제가 없어보이나 첨부파일을 여러개 첨부하게 되면 데이터가 유실된다.

upload_max_filesize : default 2M 는 너무 작은 듯하다. 사진 이미지 정도는 업로드 가능하도록 5M 정도로 올려주자.

date.timezone : Asia/Seoul 로 설정

session.gc_maxlifetime : default 1440 은 24분 뒤에 세션이 만료된다. 너무 짧다고 생각되면 12시간정도로 늘여주자.



# vi /etc/httpd/conf.d/php.conf 파일을 열어서 아래 부분 추가


AddType application/x-httpd-php .htm .html .php .php3 .php4 .inc



# systemctl restart httpd 재시작


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

리눅스 파일 ZIP 압축 비밀번호 걸기



리눅스에서 압축시 자주 사용하는 tar 명령어에는 암호를 거는 옵션이 없다.


zip 으로 패스워드를 걸어서 압축할 수가 있다. 그리고 gzip, bzip2, xz 압축 후에 비밀번호를 거는 방법에 대해서 알아보자.



사용방법은


# zip -r9P 비밀번호 압축파일명.zip 압축할대상


-r 하위폴더도 압축하는 옵션이다.

-9 압축률 옵션이다. 0 ~ 9 사이의 정수를 입력하면 된다. 9가 최대 압축이다.

-P 옵션이 패스워드


압축을 풀때는


# unzip 압축파일명.zip


비밀번호가 걸려있으면 풀기전에 물어본다.



그리고 tar 로 먼저 압축한 뒤에 zip 으로 비밀번호를 거는 방법도 있다.



▶ gzip 압축 후 zip 으로 암호걸기


# tar zcvpf 압축파일명.tar.gz 압축할대상

# zip -P 암호 -0 압축파일명.tar.gz.zip 압축파일명.tar.gz


gzip 은 zip 이랑 압축률이 비슷하다.

좀더 압축을 하려면 bzip2 나 xz 압축을 하면 된다.


▶ bzip2 압축 후 zip 으로 암호걸기


# tar jcvpf 압축파일명.tar.bz2 압축할대상

# zip -P 암호 -0 압축파일명.tar.bz2.zip 압축파일명.tar.bz2


▶ xz 압축 후 zip 으로 암호걸기


# tar Jcvpf 압축파일명.tar.xz 압축할대상

# zip -P 암호 -0 압축파일명.tar.xz.zip 압축파일명.tar.xz


잘 보면 알겠지만 옵션 하나 차이다. z, j, J


압축대상이 jpg와 같은 이미지가 많다면 gzip 이나 zip 으로 압축을 하는게 효율적이다.


텍스트 위주라면 bzip2 나 xz 압축을 하면 공간활용 측면에서 좋겠지만 압축하는데 시간이 좀 더 걸린다는 것을 감안해야 한다.



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

MySQL 유저 추가 및 삭제 스크립트



리눅스에서 계정 생성은 useradd 라는 명령어가 존재한다.


하지만 mysql은 따로 존재하지 않고 쿼리문으로 생성하거나 조금 번거롭게 추가해주어야 한다.

(create database, grant all privileges on ...)


그래서 쉘스크립트를 만들어서 사용하면 좀 더 편하게 생성 또는 삭제가 가능하다.



명령어가 어느 경로에서도 바로 사용할 수 있도록 우선 PATH 환경변수를 확인해보자.


[root@conoha bin]# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin


/root/bin 폴더가 적당하겠다.


root 에 bin 폴더가 없다면 만들고 db_user_add, db_user_del 파일을 생성하자.

[root@conoha ~]# mkdir -m700 bin

[root@conoha ~]# touch /root/bin/db_user_add

[root@conoha ~]# touch /root/bin/db_user_del

[root@conoha ~]# chmod 700 /root/bin/db_user_add

[root@conoha ~]# chmod 700 /root/bin/db_user_del


#vi /root/bin/db_user_add 아래 내용으로 저장

#!/bin/sh


ROOT_ID='root'

ROOT_PW='루트암호'


USER_ID="$1"

USER_PW="$2"


if [ "$USER_ID" == "" ] ; then

echo "Input user id : "

read USER_ID

fi


if [ "$USER_PW" == "" ] ; then

echo "Input user password : "

read USER_PW

fi


mysql -u$ROOT_ID -p$ROOT_PW mysql -e "create database $USER_ID"

mysql -u$ROOT_ID -p$ROOT_PW mysql -e "grant all privileges on $USER_ID.* to '$USER_ID'@'localhost' identified by '$USER_PW'"

mysql -u$ROOT_ID -p$ROOT_PW mysql -e "grant all privileges on $USER_ID.* to '$USER_ID'@'%' identified by '$USER_PW'"

localhost 및 외부에서도 접근이 되는 권한이다.

외부에서 접속을 허용하지 않으려면 맨아래 부분을 막아주면 된다.


#vi /root/bin/db_user_del 아래 내용으로 저장

#!/bin/sh


ROOT_ID='root'

ROOT_PW='루트암호'


USER_ID="$1"


if [ "$USER_ID" == "" ] ; then

echo "Input user id : "

read USER_ID

fi


mysql -u$ROOT_ID -p$ROOT_PW mysql -e "drop user '$USER_ID'@'%'"

mysql -u$ROOT_ID -p$ROOT_PW mysql -e "drop user '$USER_ID'@'localhost'"

mysql -u$ROOT_ID -p$ROOT_PW mysql -e "drop database $USER_ID"

유저도 삭제하고 database 도 삭제하는 명령어다.

database 를 남기려면 맨 아랫줄은 막아주면 된다.


두개의 스크립트를 생성하였으니 이제 테스트 해보면 된다.


[root@conoha ~]# db_user_add testuser password123

[root@conoha ~]# db_user_del testuser


잘 되는지 확인하여야 한다.


스크립트에서 '루트암호' 는 mysql root 비밀번호를 적어주면 된다.



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

CentOS 7.x 특정IP대역에만 특정포트허용하기



7.x 버전의 방화벽 firewall-cmd로 특정IP 대역만 특정 Port 를 허용해주는 룰 만들기 방법에 대해서 알아보자.


그리고 명령어가 너무 복잡하다고 생각되면 바로 편집을 해버리자.


[root@conoha ~]# firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="8080" accept'

success

[root@conoha ~]# firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="8081" accept'

success

[root@conoha ~]# firewall-cmd --reload

success

[root@conoha ~]# firewall-cmd --list-all

public (default, active)
  interfaces: eth0
  sources:
  services: http ssh
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks: echo-request
  rich rules:
        rule family="ipv4" source address="192.168.1.0/24" port port="8080" protocol="tcp" accept
        rule family="ipv4" source address="192.168.1.0/24" port port="8081" protocol="tcp" accept


바로 편집해서 reload 하는 방법


# vi /etc/firewalld/zones/public.xml 파일을 열어서 아래처럼 바로 편집해서 저장


<?xml version="1.0" encoding="utf-8"?>

<zone>

  <short>Public</short>

  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>

  <service name="http"/>

  <icmp-block name="echo-request"/>

  <rule family="ipv4">

    <source address="192.168.1.0/24"/>

    <port protocol="tcp" port="8080"/>

    <accept/>

  </rule>

  <rule family="ipv4">

    <source address="192.168.1.0/24"/>

    <port protocol="tcp" port="8081"/>

    <accept/>

  </rule>

</zone>


# firewall-cmd --reload 해주면 룰이 적용된다.




블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

CentOS 7.x 방화벽 ping 막기



CentOS 7.x 대로 가면서 방화벽이 iptables 에서 firewalld 로 바뀌어서 적응이 잘 안된다.


일단 외부로 부터의 ping 을 막아보자. 그리고 서비스 포트 추가 및 방법에 대해서도 알아보도록 하자.


[root@conoha log]# firewall-cmd --permanent --zone=public --add-icmp-block=echo-request

success

[root@conoha log]# firewall-cmd --reload

success

[root@conoha log]# firewall-cmd --list-all

public (default, active)

  interfaces: eth0

  sources:

  services: dhcpv6-client http ssh

  ports:

  masquerade: no

  forward-ports:

  icmp-blocks: echo-request

  rich rules:


--permanent 를 붙여야 재부팅 후에도 적용이 된다.


우선 서비스 삭제 하기


[root@conoha log]# firewall-cmd --list-all

public (default, active)

  interfaces: eth0

  sources:

  services: dhcpv6-client http l2tpd pptp ssh

  ports: 443/tcp 10022/tcp 8080/tcp

  masquerade: yes

  forward-ports:

  icmp-blocks:

  rich rules:


[root@conoha log]# firewall-cmd --permanent --remove-service=l2tpd

success

[root@conoha log]# firewall-cmd --permanent --remove-service=pptp

success

[root@conoha log]# firewall-cmd --reload

success

[root@conoha log]# firewall-cmd --list-all

public (default, active)

  interfaces: eth0

  sources:

  services: dhcpv6-client http ssh

  ports: 443/tcp 10022/tcp 8080/tcp

  masquerade: yes

  forward-ports:

  icmp-blocks:

  rich rules:


[root@conoha log]# firewall-cmd --permanent --remove-masquerade

success

[root@conoha log]# firewall-cmd --reload

success

[root@conoha log]# firewall-cmd --list-all

public (default, active)

  interfaces: eth0

  sources:

  services: dhcpv6-client http ssh

  ports: 443/tcp 10022/tcp 8080/tcp

  masquerade: no

  forward-ports:

  icmp-blocks:

  rich rules:



그리고 masquerade 도 지워봤다.


이번엔 포트 추가 및 삭제


[root@conoha log]# firewall-cmd --permanent --zone=public --add-port=10001/tcp

success

[root@conoha log]# firewall-cmd --reload

success

[root@conoha log]# firewall-cmd --list-all

public (default, active)

  interfaces: eth0

  sources:

  services: dhcpv6-client http ssh

  ports: 443/tcp 10022/tcp 8080/tcp 10001/tcp

  masquerade: no

  forward-ports:

  icmp-blocks: echo-request

  rich rules:


[root@conoha log]# firewall-cmd --permanent --zone=public --remove-port=10001/tcp

success

[root@conoha log]# firewall-cmd --reload

success

[root@conoha log]# firewall-cmd --list-all

public (default, active)

  interfaces: eth0

  sources:

  services: dhcpv6-client http ssh

  ports: 443/tcp 10022/tcp 8080/tcp

  masquerade: no

  forward-ports:

  icmp-blocks: echo-request

  rich rules:


위쪽이 추가, 아랫쪽이 삭제이다.



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,