Skip to content

Instantly share code, notes, and snippets.

@htcang
Last active May 8, 2016 15:31
Show Gist options
  • Select an option

  • Save htcang/3b1221d9ba8efdb0dcf2 to your computer and use it in GitHub Desktop.

Select an option

Save htcang/3b1221d9ba8efdb0dcf2 to your computer and use it in GitHub Desktop.
Install Redis server on Centos 6 - Add redis service on Centos 6

Redis 3

sudo yum update
sudo yum groupinstall 'Development Tools' -y
sudo yum install wget -y
wget http://download.redis.io/releases/redis-3.2.0.tar.gz
tar -zxf redis-3.2.0.tar.gz
cd redis-3.2.0
sudo make
sudo make install
sudo mkdir /etc/redis /var/redis
sudo cp utils/redis_init_script /etc/init.d/redis_6379
sudo vi /etc/init.d/redis_6379

Make sure to modify REDIS_PORT accordingly to the port you are using. Both the pid file path and the configuration file name depend on the port number.

Add these lines before REDIS_PORT:

# chkconfig: 345 99 01
# description: Redis startup script

REDISPORT=6379

Continue

sudo cp redis.conf /etc/redis/6379.conf
sudo mkdir /var/redis/6379

Edit the configuration file sudo vi /etc/redis/6379.conf, making sure to perform the following changes:

  • Set daemonize to yes (by default it is set to no).
  • Set the pidfile to /var/run/redis_6379.pid (modify the port if needed).
  • Change the port accordingly. In our example it is not needed as the default port is already 6379.
  • Set your preferred loglevel.
  • Set the logfile to /var/log/redis_6379.log
  • Set the dir to /var/redis/6379 (very important step!)
chkconfig --add redis_6379
chkconfig redis_6379 on
service redis_6379 start

As of Redis recommendation:

  • enable vm.overcommit_memory:
vi /etc/sysctl.conf

add this line

vm.overcommit_memory = 1

reboot or run sysctl vm.overcommit_memory=1 to apply the change.

  • Disable linux hugepage feature by adding these line in /etc/rc.local
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
   echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi

Run source /etc/rc.local then test if it work by running

cat /sys/kernel/mm/transparent_hugepage/enabled

The result should be: always madvise [never]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment