æ°ãããªã£ã ãããVPS + nginx + Sinatra ã§ãã©ã¤ãã¼ã Gyazo ãµã¼ããæ§ç¯ããã
åçã»ã«ã¡ã©é¢é£ã®ã¨ã³ããªã°ãããæ稿ãã¦ããã®ã§ããã®ã¾ã¾åçããã°ã«ãªã£ã¦ãã¾ãã®ã§ã¯ã¨èªåã§ãå±æ§ãã¦ããã¨ããã§ããä»æ¥ã¯ä¹ ãã¶ãã«æè¡ç³»ã®ã¨ã³ããªãæ¸ãã¦ã¿ããã¨æãã¾ãã
ã¯ããã«
çªç¶ã§ãããã¿ãªãã㯠さくらのVPS 使ã£ã¦ãã¾ããï¼
æé¡ãã£ãã®980åã§ãroot権éä»ãã®å°ç¨ãµã¼ããæã¦ãã¨ãããã¨ãããããµã¼ãã¹éå§ããããããã£ã¨æç¨ãã¦ãã¦ããã¾ããã
ããã¾ã§ã¯æ§ãã©ã³(ãããã®VPS 512)ãå¥ç´ãã¦ããã®ã§ããããã®ãã³æ°ãããã©ã³ã«ãªãã¥ã¼ã¢ã«ãããåãæé¡980åã§ãRAM1GBãHDD 200GBï¼æ§ãã©ã³ã§ã¯ã¡ã¢ãª512MBãHDD50GBï¼ã¨ããã¹ããã¯ã¢ããããVPSãµã¼ãã¹ãå©ç¨åºæ¥ãããã«ãªãã¾ããã
ããã§ä»åã¯ããããã®VPSä¸ã«ããã©ã¤ãã¼ããªGyazoãµã¼ãããæ§ç¯ããæé ã«ã¤ãã¦èª¬æãã¦ããããã¨æãã¾ãã
Gyazo · Free Screenshot App · Capture, Share, & Search Easier
Gyazoã¯ãæå ã®PCã®ã¹ã¯ãªã¼ã³ã·ã§ãããåãåã£ã¦ç¬æã«ã¤ã³ã¿ã¼ãããä¸ã«å ¬éã§ãããµã¼ãã¹ã§ããGyazoèªä½ã¯ã誰ã§ãèªç±ã«ä½¿ããã¨ãåºæ¥ããµã¼ãã¹ãªã®ã§ãããProã¢ã«ã¦ã³ãã§ãªãã¨ç»åã®åé¤ãèªç±ã«åºæ¥ãªãã£ããããä¸ã«ãGithubä¸ã§ãµã¼ãã»ã¯ã©ã¤ã¢ã³ãã®ã½ã¼ã¹ã³ã¼ããå ¬éããã¦ããçºããã©ã¤ãã¼ããªèªåå°ç¨ã®Gyazoãµã¼ããç«ã¦ã¦ãã¾ã£ãã»ããè²ã ã¨èéãå©ãã¦è¯ããã ã£ãããã¾ãã
Gitã®ã¤ã³ã¹ãã¼ã«
Gyazoé¢é£ã®ã½ã¼ã¹ã³ã¼ããGithubããã²ã£ã±ã£ã¦ããå¿ è¦ãããã®ã§ãã¾ãã¯Gitãyumããã¤ã³ã¹ãã¼ã«ã
$ sudo yum install git
Rubyã®ã¤ã³ã¹ãã¼ã«
Rubyãã½ã¼ã¹ããã¤ã³ã¹ãã¼ã«ãã¾ãã
VPSãæä¾ãããåæç¶æ
ã®Cent OSã§ã¯ãzlib-devel ãã readline-devel ãããRubyã®æ¡å¼µã©ã¤ãã©ãªãã³ã³ãã¤ã«ããã«ãããå¿
è¦ã«ãªãããã¤ãã®yumãã¤ã³ã¹ãã¼ã«ããã¦ãã¾ããã
ããã«ããããã¨ã§nginxããå種gemãããå
¥ããã¨ãã«æããã¦ãã¾ãããã¨ããRubyã®æ¡å¼µã©ã¤ãã©ãªãmakeãç´ããã¨ã«ãªãã®ã§ãæåã«ãããããyumã§ã¤ã³ã¹ãã¼ã«ãã¦ããã¾ãã
$ sudo yum install zlib-devel readline-devel curl-devel openssl-devel
ã©ã¤ãã©ãªã®ã¤ã³ã¹ãã¼ã«ãå®äºããããRubyã®ã½ã¼ã¹ããã¦ã³ãã¼ãããã«ããã¾ãã
å½ç¶ rvm ã使ç¨ãã¦ãåé¡ã¯ãªãã®ã§ãããä»å㯠/usr/local é
ä¸ã«Rubyãã¤ã³ã¹ãã¼ã«ãã¾ãã
$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz $ tar xvfz ruby-1.9.3-p125.tar.gz $ cd ruby-1.9.3-p125 $ ./configure --prefix=/usr/local $ make $ sudo make install $ ruby -v ruby 1.9.3p125 (2012-02-16 revision 34643) [i686-linux]
sudo secure_path è¨å®ã®ç¡å¹å
ãªãã¥ã¼ã¢ã«ãããVPSã§ã¯CentOSã®ãã¼ã¸ã§ã³ãæ°ãããªã£ã¦ããçºãã/etc/sudoers ã« secure_path ã®è¨å®ã追å ããã¦ãã¾ãã
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
è¦ã¯ããsudoçµç±ã§ã³ãã³ããå®è¡ããã¨ãã«éããããã§æå®ããã¦ããPATHã®ã¿ã使ç¨ãã¾ãããã¨ãããã¨ãããããã®æå®ãæå¹ã«ãªã£ã¦ããéãã¯ã/etc/sudoers ã® env_keep ã«PATHç°å¢å¤æ°ã追å ããã¨ãã¦ããsecure_pathã®è¨å®ã®ã»ããæå¹ã«ãªã£ã¦ãã¾ãã¿ããã§ãã
ãã®ã¾ã¾ã ã¨ã/usr/local é
ä¸ã«ã¤ã³ã¹ãã¼ã«ããã gem ã³ãã³ããå½ç¶ä½¿ç¨åºæ¥ã¾ãããsecure_path ã« /usr/local ã追å ããã¨ããæãããã®ã§ããããããã sudoæã®PATHç°å¢å¤æ°ãå¶éãããã¨ã®ã©ããsecureãªã®ãå
¨ãç解ãåºæ¥ãªãï¼è©³ããæ¹ãããã³ããããããã¾ãï¼ã®ã§ãä»åã¯ããã¤ãæãåã£ã¦ã³ã¡ã³ãã¢ã¦ããã¦ã/etc/sudoers ã® env_keep ã« PATH ç°å¢å¤æ°ã追å ãã¾ãã
ããã«ãããsudo çµç±ã§ gem ã³ãã³ããå®è¡åºæ¥ãããã«ãªãã¾ãã
$ su # visudo
Defaults env_reset Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS" Defaults env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE" Defaults env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES" Defaults env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE" Defaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY" Defaults env_keep += "PATH" # âãã®è¡ã追å ... # Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin # ãã®è¡ãã³ã¡ã³ãã¢ã¦ã
Passengerã®ã¤ã³ã¹ãã¼ã«
ããã¾ã§ã§ãgemã³ãã³ããå®è¡åºæ¥ãããã«ãªã£ãã®ã§ãPassenger gem ãã¤ã³ã¹ãã¼ã«ãã¾ãã
$ sudo gem install passenger
nginxã®ã¤ã³ã¹ãã¼ã«
Passngeræ·»ä»ã® passenger-install-nginx-module ã³ãã³ãã使ã£ã¦ãnginxãã¤ã³ã¹ãã¼ã«ãã¾ãã
$ sudo passenger-install-nginx-module
éä¸ãnginxã®ã¤ã³ã¹ãã¼ã«ãã¹ã®å ¥åãä¿ããã¾ããããã©ã«ãã§ã¯ /opt/nginx/ ã«ã¤ã³ã¹ãã¼ã«ãããããã«ãªã£ã¦ãããããªã®ã§ãããããã§ã¯ /usr/local/nginx ã«ã¤ã³ã¹ãã¼ã«ãã¦ã¿ã¾ããåãªã好ã¿ã®åé¡ã§ããã©ãã
nginxèµ·åã¹ã¯ãªããã®ä½æ
nginxãã¤ã³ã¹ãã¼ã«å¾ãèµ·åã¹ã¯ãªãããä½æãã¦ããã¾ãã
$ sudo touch /etc/rc.d/init.d/nginx $ sudo vi /etc/rc.d/init.d/nginx
èµ·åã¹ã¯ãªããã«ã¯ä»¥ä¸ã®ãããªå 容ãè¨è¼ã
#!/bin/sh # # nginx - this script starts and stops the nginx daemin # chkconfig: 345 85 15 # description: Nginx # export GEM_HOME=/usr/local/lib/ruby/gems/1.9.1/gems # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac
ä½æããããå®è¡æ¨©éãä»ä¸ãã¦ããã¾ãã
$ sudo chmod 755 /etc/rc.d/init.d/nginx
Sinatra ã®ã¤ã³ã¹ãã¼ã«
次ã¯Sinatraãgemã§ã¤ã³ã¹ãã¼ã«ããã¡ããç¹ã«åé¡ãªãéãã¯ãã
$ sudo gem install sinatra
gyazo-sinatra ã®ã½ã¼ã¹ã³ã¼ããåå¾
Gyazoã®Githubãªãã¸ããªã«ã¯ã以ä¸ã®ãããªã¢ãããã¼ãCGIãç¨æããã¦ãã¾ãã
https://github.com/gyazo/Gyazo/blob/master/Server/upload.cgi
ã§ãããåãªãcgiã§ã¯ãã¾ãè¸ãç¡ãã®ã§ãä»åã¯Sinatraä¸ã§åä½ããgyazoãµã¼ãã使ãã¾ãã
GitHub - send/gyazo-sinatra: A Gyazo server using Sinatra.
ä¸è¨ã®ãªãã¸ããªãããã½ã¼ã¹ã³ã¼ããcloneãã¾ãã
ããã§ã¯ä»®ã«ãnginxã®å®è¡ã¦ã¼ã¶ããaquarlaãã¨ãããã®ã¨ãã¦ããã£ã¬ã¯ããªã®ææã¦ã¼ã¶ãå¤æ´ãã¾ãã
$ cd /var/www $ sudo mkdir gyazo-sinatra $ sudo chown aquarla:aquarla gyazo-sinatra # nginxã®å®è¡ã¦ã¼ã¶ããaquarlaãã¨ããå ´å $ git clone https://github.com/send/gyazo-sinatra
ã½ã¼ã¹ã³ã¼ããcloneããããapp.rbãã¨ãã£ã¿ã§éããVPSã®ãã¡ã¤ã³åã«åããã¦ãã¡ã¤ã«ã®å 容ãå¤æ´ãã¾ãã
$ vi /var/www/gyazo-sinatra/app.rb
require 'rubygems' require 'sinatra' require 'rack' require 'digest/md5' require 'sdbm' module Gyazo class Controller < Sinatra::Base configure do set :dbm_path, 'db/id' set :image_dir, 'public/images' set :image_url, 'http://gyazo.send.sh/images' # âãã®è¡ã®ãã¡ã¤ã³ãå¤æ´ããï¼ end post '/' do id = request[:id] data = request[:imagedata][:tempfile].read hash = Digest::MD5.hexdigest(data).to_s dbm = SDBM.open(options.dbm_path, 0644) dbm[hash] = id File.open("#{options.image_dir}/#{hash}.png", 'w'){|f| f.write(data)} "#{options.image_url}/#{hash}.png" end end end
ã¡ãªã¿ã«ãã®ã¾ã¾ã®ããã°ã©ã ã ã¨ãä»»æã®ã¦ã¼ã¶ããã®ãµã¼ãã«å¯¾ãã¦ã¢ãããã¼ãæä½ãè¡ããã¨ãåºæ¥ã¦ãã¾ãã®ã§ããããå«ãªå ´åã¯å¿ è¦ã«å¿ãã¦ã¢ã¯ã»ã¹å¶éãªã©ã®çãè¬ããå¿ è¦ãããã¾ããããã§ã¯ãã®èª¬æã¯å²æãã¾ãã
nginxã®è¨å®ãå¤æ´ãã
ä¸è¨ã®gyazo-sinatraãã£ã¬ã¯ããªä¸ã§sinatraã¢ããªãåä½ããããã«ãnginxã®è¨å®ãã¡ã¤ã«ãå¤æ´ãã¾ãã
$ sudo vi /usr/local/nginx/conf/nginx.conf
a. nginxã®å®è¡ã¦ã¼ã¶ããgyazo-sinatraãã£ã¬ã¯ããªã®ææã¦ã¼ã¶ï¼ããã§ã¯ aquarlaï¼ã¨åä¸ã«ãªãããã«å¤æ´
è¦ã¯ãnginxããã»ã¹ãgyazo-sinatraãã£ã¬ã¯ããªé ä¸ã«æ¸ãè¾¼ã¿æä½ãè¡ããã¨ãåºæ¥ãã°ããã®ã§ãããããã§ã¯åãããããnginxã®å®è¡ã¦ã¼ã¶ãå¤æ´ãã¦ãã¾ãã¾ãã
user aquarla;
b. ãã¼ãã£ã«ãã¹ãã®è¨å®
gyazo-sinatra/public ã®ãã£ã¬ã¯ããªããã¼ãã£ã«ãã¹ãã®ããã¥ã¡ã³ãã«ã¼ãã«ãªãããã«ããã¼ãã£ã«ãã¹ãã®è¨å®ã追å ãã¾ãã
注æãã¹ãã¯2ç¹ã
- å½ããåã§ãããpassenger_enabled on;ãã®è¨è¼ãå¿ãã㨠Passengerãåä½ãã¾ããã
- client_max_body_sizeã®æå®ãçãã¦ãã¾ãã¨ã大ããã®ã¹ã¯ãªã¼ã³ã·ã§ãããã¢ãããã¼ãããå ´åã«ã¨ã©ã¼ã¨ãªã£ã¦ãã¾ãã¾ããデフォルトは1MBã¨ãªã£ã¦ããã®ã§ãä½è£ãæã£ã¦10MBã«å¢ããã¦ããã¾ãã
server { listen 80; server_name gyazo.aquarla.net; root /var/www/gyazo-sinatra/public; access_log logs/gyazo_access_log; error_log logs/gyazo_error_log; client_max_body_size 10m; passenger_enabled on; }
nginx ãèµ·å
ããã¾ã§è¨å®ããããnginxãèµ·åãã¾ãã
$ sudo /etc/rc.d/init.d/nginx start
ã¢ãããã¼ãç¨ã¯ã©ã¤ã¢ã³ãã®æºå
Linuxã®å ´å
以ä¸ã®ãªãã¸ããªããã½ã¼ã¹ã³ã¼ããcloneã
GitHub - gyazo/Gyazo-for-Linux: Gyazo for Linux
gyazoã¹ã¯ãªãããã¨ãã£ã¿ã§éããHOSTå¤æ°ãCGIå¤æ°ãä¿®æ£ãã¾ãã
$ git clone https://github.com/gyazo/Gyazo-for-Linux gyazo_for_linux $ cd gyazo_for_linux $ vi gyazo
... HOST = 'gyazo.aquarla.net' # 'gyazo.com' CGI = '/' # 'upload.cgi' ...
Macã®å ´å
以ä¸ã®ãªãã¸ããªããã½ã¼ã¹ã³ã¼ããcloneã
GitHub - gyazo/Gyazo: Gyazo: the simplest and fastest screenshot uploading tool
Gyazo.app/Contents/Resources/script ããLinuxçã¨åæ§ã®rubyã¹ã¯ãªããã«ãªã£ã¦ããã®ã§ãHOST/CGIã®ä¸¡å¤æ°ãå¤æ´ããã°OKã§ãã
Windowsã®å ´å
以ä¸ã®ãªãã¸ããªããã½ã¼ã¹ã³ã¼ããcloneã
GitHub - gyazo/Gyazowin: Gyazo for Windows
Visual C++ 2010ã ã¨ãã«ããéããªãã¦å°ãããã£ãã®ã§ãããããã°ã©ã ã®å®ä½ã¯gyazowin.cppã«ããã®ã§ãæ°è¦ããã¸ã§ã¯ããä½ãç´ãã¦gyazowin.cppã®ä¸èº«ãã³ãã¼ããã°ã³ã³ãã¤ã«åºæ¥ãè¨æ¶ãâ¦ããããã¸ãã¯æ¬¡åãããã«èª¬æãã¾ãã
åã¯ã©ã¤ã¢ã³ãããã¹ã¯ãªã¼ã³ã·ã§ããã®ã¢ãããã¼ãã«æåããã°ä½æ¥å®äºã§ãï¼ãã¤ãããã¾ã§ããï¼
ãããã«
ãã®ã¨ã³ããªã§ã¯ãæ°ããããããã®VPSãããã©ã¤ãã¼ãGyazoãµã¼ãã¨ãã¦æ´»ç¨ããããã®ç°å¢æ§ç¯æé ãç´¹ä»ãã¾ããã
ãªãã¥ã¼ã¢ã«ãããããããã®VPSãã¯ãä¸çªä¸ã®ããããã®VPS 1Gããã©ã³ã§ãHDDã100GBãç¨æããã¦ããã®ã§ããã£ã¹ã¯å®¹éãæ°ã«ãããã¨ãªããPCã®ã¹ã¯ãªã¼ã³ã·ã§ãããã¬ã³ã¬ã³ã¢ãããã¼ããããã¨ãåºæ¥ãããã«ãªãã¾ããã
ãã®æ©ä¼ã«ããªããèªåå°ç¨ã®Gyazoãµã¼ããæ§ç¯ãã¦ã¿ã¾ãããï¼