ã¿ãªããããã«ã¡ã¯ã æè¿ãdebian 7ã§VPSãæ§ãããªãéã§èª¿éããå¿
èŠããããŸããã
ããã§ãéãã€ããŠèžãããšã«ã€ããŠè©³ãã説æããããšæããŸãã
ãã®æçš¿ã®ãã¹ãŠãã€ã³ã¿ãŒãããäžã§åéãããæçµæ±ºå®ãããåãŸãã1ã€ã®èšäºã«ãŸãšããããŸããã
äœäŸ¡æ Œãšãã®ãéã®å®å®æ§ã®ããã«ãéžæã¯
https://account.nt-vps.ru/register/ã«èœã¡ãŸããïŒãã ãã2æ¥éã¯ãããã¯ãŒã¯ã«é倧ãªåé¡ããããŸããïŒã VPSã¯ããã£ã¹ã¯äžã«128MBãš10GBã®å°ããªRAMæ§æã§1æ¥5ã«ãŒãã«ïŒãŸãã¯1ãæããã150ã«ãŒãã«ïŒã§ååŸãããŸããã
Debian 7.0 x86-64 Wheezyãèªåçã«ã€ã³ã¹ããŒã«ãããVPSã®æºåãæŽããŸããã
64ãããã·ã¹ãã ã¯å人çãªããŒãºã«ã®ã¿éžæãããŸãããããã®VPSã«x86ãã€ã³ã¹ããŒã«ããããšããå§ãããŸãã
éå§ãã
ãµãŒããŒãäœæãããšã次ã®ãããªã¡ãŒã«ãå±ããŸãã
ããã«ã¡ã¯
ä»®æ³ãµãŒããŒïŒvps3456
æ§æïŒ1xAMD-Opteron / 128Mb / 10Gb / 1xIPv4 @ 100
ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ïŒDebian 7.0 x86-64 Wheezy
ssh2ãä»ãããµãŒããŒãžã®ã¢ã¯ã»ã¹ïŒ
IPïŒ93.189.xx.xx
ããŒãïŒ22
ãŠãŒã¶ãŒïŒroot
ãã¹ã¯ãŒãïŒxxxxxxxxxxx
puttyã䜿çšããŠãµãŒããŒã«æ¥ç¶ãã
ssh2ãããã³ã«çµç±https://www.putty.org/
ãããã
æè¡ãµããŒã
ããªããçªãæã£ãŠãããªããæçŽã®æ瀺ã«è¬èã«åŸãããããªãæ瀺ã®ããã«ãªã³ã¯
https://www.putty.org/ããã©ã£ãŠãã ãã
ãããªããLinuxïŒDebian / Ubuntuãªã©ïŒãæã£ãŠãããªããç§ãã¡ã¯ãã®ããã«ãµãŒããŒã«æ¥ç¶ããŸãïŒ
$ ssh root@93.189.xx.xx -p 22
äž»èŠãªã»ãã¥ãªãã£ã·ã¹ãã ãã€ã¢ãã°ãååŸãããã®ïŒ
The authenticity of host '[93.189.xx.xx]:22 ([93.189.xx.xx]:22)' can't be established. ECDSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx. Are you sure you want to continue connecting (yes/no)?
åæããyesãšæžã蟌ã¿ãŸãã
ããã§ãšãããããŸããããªãã¯ã·ã¹ãã ã«ããŸãã
æŽæ°ããŸãããïŒ
ã«ãŒãthã®äžã«åº§ããªãã§ãã ããïŒ
ããã©ã«ãã§ã¯ãrootãšããŠåº§ãããã«æåŸ
ãããŠããŸãããããã¯ã»ãã¥ãªãã£äžã®çç±ããããŸãè¯ããããŸããã
1.äœæ¥ãè¡ããŠãŒã¶ãŒãäœæããŸãïŒæãç°¡åãªæ¹æ³ïŒïŒ
userã¯ãŠãŒã¶ãŒåã§ã
次ã«ã次ã®ãããªãã€ã¢ãã°ã衚瀺ãããŸãã
«user» ... «user» (1001) ... «user» (1001) «user» ... «/home/user» ... «/etc/skel» ... UNIX: UNIX: passwd: user ENTER []: []: []: []: []: ? [Y/n] Y
è€éãªãã¹ã¯ãŒããäœæããŸãïŒå¿ããªãã§ãããïŒïŒãããŠãå¿
èŠãšæãããããŒã¿ãå
¥åããããåã«EnterããŒãæŒããŸãã
2.ãŠãŒã¶ãŒã«sudoã®å®è¡ãèš±å¯ãã
ãŠãŒã¶ãŒãç¹å¥ãªsudoã°ã«ãŒãã«è¿œå ããŸãã
ããã§ãuserã¯ãŠãŒã¶ãŒåã§ãã
以äžã§ããŠãŒã¶ãŒãšããŠãã°ã€ã³ããŠãã°ã€ã³ã§ããŸã
$ ssh user@93.189.xx.xx -p 22
ã«ãŒãæš©éãå¿
èŠãªå Žåã¯åŒãç¶ãsudoã䜿çšããŸã
SSHãå°ãä¿è·ãã
ãµãŒããŒãèµ·åããçŽåŸã«ãçãããã¢ã¯ãã£ããã£ã«æ°ã¥ããŸãã
anu .. ããŒã22ã§ãæããã«ãäžåœã®ãã«ãã¹ãã£ããŒãã«ãããå
ãããã¹ã¯ãŒãã解èªãå§ããããã§ãã
æãç°¡åãªæ¹æ³ã¯ãsshããŒãã22ããä»ã®ããŒãã«å€æŽããããšã§ãã
1.ãããè¡ãã«ã¯ãsshãµãŒããŒæ§æãã¡ã€ã«ãéããŸãã
$ sudo nano /etc/ssh/sshd_config
ãããŒã22ããšããæååãæ€çŽ¢ãããããŒã354ãã«çœ®ãæããŸããããã§ã354ã¯1ã65535ã®ä»»æã®æ°åã§ã
念ã®ãããéããŠããããŒããèŠãŠã¿ãŸãããã
netstat -tupln | grep LISTEN
ãã®ãªã¹ãããã§ã¯ãªããã®ãéžæããŠãã ããã
ããŒã80ã443ã3306ã22ã21ã8080ãããŒã80-443ã䜿çšããªãããšããå§ãããŸãã
2.次ã«ãæ¥ç¶ããã¢ãã¬ã¹ã®çš®é¡ïŒIPv6ãŸãã¯IPv4ïŒãå¶éããŸãã ãµãŒããŒãIPv6ã䜿çšããŠããªãå Žåã¯ããã¡ã€ã«/ etc / ssh / sshd_configãè¿œå ããŸãã
AddressFamily inet
3.ã«ãŒããšããŠã®èš±å¯ãæåŠããPermitRootLoginãã¡ã€ã«ã調ã¹ãŠãnoãèšå®ããŸãã ãã®ãã©ã¡ãŒã¿ãŒãååšããªãå Žåã¯ã次ãè¿œå ããŸãã
PermitRootLogin no
4.ç¹å®ã®ãã°ã€ã³ã«ããæ¥ç¶ã®ã¿ãèš±å¯ãããã¡ã€ã«/ etc / ssh / sshd_configãè¿œå ããŸãã
AllowUsers user
ãŠãŒã¶ãŒã®ãªã¹ãã¯ã¹ããŒã¹ã§æžãããŠããŸãã
5.空ã®ãã¹ã¯ãŒãã§ã®ãã°ã€ã³è©Šè¡ãçŠæ¢ããŸãã PermitEmptyPasswordsãæ¢ããnoãèšå®ããŸã
PermitEmptyPasswords no
6. sshããŒã¢ã³ãä¿åããŠåèµ·åããŸãã
$ sudo /etc/init.d/ssh restart
ãŸããæ°ãããã©ã¡ãŒã¿ãŒïŒ$ ssh user@93.189.xx.xx -p 354ïŒã§ãã°ã€ã³ããèšäºã§ã»ãã¥ãªãã£ã®åé¡ã«æ»ããŸãã
SWAPã€ã³ã¹ããŒã«
èªåã¢ãŒãã§å€æããããã«ã
ã¹ã¯ããã¯èšå®ãããŠãããããã®ãããªã¡ã¢ãªãµã€ãºã§ã¯éèŠã§ãã
泚æïŒ ããã¯ç§ã®ç¹å®ã®ã±ãŒã¹ã§ãã次ã®ãããªã¹ã¯ããããããã©ããã確èªã§ããŸãã
$ sudo swapon -s
ddã䜿çšããŠãã¹ã¯ããé åã«å¿
èŠãªãµã€ãºã®ãã¡ã€ã«ãäœæããŸãã/swapã¯ãã¡ã€ã«ã®ååãšãã¹ãcount = 1024Kã¯ãã®ãµã€ãºããã®å Žåã¯512 MBã§ãã
ïŒéåžžã®åŒã¯swap = ram * 1.5ã§ãããããã¯ããã§ã¯ãããŸããïŒïŒ
$ sudo dd if=/dev/zero of=/swap bs=1024 count=512K
次ã«ãã«ãŒãã«ãããŒãžãã¡ã€ã«ãæäœããããã«äœ¿çšãããã¡ã€ã«ã·ã¹ãã æ
å ±ã®å
é ã«æžã蟌ã¿ãŸãã
$ sudo mkswap /swap
æäœãå®äºãããšã次ã®ããã«ãªããŸãã
1, = 536868 , UUID=54c60583-e61a-483a-a15c-2f1be966db85
次ã®ã¹ãããã¯ãæ°ããäœæãããSWAPãã¡ã€ã«ãã¢ã¯ãã£ãã«ããããšã§ãã
$ sudo swapon /swap
次ã«ãã·ã¹ãã ã®æ¬¡åèµ·åæã«fstabãã¡ã€ã«ãç·šéããŠã¹ã¯ãããæ¥ç¶ããå¿
èŠããããŸãã
$ sudo echo "/swap swap swap defaults 0 0" | sudo tee -a /etc/fstab
以äžã§ãã¹ã¯ããã®æºåãã§ããŸããã
ã³ãã³ãã§ç¢ºèªïŒ
$ free
åãåãå¿
èŠããããŸãïŒ
total used free shared buffers cached Mem: 510116 502320 7796 4380 1212 452548 -/+ buffers/cache: 48560 461556 Swap: 524284 0 524284
NGINXã®ã€ã³ã¹ããŒã«ãšé«åºŠãªæ§æ
ããã³ããšã³ããšããŠãããç¥ãããŠããnginxã䜿çšããŸãã
Webã¢ããªã±ãŒã·ã§ã³ã«ãµãŒããŒã䜿çšããªãå Žåã¯ããã®éšåãã¹ãããã§ããŸãã
ãã¡ãããæšæºã®ãªããžããªã«ã¯ãã§ã«nginxããããŸãããç§ã¯ãã®ããŒãžã§ã³ãããæ°é®®ã§èžããªãã§æ¬²ããã§ãã
1.ãã¡ã€ã«/etc/apt/sources.listãå€æŽããŸãã
$ sudo nano /etc/apt/sources.list
ãããŠäžçªäžã«è¿œå ããŸãïŒ
deb http://nginx.org/packages/debian/ wheezy nginx deb-src http://nginx.org/packages/debian/ wheezy nginx
7以å€ã®debianãããå Žåãwheezyã®ä»£ããã«ãã®ã³ãŒãåãæžããŸãã
2.ããã±ãŒãžãœãŒã¹ãæŽæ°ããnginxãã€ã³ã¹ããŒã«ããŸãã
$ sudo apt-get update && sudo apt-get install nginx
3. nginx.confãã¡ã€ã«ã®å
é ã«æ°ãããã©ã¡ãŒã¿ãŒãè¿œå ããŸã
timer_resolution 100ms;
4. worker_processesãæ¢ããŠãããã»ããµã³ã¢ã®æ°ã§æ°å€ãèšå®ããŸãïŒãã®å Žåã¯1ïŒã
worker_processes 1;
5.ã€ãã³ããã£ã¬ã¯ãã£ããæ¢ããŠç¢ºèªããŸãã
events { worker_connections 2048; use epoll; }
6. httpãã£ã¬ã¯ãã£ããç·šéãã次ã®ãã©ã¡ãŒã¿ãŒãå€æŽãŸãã¯è¿œå ããŸãã
sendfile on;
7. /etc/nginx/conf.d/sitename.confãŸãã¯ïŒubuntuïŒ/etc/nginx/sites-available/sitename.confãç·šéããŸããsitenameã¯ãµã€ãã®ååã«ãªããŸãã
$ sudo nano /etc/nginx/conf.d/sitename.conf
ç§ãã¡ã¯ãã®ãã©ãŒã ã«æã£ãŠããŸãïŒ
èšäºã®åŸåã§ãããã®èšå®ã«æ»ããŸãã
ã·ã¹ãã å€æ°ãéžæããããçš®ã®æ»æãã身ãå®ããŸã
ãããã®ãã©ã¡ãŒã¿ãŒã¯æ²¹æ§ãäžããå Žåã«ãã£ãŠã¯è² è·ãå¢å ãããŸãã
/etc/sysctl.confã®ç·šé
$ sudo nano /etc/sysctl.conf
æåŸã«è¿œå
ããã§åèµ·åã§ããŸã
ã·ã¹ãã å
šäœã®ããã©ãŒãã³ã¹ãé«éå
ããªãªã³ã¯ãšããªããŒãã éçã©ã€ãã©ãªã¢ãã¬ã¹ãäœæããããã®PrelinkãPreloadã¯ãæãé »ç¹ã«äœ¿çšãããã¢ããªã±ãŒã·ã§ã³ã®ãã¡ã€ã«ãç£èŠããã·ã¹ãã ãã¢ã€ãã«ç¶æ
ã®ãšãã«ããããã¡ã¢ãªã«ããŒãããå°ããªã¢ããªã±ãŒã·ã§ã³ã§ãã
1. Prelinkã®ã€ã³ã¹ããŒã«ïŒ
$ sudo apt-get -y install prelink
ãã¡ã€ã«/ etc / default / prelinkãç·šéããŸãã
$ sudo nano /etc/default/prelink
è¡ãPRELINKING = unknownããPRELINKING = yesã«å€æŽããŸã
以äžãéå§ããŸãã
$ sudo /etc/cron.daily/prelink
2.ããªããŒãã®ã€ã³ã¹ããŒã«ïŒ
$ sudo apt-get -y install preload
ãã¹ãŠãä»ã«äœãå¿
èŠãããŸãã
ãã¡ã€ã¢ãŠã©ãŒã«ãæ§æããïŒãã¡ã€ã¢ãŠã©ãŒã«ïŒ
ããã«ãéåžžã«çãããæ§æããããŸãã 1ã€ã®IPã¢ãã¬ã¹ããã®æ¥ç¶æ°ãæ§æããŸãã
ããã€ãã®çš®é¡ã®DOSæ»æãšãã«ãŒããã©ãŒã¹ã§ç¯çŽããŸãã
ç§ãã¡ã¯å®æœããŸãïŒ
$ sudo iptables -A INPUT -p tcp --dport 80 -i eth0 \ -m state --state NEW -m recent --set
ããã«ïŒ
$ sudo iptables -A INPUT -p tcp --dport 80 -i eth0 \ -m state --state NEW -m recent --update \ --seconds 15 --hitcount 20 -j DROP
ãã®ã«ãŒã«ã¯ã1ã€ã®IPã¢ãã¬ã¹ãã15ç§ä»¥å
ã«ããŒã80ïŒãŠã§ãïŒãžã®20以äžã®æ¥ç¶ãå¶éããŸãã
ïŒãšããã§ãåæ§ã®ã«ãŒã«ã¯nginxã¬ãã«ã§ãã§ã«èšå®ãããŠããŸãããèšå€§ãªéã®ãªãœãŒã¹ãæ¶è²»ããŸãïŒ
$ sudo iptables -A INPUT -p tcp --dport 354 -i eth0 \ -m state --state NEW -m recent --set
$ sudo iptables -A INPUT -p tcp --dport 354 -i eth0 \ -m state --state NEW -m recent --update \ --seconds 60 --hitcount 4 -j DROP
sshãµãŒããŒã®354ããŒãã¯ã©ãã«ãããŸããã ã«ãŒã«ã¯æ¥ç¶æ°ãå¶éãã1åéã«4æ¥ç¶ãè¶
ããªãããã«ããŸãã å®éã1åéã«1å以äžèš±å¯ããããšã¯ã§ããŸããã§ããã
ããã«ããã®ã«ãŒã«ãèªåèªèº«ãä»ã®ãµãŒãã¹ã«ããã«é©åãããããšãã§ããŸãã
ã·ã¹ãã ãåèµ·åãããšããã¹ãŠã®ã«ãŒã«ããŒãã«ãªã»ãããããããã次ã®ããšãè¡ããŸãã
ãã¡ã€ã«/etc/network/if-up.d/00-iptablesãäœæããã³ç·šéããŸã
$ sudo nano -w /etc/network/if-up.d/00-iptables
æžã蟌ã¿ãŸãïŒ
ãã¡ã€ã«ãä¿åããŠå®è¡å¯èœã«ããŸãïŒ
$ sudo chmod +x /etc/network/if-up.d/00-iptables
ã«ãŒã«ããã¡ã€ã«ã«ä¿åããŸãã
$ sudo iptables-save | sudo tee /etc/firewall.conf
ãã¹ãŠãã«ãŒã«ãèšå®ãããã·ã¹ãã ã®åèµ·ååŸãæ®ããŸãã
ããã§æåã®éšåã¯çµãããèªç±æéãæ¥ãŸããã
次ã®ããŒãã§ã¯ãnginxãnode.jsã«ãããã·ãããnode.jsãã€ã³ã¹ããŒã«ããŠæ§æãããphp-fpmãã€ã³ã¹ããŒã«ããŠnginxã«æ¥ç¶ããããšã«ã€ããŠèª¬æããŸãã +äžèŠãªãã³ã¹ãªãã®é床ãšå®å
šæ§ã«é¢ãããã³ããPSããã¯Habréã«é¢ããç§ã®æåã®æçš¿ã§ãããé«åºŠãªdebianã»ããã¢ããã®æåã®çµéšã®1ã€ã§ãã æ¹å€ãèšæ£ãèããŠããããã§ãã
updïŒ habra-peopleã®æ¹å€ãä¿®æ£ãã¢ããã€ã¹ãããã³åå¿æ§ã«æè¬ããŸãã 次ã®èšäºã«ããªãã®ã¢ããã€ã¹ãè£è¶³ããŸãã
upd 04/19/16ïŒèšäºãå°ãç·šéãããšã©ãŒãä¿®æ£ããããã€ãã®å Žæã§è£è¶³ããŸããã debian 8.1ã§ãã§ãã¯-åäœããŸãã nåç®ã«å»¶æãããæ°ããèšäº...
2018幎12æ10æ¥æŽæ°ïŒãµãŒãã¹ãåå²ãããŸããã èšäºå
ã®ãªã³ã¯ãæŽæ°ãããŸãã