å¤åããããªã¿ã¤ãã«ã¨è¢«ã£ã¡ãã£ã¦ãã¨æããã§ãä¼ããæè¨ããããªãã ã許ãã¦ã»ããã
ãã¡WebServiceã¤ã³ã¹ã¿ã³ã¹ã®ããã«OSå ¥ãæ¿ããªãã¦ãã¦ããããï¼ æè©®Ruby on Railsãä¾åããã£ãã°ããããããã§ãããï¼
Production-guide.mdã«æ²¿ã£ã¦ããããã
åºæ¬çã«Package Managerã使ã£ã¦è§£æ±ºãã¦ããããã
ç°å¢
TL;DR
- CentOS6.9ã§ã Mastodonã¯åã
- æææã£ã¦AWSã®æå©ããã»ããç¾åãããä¸åã¯çç£æ§é«ã
mastodon userãä½æãã¦ãã
sudo useradd mastodon sudo passwd mastodon
å¤é¨ããsshã§ãã¹ã¯ã¼ããã°ã¤ã³ãããªããã ã¨ãã¯å²æã
Software Collectionãå°å ¥ãã¦ãã
CentOS6.9ã®æ¨æºã§ã¯ãã¼ã¸ã§ã³ã®è¶³ããªãããã±ã¼ã¸ãã¡ãã»ãããã®ã§ãSoftware Collectionãå°å ¥ãã¦ããã
sudo yum install centos-release-scl
sudo yum-config-manager --enable rhel-server-rhscl-6-rpms
Apacheã2.4.5以éã«ãã
WebSocket対å¿ã®ãªãã¼ã¹ãããã·ãæä¾ããmod_proxy_wstunnel
ãå¿
è¦ã ããApache 2.4.5
以éã§æå¹ã¨ã®ãã¨ã
ãã®ä»¶ã«é¢ãã¦ã¯ä»ã§ãæµç¨ã§ããããªã®ã§å¥è¨äºã«ããã
General Depenciesã解決ãã
è³æãå ã«è§£æ±ºããã
# ããã CentOSãã¤ãºãã sudo apt-get install imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev nodejs file git curl curl -sL https://deb.nodesource.com/setup_4.x | sudo bash - sudo apt-get install nodejs sudo npm install -g yarn
ImageMagick
https://www.imagemagick.org/script/index.php
ç»åæä½å¨ããMastodonã§åãæ±ãéã«ä½¿ã£ã¦ãã®ããªã
base
ãªãã¸ããªã®6.7.2.7
ã使ãã
å°å ¥æ¹æ³
sudo yum install ImageMagick
FFmpeg
åç»å¨ãã®å¦çãä»»ãã¦ãã®ããªã
ubuntuã§ã®å°å
¥æ¹æ³ããæ¸ãã¦ãªãçç±ã¯ããã¤ã®ãããããªãããªã¨æãã
å°å ¥æ¹æ³
å ¬å¼ãã¼ã¸ã®Downloadãè¦ãã¨RPMFusionãæ¡å ãã¦ããã®ã§ãã¡ãããå°å ¥ãã¦ã¿ãã
RPMFusion
http://qiita.com/m2wasabi/items/6d6a68da2e9dada92369#rpmfusion ãåèã«ããã
--enablerepo
åæã§ã¤ã³ã¹ãã¼ã«ããã®ã§å è¨äºã®yum-plugin-*
ã¯é¤å¤
ã¾ãèªèº«ã®ç°å¢ãã§ãã¯
cat /etc/redhat-release # CentOS release 6.9 (Final) arch # x86_64
RPM Fusionã®ãã¼ã¸ãããå¿ è¦ãªãªãã¸ããªãã©ããå¤æããã
- Browse available packagesããffmpegãæ¢ãã¦ã¿ã
CentOS 6.9
ã§x86_64
free
ã«ããããapplications/multimedia
ã«ãããã- ãã£ã
PGP-Keyã®ã¤ã³ã¹ãã¼ã«
- Keysã®ãã¼ã¸ããæ¢ã
free
ã§EL 6
ã®keyãã¤ã³ã¹ãã¼ã«ããã°ãã
sudo gpg --keyserver pgp.mit.edu --recv-keys 849C449F
ãªãã¸ããªã追å ãã
- RPMã®ãªã³ã¯æ¢ã
- ã¨ããããFAQè¦ã¦ã¿ããã·ã³ãã«ãªãã¼ã¸ã¸ã®æ¡å ããã£ãã
- ç¨ãããã®ã¯freeãªãã¸ããªã ããªã®ã§non-freeã¯ç¡è¦
sudo yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-6.noarch.rpm
rpmfusionã¯åæç¶æ ç¡å¹ã¨ããã
sudo vi /etc/yum.repo.d/rpmfusion-free-updates.repo
[rpmfusion-free-updates] # enabled=1 enabled=0
yum-config-manager
使ãã£ã¦ãè¯ãã£ãã®ããªã
ffmpeg
sudo yum --enablerepo=rpmfusion-free-updates install ffmpeg
libpq-dev
PostgreSQLã®ã©ã¤ãã©ãªãããããã®æè¨ã®ã¾ã¾ã§ã¯yumã§è¦ã¤ãããªãã
- yumã§å¯¾å¿ããã®ã¯
postgresql-devel
ããã- ãããç¡ããã¨ã§çºçããã¨ã©ã¼ãè¦ãã¨ãå¿
è¦ãªãããã¼ãç¡ãã¨
gem pg
ãå°å ¥ããéãã«ãã失æããããã yum search postgresql
ãã¦åºã¦ããçµæãè¦ãã¨ãããã§ããããpostgresql-devel.x86_64 : PostgreSQL development header files and libraries
- ãããç¡ããã¨ã§çºçããã¨ã©ã¼ãè¦ãã¨ãå¿
è¦ãªãããã¼ãç¡ãã¨
å°å ¥æ¹æ³
sudo yum install postgresql-devel
libxml2-dev
yumã ã¨libxml2-devel
ã対å¿ããã®ããªãURLã¯åãå ´æã示ãã¦ããã
The XML C parser and toolkit of Gnome http://xmlsoft.org/
å°å ¥æ¹æ³
sudo yum install libxml2-devel
libxslt1-dev
yumã ã¨libxslt-devel
ã対å¿ããã®ããªãURLã¯åãå ´æã示ãã¦ããã
- http://packages.ubuntu.com/ja/trusty/libxslt1-dev
- http://rpmfind.net/linux/rpm2html/search.php?query=libxslt-devel
ãªã1ãç¡ãã®ã ããâ¦
å°å ¥æ¹æ³
sudo yum install libxslt-devel
nodejs and yarn
anyenv -> nodenv çµç±ã§å ¥ããã
ãã¼ãã¼ãªã®ã§ç¾æç¹(2017/04/19)ã®ææ°ç7.9.0
ãã¤ã³ã¹ãã¼ã«ããã
yarn install
ã§ãªããæ»ãã ã
Production-Guideã«å¾ã£ã¦ã4.xã®ææ°çã§ãã4.8.2
ãå
¥ããã
åå ã¯å¥ä»¶ã ã£ã: ä¸è¨ãã©ãã«ã·ã¥ã¼ãåç §
ã¨ãã«èãããªãndenv使ã£ã¦ããã©ãã³ããããéããªã®ã§æµ®æ°ãï¼**envã«æ´»çºæ§ãæ±ãã¦ããããããªããã©ï¼
nodenvã¯nodenvã§ndenv Ownerã«Joinæã¡ãããããanyenvããä»ã®node.jsç³»envææ¥ãæã¡ããããããã³ãã¥ããã£ãªã®ã§ã©ããªã®ã¨æããªãããªãã
å°å ¥æ¹æ³
su - mastodon git clone https://github.com/riywo/anyenv ~/.anyenv echo 'export PATH="$HOME/.anyenv/bin:$PATH"' >> ~/.bash_profile echo 'eval "$(anyenv init -)"' >> ~/.bash_profile exec $SHELL -l anyenv install nodenv exec $SHELL -l nodenv install 4.8.2 nodenv global 4.8.2 npm install -g yarn nodenv rehash
file, git, curl
ç¹ã«ããåããããã¤ã³ãã¯ãªãã
å°å ¥æ¹æ³
sudo yum install file git curl
Redis
Sidekiqã®è¦æ±ãã¼ã¸ã§ã³ã>= 2.8.0
ã¨ã®ãã¨ã
epelããå
¥æããRedisã§ã¯2.4.x
ã®ãããçµç¤ã«ãªã£ã¦åé¡ãçºè¦ãã¦é常ã«æ²ããæ°æã¡ã«ãªãã
SoftwareCollectionããRedis 3.2
ãå°å
¥ããã
å°å ¥æ¹æ³
sudo yum install rh-redis32-redis # Lockãã¡ã¤ã«ãç½®ããã£ã¬ã¯ããªãä½ãã¦ãããæããã®ã§å¯¾å¿ sudo mkdir /var/opt/rh/rh-redis32/lock sudo mkdir /var/opt/rh/rh-redis32/lock/subsys sudo service rh-redis32-redis start sudo chkconfig rh-redis32-redis on
PostgreSQL
Ruby on Rails ã¨ããã ActiveRecordsã®è¦æ±ãã¼ã¸ã§ã³ã>= 9.1
ã¨ã®ãã¨ãªã®ã§ãSoftwareCollectionããPostgreSQL 9.5
ãå°å
¥ããã
å°å ¥æ¹æ³
sudo yum install rh-postgresql95-postgresql-server sudo yum install rh-postgresql95-postgresql-contrib scl enable rh-postgresql95 bash # rootã§ã®ä½æ¥ ãããã su - echo 'source /opt/rh/rh-postgresql95/enable' >> /etc/profile.d/rh-postgresql95.sh exit # rootã§ã®ä½æ¥ ããã¾ã§ sudo /opt/rh/rh-postgresql95/root/usr/bin/postgresql-setup --initdb sudo service rh-postgresql95-postgresql start sudo chkconfig rh-postgresql95-postgresql on sudo passwd postgres
mastodonãå°å ¥ãã
PostgreSQL userãä½ã
su - postgres psql
CREATE USER mastodon CREATEDB; \q
# postgres userããæãã exit
rbenvã使ã£ã¦rubyãå°å ¥ãã
su - mastodon anyenv install rbenv exec $SHELL -l rbenv install 2.4.1 rbenv global 2.4.1
mastodon ãã¤ã³ã¹ãã¼ã«ãã
cd ~ git clone https://github.com/tootsuite/mastodon.git live cd live gem install bundler bundle install --deployment --without development test yarn install
mastodon ã®ç°å¢è¨å®
.env.productionãè¨å®ãã¦ããã
pwd # /home/mastodon/live cp .env.production.sample .env.production
redis
以ä¸ã.env.production
ã®é
ç®ã§ç·¨éããã
REDIS_HOST=localhost REDIS_PORT=6379
DB (PostgreSQL)
以ä¸ã.env.production
ã®é
ç®ã§ç·¨éããã
DB_HOST= DB_USER=mastodon DB_NAME=mastodon DB_PASS= DB_PORT=5432
mastodon ã®ã»ããã¢ãã
RAILS_ENV=production bundle exec rails db:setup RAILS_ENV=production bundle exec rails assets:precompile
ãµã¼ãã¹ã®ä½æ
CentOS6.9ã ããSystemd
ã¯ä½¿ã£ã¦ãªãã®ã§/etc/init.d/
ã«é
ç½®ããã»ãã®ãµã¼ãã¹ã¨ãã¦æ¸ãåºãã
ææ¢ãã§start-stop-deamon
ç¡ãã©ãããdeamon
使ã£ã¦ãªãããã¨ãããstart
ã¨stop
ãããªãã
mastodon-web
#!/bin/bash # # Mastodon worker web # # chkconfig: - 85 15 # description: Mastodon web prog="mastodon-web" username="mastodon" root="/home/mastodon/live" pidfile="${root}/web.pid" start() { if [ -f $pidfile ]; then echo "Mastodon webservice running..." exit 1 fi su - $username -c "cd ${root} && RAILS_ENV=production PORT=3000 bundle exec puma -C config/puma.rb -d --pidfile ${pidfile}" return 0 } stop() { if [ -f $pidfile ]; then su - $username -c "kill $(cat ${pidfile}) && rm ${pidfile}" else echo "Mastodon webservice dos'nt running..." exit 1 fi return 0 } case "$1" in start) start ;; stop) stop ;; *) echo $"Usage $prog {start|stop}" exit 2 esac exit 0
mastodon-sidekiq
#!/bin/bash # # Mastodon worker sidekiq # # chkconfig: - 85 15 # description: Mastodon sidekiq prog="mastodon-sidekiq" username="mastodon" root="/home/mastodon/live" pidfile="${root}/worker.pid" logfile="${root}/sidekiq.conf" start() { if [ -f $pidfile ]; then echo "Mastodon worker sidekiq running..." exit 1 fi su - $username -c "cd ${root} && RAILS_ENV=production DB_POOL=5 bundle exec sidekiq -d -P ${pidfile} -L ${logfile} -c 5 -q default -q mailers -q pull -q push" return 0 } stop() { if [ -f $pidfile ]; then su - $username -c "kill $(cat ${pidfile}) && rm ${pidfile}" else echo "Mastodon worker sidekiq dos'nt running..." exit 1 fi return 0 } case "$1" in start) start ;; stop) stop ;; *) echo $"Usage $prog {start|stop}" exit 2 esac exit 0
mastodon-streaming
#!/bin/bash # # Mastodon streaming API service # # chkconfig: - 85 15 # description: Mastodon steaming API service prog="mastodon-streaming-api" username="mastodon" root="/home/mastodon/live" pidfile="${root}/streaming.pid" start() { if [ -f $pidfile ]; then echo "Mastodon streaming API running..." exit 1 fi su - $username -c "cd ${root} && NODE_ENV=production PORT=4000 nohup npm run start & echo \$! > ${pidfile}" return 0 } stop() { if [ -f $pidfile ]; then local pid=$(cat ${pidfile}) local pgid=$(ps ho pgid -p $pid | sed 's/\s//g') for target in $(ps h -g $pgid | sed 's/^\s\+//' | sed 's/\s\+/\t/g' | cut -f1) do kill $target done su - $username -c "${pidfile}" else echo "Mastodon streaming API dos'nt running..." exit 1 fi return 0 } case "$1" in start) start ;; stop) stop ;; *) echo $"Usage $prog {start|stop}" exit 2 esac exit 0
ä¸è¨ã/etc/init.d/
ã«é
ç½®ãããã以ä¸ãå®è¡ããã
sudo service mastodon-web start sudo chkconfig mastodon-web on sudo service mastodon-sidekiq start sudo chkconfig mastodon-sidekiq on sudo service mastodon-streaming start sudo chkconfig mastodon-streaming on
åèè³æ
CronJobã®ä½æ
RAILS_ENV=production @daily cd /home/mastodon/live && /home/mastodon/.rbenv/shims/bundle exec rake mastodon:daily > /dev/null
ãã©ãã«ã·ã¥ã¼ã
yarn installã§ãªããæ»ãã§ã
bufferutil
ãªãããã±ã¼ã¸ããã«ãã§ããã«æ»ãã§ããæ»ã¬ã¾ã§ç¼ãåããã¦ãããC++11ã³ã³ãã¤ã©ãè¦ã¤ãã£ã¦ãªãããã ã£ãã
gcc --version # gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18) g++ --version # g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18)
Software Collectionããææ°ã®DevToolset3ãå°å ¥ããã
sudo yum install devtoolset-3-gcc devtoolset-3-binutils
sudo yum install devtoolset-3-gcc-c++ devtoolset-3-gcc-gfortran
scl enable devtoolset-3 bash
ããã±ã¼ã¸ãå°å
¥ãããã³ã«scl enable
ãå®è¡ãããã¨ã§æå¹åã§ããã
ãããã·ã§ã«èµ·åææ¯åå¼ã³åºãã¨æ軽ãããã
# rootã«ãªã su - echo 'source /opt/rh/devtoolset-3/enable' >> /etc/profile.d/devtools.sh # rootãæãã exit
binutils
ã¨gfortran
ãããããããã
åèè³æ
CentOSã«æ°ãããã¼ã¸ã§ã³ã®GCC/G++(4.8/4.9)ãã¤ã³ã¹ãã¼ã«ãã - TASK NOTES http://www.task-notes.com/entry/20151114/1447492231
Devtoolset-3 â Software Collections https://www.softwarecollections.org/en/scls/rhscl/devtoolset-3/
SMTPãµã¼ãç¨æããã®ããã©ã
.env.production.sampleã«ãæ¸ãã¦ãã£ããã©ãSparkPost使ãã°ï¼ã¨ã®ãã¨ã
SendGridã使ç¨ãããã¨ã«ããã
ãããã® VPS + CentOS7 㧠俺å°ç¨ Mastodon ã¤ã³ã¹ã¿ã³ã¹ãç«ã¦ã¦ã¿ã話 | WWW WATCH https://hyper-text.org/archives/2017/04/mastodon-instance-single-user.shtml
PostgreSQLã®identèªè¨¼ãéããªãï¼
ããã®ããã§DBä½æãã§ããã«2æ¥ã»ã©ä½æ¥ãæ¢ã¾ã£ãã
mastodon userã§psql
ãå©ãã¨PostgreSQLã¯èµ·åããã
psql -h localhost
ã¨ããã¨ãidentèªè¨¼ãéãããã¾ããããªãã
# local local trust # IPv6 host ::128 ident # IPv4 host 127.0.0.1/32 ident
ãããå¥ã«localhostã®ããã«ä¸æ¦ãããã¯ã¼ã¯åºãå¿ è¦ãªããªãï¼
ã¨ãããã¨ã§.env.productionããDB_HOST
ã®å¤ããªããªã£ãã
S3ã«ãã¾ãã¢ãããã¼ãã§ããªã
åèè³æãå ã«é²ããã¨ãããS3ã¸ã®ã¢ãããã¼ãã§500ã¨ã©ã¼ãããã£ã¦ãããããã ãã¤ã³ãã¯å¤å以ä¸ã ã¨æãã
# æ±äº¬ãªã¼ã¸ã§ã³ã§ã®è¨å® S3_HOSTNAME=s3-ap-northeast-1.amazonaws.com # ENDPOINTãæè¨ããå ´åãhttps:// ãä»ãã¦ãã S3_ENDPOINT=https://s3-ap-northeast-1.amazonaws.com
æ
å ±æºãã¨ã«æ
å ±ããã¬ãã®ã¯ãMastodonã®ãã¼ã¸ã§ã³ã«ãã£ã¦æåãéã£ãã®ãããããªãã
ãã®æ
å ±ã¯ãMastodon 1.2.2
ã§ç¢ºèªãã¦ããã
åèè³æ
- SSLã§éç¨ãã¦ããmastodonã¨S3ã®é£æºã®ãããã©ãã - Qiita
- Mastodon ã¤ã³ã¹ã¿ã³ã¹ã®ç»åãåç»ã®ä¿åå ãã¯ã©ã¦ãã¹ãã¬ã¼ã¸ ï¼Amazon S3ï¼ ã«ç§»è¡ãã話 | WWW WATCH
èªåã§ã¢ãããã¼ãããã®ã¯S3ã«ä¸ãããããªã¢ã¼ããã©ãã¼ãã人ã®ã¢ã¤ã³ã³ã¨ãS3ã«ä¸ãããªã
S3è¨å®ã®æ´æ°ãããããSidekiqã®åèµ·åãå¿ è¦ã ã£ãã
ãªã¢ã¼ããã©ãã¼å¨ãã¯Sidekiq Workerãåãæã£ã¦ããã¦ãããS3è¨å®å¾ã«åèµ·åãå¿ããã¨ããã¼ã«ã«ã«ä¿åããè¨å®ã®ã¾ã¾ã«ãªã£ã¦ããã