目次
Macbookにて、mysql_multiで複数サーバを立てたので、その時のinstallメモ
目的は、dual master replication の failover動作確認をするため
Macにmysqlはinstall済みであることが前提
メモリを食うので、必要な時だけ起動するようにplistはunloadしておく
# 起動していたら停止
% sudo /opt/local/share/mysql5/mysql/mysql.server stop
% sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
# ここに入っている + pathは通しておく
% which mysql5
/opt/local/bin/mysql5
# エラーになるのでリンクを張っておく等
% sudo ln -s /opt/local/bin/my_print_defaults5 /opt/local/bin/my_print_defaults
% mkdir -p /Users/satoshi.tanaka/var/mysql1
% mkdir -p /Users/satoshi.tanaka/var/mysql2
% mkdir -p /Users/satoshi.tanaka/var/log
# ~/.my.cnf を準備, user名やportなどは適当に変更すること
% cat ~/.my.cnf
[mysqld_multi]
mysqld = /opt/local/lib/mysql5/bin/mysqld_safe
mysqladmin = /opt/local/lib/mysql5/bin/mysqladmin
user = root
[mysqld1]
server-id = 1
socket = /tmp/mysql1.sock
port = 13306
pid-file = /tmp/mysql1.pid
datadir = /Users/satoshi.tanaka/var/mysql1
language = /opt/local/share/mysql5/mysql/english
user = satoshi.tanaka
log = /Users/satoshi.tanaka/var/log/mysqld1.log
log-error = /Users/satoshi.tanaka/var/log/mysqld1.error.log
[mysqld2]
server-id = 2
socket = /tmp/mysql2.sock
port = 13307
pid-file = /tmp/mysql2.pid
datadir = /Users/satoshi.tanaka/var/mysql2
language = /opt/local/share/mysql5/mysql/english
user = satoshi.tanaka
log = /Users/satoshi.tanaka/var/log/mysqld2.log
log-error = /Users/satoshi.tanaka/var/log/mysqld2.error.log
# datadirの準備
% mysql_install_db5 --datadir=./var/mysql1/
% mysql_install_db5 --datadir=./var/mysql2/
# 起動して確認
% /opt/local/bin/mysqld_multi5 start --log=/tmp/mysqld_multi.log
% /opt/local/bin/mysqld_multi5 report --log=/tmp/mysqld_multi.log
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
% mysql5 -S /tmp/mysql2.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.63-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Macbookにて、Javascript実行環境を整えたので、その際の手順履歴
Rhino = Java実装のJavascript実行環境
その他の言語のJava実装は以下のものがある
Jython - port of Python.
JRuby - port of Ruby.
Rhino - port of ECMAScript.
Clojure - Lisp dialect.
Groovy - Scripting language for the JVM.
Scala - object-oriented, functional language for the JVM.
Macにinstallするには、brew installで一発。
2012/03/12 時点でinstallされるversionは1.7R3
brew install rhino
実行するには以下のjarを指定する。-eでコードを直接渡す。
% java -jar /usr/local/Cellar/rhino/1.7R3/libexec/js.jar -e "print('hello world!');"
java -jar /usr/local/Cellar/rhino/1.7R3/libexec/js.jar -e "print('hello worldjava -jar /usr/local/Cellar/rhino/1.7R3/libexec/js.jar');"
hello worldjava -jar /usr/local/Cellar/rhino/1.7R3/libexec/js.jar
%
インタラクティブシェルは以下の通りに実行できる
% java -jar /usr/local/Cellar/rhino/1.7R3/libexec/js.jar
Rhino 1.7 release 3 2011 05 09
js> print('hello world!');
hello world!
js>
こちらもJavascript実行環境。実装はV8だったりSpiderMondkeyだったり。
同じく、brew installにて。
% brew install node
npmと単体テストフレームワークもついでにinstall
% git clone git://github.com/creationix/nvm.git ~/.nvm
% nvm install v0.6.12
% nvm alias default v0.6.12
% source ~/.nvm/nvm.sh
% curl http://npmjs.org/install.sh | sh
% npm install nodeunit
% ln -s $HOME/.npm/nodeunit/0.7.4/package/bin/nodeunit $HOME/bin/nodeunit
以下のようなことを考えた
% mkdir /tmp/py27
% cd /tmp/py27
% (buildout.cfg + bootstrap.pyを用意)
% cat buildout.cfg
[buildout]
python = python
parts =
python
env
[python]
recipe = zc.recipe.cmmi
url = http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
executable = ${buildout:parts-directory}/python/bin/python2.7
environment =
LDFLAGS=-Wl,-rpath,${buildout:parts-directory}/python/lib
extra_options =
--enable-unicode=ucs4
--enable-shared
--with-threads
[env]
recipe = zc.recipe.egg
eggs =
virtualenv
virtualenvwrapper
interpreter = python
% python bootstrap.py
% bin/buildout
% export WORKON_HOME=/tmp/virtualenvs
% export VIRTUALENVWRAPPER_HOOK_DIR=/tmp/virtualenvs
% export VIRTUALENVWRAPPER_LOG_DIR=/tmp/virtualenvs
## FIXME: クリーンな環境でうまくいくか?
% mkvirtualenv -p /tmp/py27/parts/python/bin/python testenv
% /tmp/virtualenvs/testenv/bin/pip install Flask
% /tmp/virtualenvs/testenv/bin/pip install gunicorn
% /tmp/virtualenvs/testenv/bin/pip install supervisor
% cat myserver.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "<h1>hello!Yes!</h1>"
if __name__ == '__main__':
app.run(debug=True)
% /tmp/virtualenvs/testenv/bin/python myserver.py
* Running on http://127.0.0.1:5000/
* Restarting with reloader
cpでinstallしないほうがいい(暫定手順)
% sudo mkdir /tmp/virtualenvs/testenv/lib/python2.7/site-packages/mypj
% touch /tmp/virtualenvs/testenv/lib/python2.7/site-packages/mypj/__init__.py
% sudo cp myserver.py /tmp/virtualenvs/testenv/lib/python2.7/site-packages/mypj/
本当はdaemonモード
% /tmp/virtualenvs/testenv/bin/gunicorn mypj.myserver:app