Hello. This is Komiya from OPS.
I asked you to install the redis source and CHEF-SOLO, so I will record it.
★ Requirements
Please use 2.8.4 for the version. (Latest source as of 2014/1)
★ The following tasks
・Check the version that enters by rpm (*Check with yum on the server in the same environment)
redis.x86_64 0:2.4.10-1.el6
*Source installation is required because it does not meet the requirements.
・Preparation for chef-solo
[shell]$ ssh-copy-id -i ~/.ssh/id_dsa.pub server2 $ ssh-copy-id -i ~/.ssh/id_dsa.pub server1
$ knife solo prepare server1 $ knife solo prepare server2[/shell]
・Role creation
[shell]$ vi roles/rankingAPI.json { "name":"rankingAPI", "chef_type": "role", "json_class":"Chef::Role", "default_attributes":{ "base_setting": { "swappiness": "0", "tcp_tw_ reuse": "0", "tcp_tw_recycle": "0", "tcp_fin_timeout": "10", "tcp_max_syn_backlog": "8192", "somaxconn": "8192", "ntpserver1": "ntp.nict.jp" } }, "override_attributes":{}, " description":"rankingAPI's role", "run_list": [ "recipe[roles::rankingAPI]" ] }
$ vi site-cookbooks/roles/recipes/rankingAPI.rb include_recipe "base_setting::common-pkgs" include_recipe "base_setting::sysctl" include_recipe "base_setting::ntpd" #include_recipe "base_setting::rps_cpus" include_recipe "login-users::create_user" include_recipe "login-users::key_copy" #include_recipe "java::java" #include_ recipe "nginx::nginx" #include_recipe "play::play" #include_recipe "mysqld::mysql-client" #include_recipe "git::git" include_recipe "redis::redis"[/shell]
*Recipes that are not subject to work have been commented out for now.
・node editing
[shell]$ vi nodes/server1.json $ vi nodes/server2.json { "run_list":[ "role[rankingAPI]" ] }[/shell]
・Cookbook creation
[shell]$ cd ~/chef-repo $ knife cookbook create redis -o site-cookbooks[/shell]
・Prepare the necessary files, deta_bags, and recipes
[shell]$ mkdir -p site-cookbooks/redis/files/default/usr/local/src $ cd site-cookbooks/redis/files/default/usr/local/src $ wget http://download.redis.io/releases/redis-2.8.4.tar.gz $ cd ~/chef-repo $ knife solo data bag create pkg_versions redis { "id": "redis", "version": "2.8.4" } $ knife solo data bag edit pkg_ versions redis
$ vim site-cookbooks/redis/recipes/redis.rb ---------------------------------------- version = data_bag_item('pkg_versions','redis')['version'] redis_pkg="redis-#{ version}" cookbook_file "/usr/local/src/#{redis_pkg}.tar.gz" do not_if "ls /usr/local/src/#{redis_pkg}.tar.gz" source "usr/local/src/#{redis_pkg}.tar.gz" end
%W{tcl make gcc}.each do |pkg| package pkg do action :install not_if "'rpm -qa|grep #{pkg}" end end
bash "redis-install" do not_if "which redis-cli" code <-EOC cd="" sr/local/src="" tar="" zxf="" #{redis_pkg}.tar.gz="" cd="" #{redis_pkg}="" make="" -j="" &&="" make="" install="" eoc="" end="" directory="" "/etc/redis"="" do="" not_if="" "ls="" tc/redis"="" mode="" 0755="" action="" :create="" recursive="" false="" end="" directory="" "/usr/local/redis"="" do="" not_if="" "ls="" sr/local/redis"="" mode="" 0755="" action="" :create="" recursive="" false="" end="" cookbook_file="" "/etc/init.d/redis"="" do="" source="" "/etc/init.d/redis"="" mode="" 0754="" end="" cookbook_file="" "/etc/redis/6379.conf"="" do="" source="" "etc/redis/6379.conf"="" mode="" 0644="" notifies="" :restart,="" 'service[redis]'="" end="" cookbook_file="" "/etc/logrotate.d/redis"="" do="" source="" "etc/logrotate.d/redis"="" mode="" 0644="" end="" service="" "redis"="" do="" not_if="" "ps="" -ef|grep="" redis|grep="" -v="" grep"="" supports="" :status=""> true, :restart => true action [ :enable, :start ] end ----------------------------------------
$ knife cookbook test redis
$ sudo cp -p utils/redis_init_script /etc/init.d/redis $ diff /etc/init.d/redis /usr/local/src/redis-2.8.4/utils/redis_init_script 5,9d4 < # chkconfig: - 85 15 < # description: redis-server < # processname: redis < < . /etc/rc.d/init.d/functions 14d8 < prog=$(basename $EXEC) 15a10 > PIDFILE=/var/run/redis_${REDISPORT}.pid 17d11 < PIDFILE=`grep pidfile ${CONF} |awk '{print $2}'` 19c13,14 < start() { --- > case "$1" in > start) 26,27d20 < sleep 2 < echo -100 > /proc/`cat $PIDFILE`/oom_score_adj 29,30c22,23 < } < stop() { --- > ;; > stop) 45,60d37 < } < < rh_status() { < status $prog < } < < case "$1" in < start) < start < ;; < stop) < stop < ;; < restart) < stop < start 62,64d38 < status) < rh_status < ;;
$ mkdir -p site-cookbooks/redis/files/default/etc/init.d $ vim site-cookbooks/redis/files/default/etc/init.d/redis ---------------------------------------- #!/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. # chkconfig: - 85 15 # description: redis-server # processname: redis
. /etc/rc.d/init.d/functions
REDISPORT=6379 EXEC=/usr/local/bin/redis-server CLIEXEC=/usr/local/bin/redis-cli prog=$(basename $EXEC)
CONF="/etc/redis/${REDISPORT}.conf" PIDFILE=`grep pidfile ${CONF} |awk '{print $2}'`
start() { if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." $EXEC $CONF sleep 2 echo -100 > /proc/`cat $PIDFILE`/oom_score_adj fi } stop() { if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $CLIEXEC -p $ REDISPORT shutdown while [ -x /proc/${PID} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi }
rh_status() { status $prog }
case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) rh_status ;; *) echo "Please use start or stop as first argument" ;; esac ----------------------------------------[/shell] has been modified so that it can be added to chkconfig, restart and status, and oom_killer countermeasures and PIDs are read from config.
It seemed that if you can't restart or status, you can't start it with the service resource on the chef side.
The startup script included in the source package did not seem to be for rh OS.
[shell]cd site-cookbooks/redis/files/default/usr/local/src $ tar xf redis-2.8.4.tar.gz redis-2.8.4/redis.conf mkdir -p ~/chef-repo/site-cookbooks/redis/files/default/etc/ redis cp -p redis-2.8.4/redis.conf ~/chef-repo/site-cookbooks/redis/files/default/etc/redis/6379.conf vi ~/chef-repo/site-cookbooks/redis/files/default/etc/redis/6379.conf $ diff ~/chef-repo/site-cookbooks/redis/files/default/etc/redis/6379.conf redis-2.8.4/redis.conf 37c37 < daemonize yes --- > daemonize no 94c94 < logfile "/var/log/redis.log" --- > logfile "" 178,179c178 < #dir ./ < dir /usr/local/redis --- > dir ./
$ cd ~/chef-repo $ mkdir -p site-cookbooks/redis/files/default/etc/logrotate.d/ $ vi site-cookbooks/redis/files/default/etc/logrotate.d/redis /var/log/redis.log { weekly missingok copytruncate rotate 12 compress notifempty }[/shell]
・Recipe application
[shell]$ knife solo cook server1 $ knife solo cook server2[/shell]
・Confirmation (after SSH)
[shell]$ logrotate -d /etc/logrotate.d/redis $ ps -ef|grep redis $ netstat -lnpt $ sudo service redis status redis-server (pid 21560) is running... $ redis-cli $ cat /proc/`cat /var/run/ redis.pid`/oom_score_adj -100 $ tail /etc/sysctl.conf $ ll /home $ sudo su - $ sudo ls -lha /home/*/.ssh/ $ ntpq -p[/shell]
・Reference
Redis installation on Sakura VPS (CentOS 6.3) and registration in chkconfig - Enta no Record Redis 2.2.12 Installation Notes (amazon Linux) - developer's diarySteps to Introduce Redis to CentOS/Mac OSX - memcache-like Key-Value method and persistence-compatible in-memory DB - Sake and tears, Ruby and Rails
[[CentOS]redis installation - Qiita[Keita]] (http://qiita.com/sora083/items/a3b7e754cfaffdb9a51c)
[Notes from various things I tried to use Redis - Qiita [Keita]] (http://qiita.com/A-gen/items/345c07d830205a7ea6cb)
redis-debian/src/etc/logrotate.d/redis-server at master · mpillar/redis-debian · GitHubDownload –Don't Get Killed by Redis OOM Killer - Practice Now! Linux System Management / Vol.238
Thank you for watching the above.
</-EOC>