installation - Setting up Redis on Webfaction -
what steps required set redis database on webfaction shared hosting account?
introduction
because of special environment restrictions of webfaction servers installation instructions not straightforward be. nevertheless @ end have functioning redis server stays after reboot. installed redis following procedure half year ago , has been running flawlessy since. little word of warning though, half year not long time, because server have not been under heavy use.
the instructions consists of 5 parts: installation, testing, starting server, managing server , keeping server running.
installation
login webfaction shell
ssh foouser@foouser.webfactional.com download latest redis redis download site.
> mkdir -p ~/src/ > cd ~/src/ > wget http://download.redis.io/releases/redis-2.6.16.tar.gz > tar -xzf redis-2.6.16.tar.gz > cd redis-2.6.16/ before make, see server linux 32 or 64 bit. installation script not handle 32 bit environments well, at least on webfaction's centos 5 machines. command bits uname -m. if linux 32 bit result i686, if 64 bit x86_64. see answer details.
> uname -m i686 if server 64 bit (x86_64) make.
> make but if server 32 bit (i686) must little stuff. there command make 32bit produces error. edit line in installation script make make 32bit work.
> nano ~/src/redis-2.6.16/src/makefile change line 214 this
$(make) cflags="-m32" ldflags="-m32" to this
$(make) cflags="-m32 -march=i686" ldflags="-m32 -march=i686" and save. run make 32bit flag.
> cd ~/src/redis-2.6.16/ ## note dir, no trailing src/ > make 32bit the executables created directory ~/src/redis-2.6.16/src/. executables include redis-cli, redis-server, redis-benchmark , redis-sentinel.
testing (optional)
as output of installation suggests, nice ensure works expected running tests.
hint: run 'make test' idea ;) unfortunately testing requires tlc8.6.0 installed not default @ least on machine web223. must install first, source. see tcl/tk installation notes , compiling notes.
> cd ~/src/ > wget http://prdownloads.sourceforge.net/tcl/tcl8.6.0-src.tar.gz > tar -xzf tcl8.6.0-src.tar.gz > cd tcl8.6.0-src/unix/ > ./configure --prefix=$home > make > make test # optional, see notes below > make install testing tcl make test take time , fail due webfaction's environment restrictions. suggest skip this.
now have tlc installed can run redis tests. tests take long time , temporarily uses quite large amount of memory.
> cd ~/src/redis-2.6.16/ > make test after tests ready continue.
starting server
first, create custom application via webfaction control panel (custom app (listening on port)). name example fooredis. note not have create domain or website app if redis used locally i.e. same host.
second, make note socket port number given app. let example 23015.
copy compiled executables app's directory. may choose copy or ones need.
> cd ~/webapps/fooredis/ > cp ~/src/redis-2.6.16/src/redis-server . > cp ~/src/redis-2.6.16/src/redis-cli . copy sample configuration file. modify that.
> cp ~/src/redis-2.6.16/redis.conf . now redis runnable. there couple problems though. first default redis port 6379 might in use. second, if port free, yes, start server stops running @ same moment exit shell. first redis.conf must edited , second, need daemon solved editing redis.conf.
redis able run in the daemon mode. need set place daemon stores process ids, pids. pidfiles stored in /var/run/ because environment restrictions must select place them in home directory. because reason explained later in part managing server, choice put pidfile under same directory executables. not have create file yourself, redis creates automatically.
now open redis.conf editing.
> cd ~/webapps/fooredis/ > nano redis.conf change configurations in following manner.
daemonize no->daemonize yespidfile /var/run/redis.pid->pidfile /home/foouser/webapps/fooredis/redis.pidport 6379->port 23015
now finally, start redis server. specify conf-file redis listens right port , runs daemon.
> cd ~/webapps/fooredis/ > ./redis-server redis.conf > see running.
> cd ~/webapps/fooredis/ > ./redis-cli -p 23015 redis 127.0.0.1:23015> set myfeeling phew. ok redis 127.0.0.1:23015> myfeeling "phew." redis 127.0.0.1:23015> (ctrl-d) > stop server if want to.
> ps -u $user -o pid,command | grep redis 718 grep redis 10735 ./redis-server redis.conf > kill 10735 or
> cat redis.pid | xargs kill managing server
for ease of use , preparatory work next part, make script helps open client , start, restart , stop server. easy solution write makefile. when writing makefile, remember use tabs instead of spaces.
> cd ~/webapps/fooredis/ > nano makefile # redis makefile client cli: ./redis-cli -p 23015 start restart: ./redis-server redis.conf stop: cat redis.pid | xargs kill the rules quite self-explanatory. special second rule while in daemon mode, calling ./redis-server not create new process if there 1 running already.
the third rule has quiet wisdom in it. if redis.pid not stored under directory of fooredis example /var/run/redis.pid not easy stop server. true if run multiple redis instances concurrently.
to execute rule:
> make start keeping server running
you have instance of redis running in daemon mode allows quit shell without stopping it. still not enough. if process crashes? if server machine rebooted? cover these have create 2 cronjobs.
> export editor=nano > crontab -e add following 2 lines , save.
*/5 * * * * make -c ~/webapps/fooredis/ -f ~/webapps/fooredis/makefile start @reboot make -c ~/webapps/fooredis/ -f ~/webapps/fooredis/makefile start the first 1 ensures each 5 minutes fooredis running. said above not start new process if 1 running. second 1 ensures fooredis started after server machine reboot , long before first rule kicks in.
some more deligate methods used, example forever. see webfaction community thread more topic.
conclusion
now have it. lots of things done maybe more come. things may in future not covered here includes following.
- setting password, preventing other users flushing databases. (see redis.conf)
- limiting memory usage (see redis.conf)
- logging usage , errors (see redis.conf)
- backupping data once in while.
any ideas, comments or corrections?
Comments
Post a Comment