os/Ubuntu

ubuntu server install 후 설정

C/H 2012. 11. 22. 07:34
ubuntu server install 후 설정

ubuntu ufw(uncomplicated firewall) 설정

Root 원격 로그인 금지

vi /etc/ssh/sshd_confg
PermitRoogLogin no
/etc/init.d/ssh restart


* 사용자 추가
sudo useradd -b /home -s /bin/bash -m -p 비밀번호 사용자아이디

* Sudoers

1. 새로운 sudo 사용자 추가
sudo useradd -n -d /home/userid -G admin userid
sudo passwd userid

-n : 새로운 계정 추가 옵션
-d : 계정의 디렉토리 설정
-G : 계정이 속하는 그룹 옵션
userid : 계정 아이디
2. /etc/group 에서 userid를 admin 그룹에 추가
sudo vi /etc/group

...
admin:x:115:admin1,userid
3. CentOS Sudores 추가
 vi /etc/sudoers 

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
userid   ALL=(ALL)       ALL            # 사용자 추가

# 패스워드 물어보지 않게 하기
## Same thing without a password
%wheel  ALL=(ALL)       NOPASSWD: ALL		# 주석 제거
:wq # 저장

# wheel 그룹에 sudo 사용자 추가
vi /etc/group

...
wheel:x:10:root,userid		# sudo 사용할 userid 추가
...
userid:500:

:wq # 저장

* Dotdeb 저장수 추가 // 2013.01.22

sudo vi /etc/apt/sources.list
deb http://packages.dotdeb.org squeeze all
deb-src http://packages.dotdeb.org squeeze all

// apt-key add
wget http://www.dotdeb.org/dotdeb.gpg
sudo cat dotdeb.gpg | sudo apt-key add -

// update
sudo apt-get update && sudo apt-get upgrade

* dotdeb를 이용해 php를 업그레이드시에 문제가 생길 수 있음.

# 2013.10.17
sudo add-apt-repository ppa:ondrej/php5
sudo apt-get update
sudo apt-get upgrade
# If you don't have add-apt-repository binary do the following:
sudo apt-get install python-software-properties


* ufw 설치 설정

sudo ufw allow in 80,443/tcp
sudo ufw allow in 3690/tcp
# sudo ufw delete allow 80,443/tcp # 삭제
# sudo ufw delete allow out 80,443/tcp # 삭제
# sudo ufw allow in http
# sudo ufw allow in https
sudo ufw allow from xxx.xxx.xxx.xxx to any port 22
sudo ufw allow from xxx.xxx.xxx.1/24 to any port 22
sudo ufw allow out 53,137,138/udp
sudo ufw allow out 3690/tcp
sudo ufw delete allow out 3690/tcp # 삭제
sudo ufw allow out 22,80,443,5900,8001/tcp
sudo ufw allow out ntp
sudo ufw delete deny out to any
sudo ufw deny out any
# sudo ufw deny out any 가 항상 마지막에 있도록 설정
sudo ufw status numbered



* 수정

sudo ufw delete allow out 53,137,138/udp
sudo ufw allow out 53,123,137,138/udp

* 숫자 라벨링으로 삭제

sudo ufw status numbered
[ 1] 80,443/tcp                 ALLOW IN    Anywhere
[ 2] 3690/tcp                   ALLOW IN    Anywhere
[ 3] 22,80,443,5900,8001/tcp    ALLOW OUT   Anywhere (out)
[ 4] 123                        ALLOW OUT   Anywhere (out)
[ 5] 53,123,137,138/udp         ALLOW OUT   Anywhere (out)
[ 6] 22                         ALLOW IN    61.xx.xxx.xxx
[ 7] 22                         ALLOW IN    115.xx.xxx.xxx
[ 8] 3306/tcp                   ALLOW IN    Anywhere
[ 9] 22                         ALLOW IN    61.xx.xxx.xxx/24
[10] 22                         ALLOW IN    1.xx.xxx.xxx
[11] 22                         ALLOW IN    49.xx.xxx.xxx
[12] 80,443/tcp                 ALLOW IN    Anywhere (v6)
[13] 3690/tcp                   ALLOW IN    Anywhere (v6)
[14] 22,80,443,5900,8001/tcp    ALLOW OUT   Anywhere (v6) (out)
[15] 123                        ALLOW OUT   Anywhere (v6) (out)
[16] 53,123,137,138/udp         ALLOW OUT   Anywhere (v6) (out)
[17] 3306/tcp                   ALLOW IN    Anywhere (v6)

sudo ufw delete 6

route 이용할 경우

등록

route add -host 도메인(IP) reject
Ex)    route add -host 61.147.74.223 reject

해제 
route del -host 도메인(IP) reject


목록보기
route


Networking 설정

  1. /etc/hosts
  2. /etc/resolv.conf
  3. /etc/network/interface
    auto eth0
    iface eth0 inet static
    	address xxx.xxx.xxx.xxx
    	netmask 255.255.255.248
    	network xxx.xxx.xxx.xxx
    	broadcast      xxx.xxx.xxx.xxx
    	geteway xxx.xxx.xxx.xxx
    	dns-nameservers 8.8.8.8 8.8.4.4 168.126.63.1 164.124.101.2
    	mtu     9000
