Linux

Setting up a server on DigitalOcean (CentOS 6.7)

Contents

Set up a server for a simple messaging app I’m building with a friend. Of course I don’t really know what I’m doing. Everything comes from Google..

1. Allocate SWAP memory

https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-centos-6

1
2
3
4
5
dd if=/dev/zero of=/swapfile bs=1024 count=2048k
mkswap /swapfile
swapon /swapfile
chown root:root /swapfile
chmod 0600 /swapfile

Append the following to /etc/fstab.

1
/swapfile          swap            swap    defaults        0 0

2. Change server time to KST & install rdate

1
2
ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
yum install rdate

3. Install Java 1.7 via rpm

http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html Download the 64-bit Linux version from the link above.

1
rpm -ivh jre-7u80-linux-x64.rpm

4. Install the RabbitMQ server the same way

1
2
rpm -ivh erlang-17.4-1.el6.x86_64.rpm
rpm -ivh rabbitmq-server-3.4.4-1.noarch.rpm

Create /etc/rabbitmq/rabbitmq-env.conf and set the nodename

1
NODENAME=samplenode

Enable the management plugin & start the server

1
2
rabbitmq-plugins enable rabbitmq_management
rabbitmq-server -detached

Add a user, set id/pwd, grant permissions Reference) https://www.rabbitmq.com/man/rabbitmqctl.1.man.html#

1
2
rabbitmqctl add_user {username} {password}
rabbitmqctl set_user_tags {username} administrator

Go to http://hostname:15672/, delete the guest account in the admin menu, and add a new worker account.

5. Install Tomcat 7

Download the tar and extract it under /usr/local/.

1
ln -s apache-tomcat-7.0.57 tomcat

6. Install MariaDB

Reference: http://zetawiki.com/wiki/%EB%A6%AC%EB%88%85%EC%8A%A4_MariaDB_%EC%84%A4%EC%B9%98 Create the file below and fill it in /etc/yum.repos.d/MariaDB.repoMariaDB.repo

1
2
3
4
5
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
1
2
3
4
yum install MariaDB-server MariaDB-client

#나중에 추가됨 (기본 설정 파일 적용)
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

7. Install Apache

1
2
yum install httpd
yum install mod_ssl

8. iptables setup

Found a good article and wrote it like this. Source) http://webdir.tistory.com/170

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
# iptables 설정 자동화 스크립트
# 입맛에 따라 수정해서 사용합시다.
iptables -F

# TCP 포트 22번을 SSH 접속을 위해 허용
# 원격 접속을 위해 먼저 설정합니다
iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT

# 기본 정책을 설정합니다
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT

# localhost 접속 허용
iptables -A INPUT -i lo -j ACCEPT

# established and related 접속을 허용
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# 기타 사용하는 포트 허용
# -s xxx.xxx.xxx.xxx 를 추가 하여 특정 아이피만 가능하도록 할 수 있다.
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
iptables -A INPUT -p tcp --dport 15672 -j ACCEPT

# 설정을 저장
/sbin/service iptables save

# 설정한 내용을 출력
iptables -L -v