sudo /etc/init.d/networking restart
wget www.google.com
# Resolving www.google.com (www.google.com)... 접속 실패: name resolution에서 일시적인 실패.
wget: unable to resolve host address `www.google.com'


sudo vi /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi=off pci=noacpi"
sudo reboot now
server time 설정

$ sudo ntpdate time.nuri.net


서비스 설정
* node 설치
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm
sudo npm install nodemon -g
# # auto deploy
# nodemon app.js
sudo npm install forever -g
# forever start app.js
sudo npm install express -g
sudo npm install node-schedule -g
sudo npm install node-inspector -g
npm install mysql
npm install mongolian
npm install clog
npm install consolidate 


** axconfig: port 1 not active axconfig: port 2 not active 에러
$ vi .bash_profile
PATH=/usr/bin:$PATH #추가
$ source .bash_profile

* nginx
$ sudo apt-get install nginx
$ /etc/init.d/nginx start

* nginx config
$ vi /etc/nginx/nginx.conf
http {
	##
	# Log Format
	##
	log_format	main	'$remote_addr - $remote_user [$time_local] $status '
					'"$request" $body_types_sent "$http_referer" '
					'"$http_user_agent" "$http_x_forwarded_for" ';

##
# Server blocks
##
index index.html;
server {
	server_name	xxx.kr;
	#access_log	/home/username/xxx.kr.access.log main;
	root			/home/username/www;
}
server {
	server_name	dev.xxx.kr;
	#access_log	/home/username/dev.xxx.kr.access.log main;
	root			/home/xxx/dev;
}

##
# Basic Settings
##
}

$ sudo /etc/init.d/nginx restart

* PHP
$ sudo apt-cache search php5
원하는 모듈만 설치

nginx 설정변경
  1. 기존 설정 삭제 > Clean 설정 상태
  2. /etc/nginx/sites-enabled/default 설정 수정
  3. PHP 서비스용 서버 블럭 추가
server {
	server_name	xx.xxx.kr;
	#access_log	/home/username/xx.xxx.access.log main;
	index                index.html index.htm index.php;

	location	/ {
		try_files $uri $uri/ @rewrites;
	}

	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
	location ! \.php$ {
location ~ \.php$ {
		fastcgi_split_path_info ^(.+\.php)(/.+)$;
		# NOTE: You should hava "cgi.fix_pathinfo = 0;" in php.ini
		# With php5-cgi alone;
		# fastcgi_pass 127.0.0.1:9000;
		# With php5-fpm;
		fastcgi_pass unix:/var/run/php5-fpm.sock;
		fastcgi_index index.php;
		include fastcgi_params;
	}
	# deny access to .htaccess files, if Apache's document root # 아파치에서 사용하는 .htaccess 무력화
	# concurs with nginx's one
	location ~ /\.ht {
		deny all;
	}
}
$ sudo /etc/init.d/nginx restart

* MySQL 설치
$ sudo apt-get install mysql-server mysql-client
# Dotdeb 저장소는 5.5 설치됨
# 2012.01.24 기본 5.5로 업그레이드 됨.

mysql> SET PASSWORD FOR 'ROOT'@'LOCALHOST"=PASSWORD('비밀번호');
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '비밀번호' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

$ sudo vim /etc/mysql/my.cnf
# bind-address = 127.0.0.1 # 주석처리, 내부시스템 제한 해제
$ sudo /etc/init.d/mysql restart


* PHP5, PHP-FPM 2013.01.17


# php와 그 외 패키지 제거
sudo apt-get -y purge php.*
sudo mkdir /var/www
# sudo apt-get install php5-cgi php5-mysql php5-fpm php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
#sudo apt-get install php5-cgi php5-mysql php5-fpm php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php-apc
sudo apt-get install php5-cgi php5-mysql php5-fpm php5-common php5-curl php5-gd php5-intl php-pear php5-imagick php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php-apc


# Dotdeb 저장소에서 설정할 경우 의존성 문제가 발생할 수 있슴.
$ sudo vim /etc/php5/fpm/php.ini
#cgi.fix_pathinfo=1
cgi.fix_pathinfo=0


$ sudo vi /etc/php5/fpm/pool.d/www.conf
listen = /dev/shm/php5-fpm.sock
$ sudo /etc/init.d/php5-fpm restart
# /dev/shm/php5-fpm.sock= 파일이 생성된다.
# [linux] Ram disk mechnism: tmpfs /dev/shm 참고
# /dev/shm -> /run/shm/
# 공유메모리 사용


// 설정 변경
$ sudo vi /etc/nginx/sites-available/default
server {
	listen [::]:80 default ipv6only=on;
	listen 80;
	server_name localhost;
	root /var/www/;
	#access_log /var/www/log/xxx-access.log;
	#error_log /var/www/logs/xxx-error.log;
	location / {
		index index.php index.html index.htm;
	}
	#error_page 404 /404.html;
	# redirect server error pages to the static page /50x.html
	#
	#error_page 500 502 503 504 /50x.html;
	#location = /50x.html {
	# root /var/www/nginx-default;
	#}
	location ~ \.php$ {
		#fastcgi_pass 127.0.0.1:9000;
		fastcgi_pass  unix:/dev/shm/php-fpm.sock;
		fastcgi_index index.php;
		include fastcgi_params;
	}
}
$ sudo vi /etc/nginx/fastcgi_params

# 아래 내용 추가
fastcgi_param   HTTP_X_REQUESTED_WITH   $http_x_requested_with;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;

$ sudo /etc/init.d/nginx restart
$ sudo /etc/init.d/php5-fpm reload
반응형

'os > Ubuntu' 카테고리의 다른 글

ubuntu mysql remove error  (0) 2013.07.23
우분투 원격접속  (0) 2013.07.12
ubuntu myunity  (0) 2012.04.12
우분투 데일리 ppa 업데이트  (0) 2011.06.06
ubuntu 한글폰트 모음 페이지  (0) 2011.03.29