1. 程式人生 > >centos6.5編譯安裝LNMP環境

centos6.5編譯安裝LNMP環境

安裝編譯工具及庫檔案

yum install -y  yasm apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel
libpng libpng* libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libX* libtiff libtiff* make mpfr ncurses* ntp openssl nasm nasm* openssl-devel patch pcre-devel perl php-common php-gd policycoreutils ppl telnet t1lib t1lib* wget zlib-devel

配置埠

[root@localhost vagrant]vi /etc/sysconfig/iptables 

貼上如下:

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT

重啟使生效

[root@localhost vagrant]#service iptables restart 

檢視已開啟的埠

[root@localhost vagrant]# /etc/init.d/iptables status

關閉SELINUX

[root@localhost vagrant]# vi /etc/selinux/config

註釋掉:

SELINUXTYPE=targeted 

新增:

SELINUX=disabled 

關閉selinux防火牆:

[root@localhost vagrant]# setenforce 0 

系統約定

軟體原始碼包存放位置:/usr/local/src
原始碼包編譯安裝位置:/usr/local/軟體名字

下載軟體包

1、下載nginx

[root@localhost src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz

2、下載MySQL

[root@localhost src]# wget  http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.21.tar.gz

3、下載php

[root@localhost src]# wget http://cn2.php.net/distributions/php-5.6.3.tar.gz

4、下載pcre (支援nginx偽靜態)

[root@localhost src]# wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.36/pcre-8.36.tar.gz

5、下載openssl(nginx擴充套件)

[root@localhost src]# wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz

6、下載zlib(nginx擴充套件)

[root@localhost src]# wget zlib.net/fossils/zlib-1.2.8.tar.gz

7、下載cmake(MySQL編譯工具)

[root@localhost src]# wget http://www.cmake.org/files/v3.0/cmake-3.0.2.tar.gz

8、下載libmcrypt(php擴充套件)

[root@localhost src]# wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

9、下載yasm(php擴充套件)

[root@localhost src]# wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz

10、t1lib(php擴充套件)

http://download.csdn.net/download/sunkaivg/9696064

11、下載gd庫安裝包

http://download.csdn.net/detail/long712905/9391234

12、libvpx(gd庫需要)

http://download.csdn.net/download/huaweichina/8485159

13、tiff(gd庫需要)

http://download.csdn.net/download/damys/9326943

14、libpng(gd庫需要)

http://download.csdn.net/download/damys/9326857

15、freetype(gd庫需要)

[root@localhost src]# wget http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/freetype-2.5.4.tar.gz

16、jpegsrc(gd庫需要)

[root@localhost src]# wget http://www.ijg.org/files/jpegsrc.v9a.tar.gz

安裝MySQL

1、安裝cmake

[root@localhost vagrant]# cd /usr/local/src/
[root@localhost src]# tar zxvf cmake-3.0.2.tar.gz
[root@localhost src]# cd cmake-3.0.2
[root@localhost cmake-3.0.2]# ./configure
[root@localhost cmake-3.0.2]# make
[root@localhost cmake-3.0.2]# make install

2、安裝MySQL

[root@localhost cmake-3.0.2]# cd /usr/local/src/
[root@localhost src]# groupadd mysql #新增mysql組
[root@localhost src]# useradd -g mysql mysql -s /bin/false #建立使用者mysql並加入到mysql組,不允許mysql使用者直接登入系統
[root@localhost src]# mkdir -p /data/mysql #建立MySQL資料庫存放目錄
[root@localhost src]# chown -R mysql:mysql /data/mysql #設定MySQL資料庫存放目錄許可權
[root@localhost src]# mkdir -p /usr/local/mysql #建立MySQL安裝目錄
[root@localhost src]# tar zxvf mysql-5.6.21.tar.gz
[root@localhost src]# cd mysql-5.6.21
[root@localhost mysql-5.6.21]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc #配置
[root@localhost mysql-5.6.21]# make 
[root@localhost mysql-5.6.21]# make install
[root@localhost mysql-5.6.21]# rm -rf /etc/my.cnf #刪除系統預設的配置檔案
[root@localhost mysql-5.6.21]# cd /usr/local/mysql #進入MySQL安裝目錄
[root@localhost mysql-5.6.21]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql #生成mysql系統資料庫
[root@localhost mysql-5.6.21]# ln -s /usr/local/mysql/my.cnf /etc/my.cnf #新增到/etc目錄的軟連線
[root@localhost mysql-5.6.21]#  cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系統啟動
[root@localhost mysql-5.6.21]# chmod 755 /etc/init.d/mysqld #增加執行許可權
[root@localhost mysql-5.6.21]# chkconfig mysqld on #加入開機啟動
[root@localhost mysql-5.6.21]#  vi /etc/rc.d/init.d/mysqld 
#檔案內容新增如下:
    basedir=/usr/local/mysql #MySQL程式安裝路徑
    datadir=/data/mysql #MySQl資料庫存放目錄

[root@localhost mysql-5.6.21]# service mysqld start #啟動
[root@localhost mysql-5.6.21]# vi /etc/profile 
#把mysql服務加入系統環境變數:在最後新增下面這一行:
    export PATH=$PATH:/usr/local/mysql/bin
[root@localhost mysql-5.6.21]# source /etc/profile #使配置立刻生效
[root@localhost mysql]# mysql_secure_installation #設定Mysql密碼

#下面這幾行把myslq的庫檔案連結到系統預設的位置,這樣你在編譯類似PHP等軟體時可以不用指定mysql的庫檔案地址:
[root@localhost mysql]# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
[root@localhost mysql]# ln -s /usr/local/mysql/include/mysql /usr/include/mysql
[root@localhost mysql]# mkdir /var/lib/mysql #建立目錄
[root@localhost mysql]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock 

安裝Nginx

1、安裝pcre

[root@localhost mysql]# cd /usr/local/src
[root@localhost src]# mkdir /usr/local/pcre
[root@localhost src]# tar zxvf pcre-8.36.tar.gz
[root@localhost src]# cd pcre-8.36
[root@localhost pcre-8.36]# ./configure --prefix=/usr/local/pcre
[root@localhost pcre-8.36]# make
[root@localhost pcre-8.36]# make install

2、安裝openssl

[root@localhost pcre-8.36]# cd /usr/local/src
[root@localhost src]# mkdir /usr/local/openssl
[root@localhost src]# tar zxvf openssl-1.0.1j.tar.gz
[root@localhost src]# cd openssl-1.0.1j
[root@localhost openssl-1.0.1j]# ./config --prefix=/usr/local/openssl
[root@localhost openssl-1.0.1j]# make
[root@localhost openssl-1.0.1j]# make install
[root@localhost openssl-1.0.1j]# vi /etc/profile
    export PATH=$PATH:/usr/local/openssl/bin#新增

3、安裝zlib

[root@localhost openssl-1.0.1j]# cd /usr/local/src
[root@localhost src]# mkdir /usr/local/zlib
[root@localhost src]# tar zxvf zlib-1.2.8.tar.gz
[root@localhost src]# cd zlib-1.2.8
[root@localhost zlib-1.2.8]# ./configure --prefix=/usr/local/zlib
[root@localhost zlib-1.2.8]# make
[root@localhost zlib-1.2.8]# make install

4、安裝Nginx

[[email protected] zlib-1.2.8]# cd /usr/local/src/
[[email protected] src]# groupadd www
[[email protected] src]# useradd -g www www -s /bin/false
[[email protected] src]# tar zxvf nginx-1.6.2.tar.gz
[[email protected] src]# cd nginx-1.6.2
[[email protected] nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36
#注意:--with-openssl=/usr/local/src/openssl-1.0.1j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36指向的是原始碼包解壓的路徑,而不是安裝的路徑,否則會報錯
[[email protected] nginx-1.6.2]# make
[[email protected] nginx-1.6.2]# make install
[[email protected] nginx-1.6.2]# /usr/local/nginx/sbin/nginx #啟動Nginx

#設定nginx開機啟動,新增到系統服務
[[email protected] /]# vi /etc/init.d/nginx 
##新增如下程式碼
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#  It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "

   daemon $nginxd -c ${nginx_config}

   RETVAL=$?

   echo

   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx

   return $RETVAL

}

# Stop nginx daemons functions.

stop() {

        echo -n $"Stopping $prog: "

        killproc $nginxd

        RETVAL=$?

        echo

        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid

}

# reload nginx service functions.

reload() {

    echo -n $"Reloading $prog: "

    #kill -HUP `cat ${nginx_pid}`

    killproc $nginxd -HUP

    RETVAL=$?

    echo

}

# See how we were called.

case "$1" in

start)

        start

        ;;

stop)

        stop

        ;;

reload)

        reload

        ;;

restart)

        stop

        start

        ;;

status)

        status $prog

        RETVAL=$?

        ;;

*)

        echo $"Usage: $prog {start|stop|restart|reload|status|help}"

        exit 1

esac

exit $RETVAL



[[email protected] /]# chkconfig --add /etc/init.d/nginx
[[email protected] /]# chmod 755 /etc/init.d/nginx
[[email protected] /]# chkconfig --add nginx
[[email protected] /]# chkconfig nginx on
#訪問

這裡寫圖片描述

安裝php

1、安裝yasm

[root@localhost vagrant]# cd /usr/local/src
[root@localhost src]# tar zxvf yasm-1.3.0.tar.gz
[root@localhost src]# cd yasm-1.3.0
[root@localhost yasm-1.3.0]# ./configure
[root@localhost yasm-1.3.0]# make
[root@localhost yasm-1.3.0]# make install

2、安裝libmcrypt

[root@localhost yasm-1.3.0]# cd /usr/local/src
[root@localhost src]# tar zxvf libmcrypt-2.5.8.tar.gz
[root@localhost src]# cd libmcrypt-2.5.8
[root@localhost libmcrypt-2.5.8]# ./configure
[root@localhost libmcrypt-2.5.8]# make
[root@localhost libmcrypt-2.5.8]# make install

3、安裝libvpx

[root@localhost libmcrypt-2.5.8]# cd /usr/local/src
[root@localhost src]# tar xvf libvpx-v1.3.0.tar.bz2
[root@localhost src]# cd libvpx-v1.3.0
[root@localhost libvpx-v1.3.0]# ./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9
[root@localhost libvpx-v1.3.0]# make
[root@localhost libvpx-v1.3.0]# make install

4、安裝tiff

[root@localhost libvpx-v1.3.0]# cd /usr/local/src
[root@localhost src]# tar zxvf tiff-4.0.3.tar.gz
[root@localhost src]# cd tiff-4.0.3
[root@localhost tiff-4.0.3]# ./configure --prefix=/usr/local/tiff --enable-shared
[root@localhost tiff-4.0.3]# make
[root@localhost tiff-4.0.3]# make install

5、安裝libpng

[root@localhost tiff-4.0.3]# cd /usr/local/src
[root@localhost src]# tar zxvf libpng-1.6.16.tar.gz
[root@localhost src]# cd libpng-1.6.16
[root@localhost libpng-1.6.16]# ./configure --prefix=/usr/local/libpng --enable-shared
[root@localhost libpng-1.6.16]# make
[root@localhost libpng-1.6.16]# make install

6、安裝freetype

[root@localhost libpng-1.6.16]# cd /usr/local/src
[root@localhost src]# tar zxvf freetype-2.5.4.tar.gz
[root@localhost src]# cd freetype-2.5.4
[root@localhost freetype-2.5.4]# ./configure --prefix=/usr/local/freetype --enable-shared
[root@localhost freetype-2.5.4]# make
[root@localhost freetype-2.5.4]# make install 

7、安裝jpeg

[root@localhost vagrant]# cd /usr/local/src
[root@localhost src]# tar zxvf jpegsrc.v9a.tar.gz
[root@localhost src]# cd jpeg-9a
[root@localhost jpeg-9a]# ./configure --prefix=/usr/local/jpeg --enable-shared
[root@localhost jpeg-9a]# make 
[root@localhost jpeg-9a]# make  install

8、安裝libgd

[[email protected] jpeg-9a]# cd /usr/local/src
[[email protected] src]# tar zxvf libgd-2.1.0.tar.gz 
[[email protected] src]# cd libgd-2.1.0
[[email protected] libgd-2.1.0]# ./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-vpx=/usr/local/libvpx
[[email protected] libgd-2.1.0]# make 
[[email protected] libgd-2.1.0]# make install 

9、安裝t1lib

[root@localhost libgd-2.1.0]# cd /usr/local/src
[root@localhost src]# tar zxvf t1lib-5.1.2.tar.gz
[root@localhost src]# cd t1lib-5.1.2
[root@localhost t1lib-5.1.2]# ./configure --prefix=/usr/local/t1lib --enable-shared
[root@localhost t1lib-5.1.2]# make without_doc
[root@localhost t1lib-5.1.2]# make install

10、安裝php

注意:如果系統是64位,請執行以下兩條命令,否則安裝php會出錯(32位系統不需要執行)

# cp -frp /usr/lib64/libltdl.so*  /usr/lib/
# cp -frp /usr/lib64/libXpm.so* /usr/lib/

[root@localhost t1lib-5.1.2]# cd /usr/local/src
[root@localhost src]# tar -zvxf php-5.6.3.tar.gz
[root@localhost src]# cd php-5.6.3
[root@localhost src]# export LD_LIBRARY_PATH=/usr/local/libgd/lib
[root@localhost php-5.6.3]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctype 
[root@localhost php-5.6.3]# make 
[root@localhost php-5.6.3]# make install
[root@localhost php-5.6.3]# cp php.ini-production /usr/local/php/etc/php.ini  #複製php配置檔案到安裝目錄
[root@localhost php-5.6.3]# rm -rf /etc/php.ini
[root@localhost php-5.6.3]# ln -s /usr/local/php/etc/php.ini /etc/php.ini #新增軟連結到 /etc目錄
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #拷貝模板檔案為php-fpm配置檔案
[root@localhost php-5.6.3]# ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf #新增軟連線到 /etc目錄
[root@localhost php-5.6.3]# vi /etc/php-fpm.conf
    #編輯如下
    user = www #設定php-fpm執行賬號為www
    group = www #設定php-fpm執行組為www
    pid = run/php-fpm.pid #取消前面的分號

#設定 php-fpm開機啟動
[root@localhost php-5.6.3]# cp /usr/local/src/php-5.6.3/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷貝php-fpm到啟動目錄
[root@localhost php-5.6.3]# chmod +x /etc/rc.d/init.d/php-fpm #新增執行許可權
[root@localhost php-5.6.3]# chkconfig php-fpm on #設定開機啟動

##新增到全域性環境變數##
[root@localhost /]# vi /etc/profile
    ##編輯如下:
    export PATH=$PATH:/usr/local/mysql/bin:/usr/local/openssl/bin:/usr/local/php/bin
[root@localhost /]# source /etc/profile

[root@localhost php-5.6.3]# vi /usr/local/php/etc/php.ini 
    #編輯如下
    #1、列出PHP可以禁用的函式
    找到:disable_functions =
    修改為:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
    #2、設定時區
    找到:;date.timezone =
    修改為:date.timezone = PRC 
    #3、禁止顯示php版本的資訊
    找到:expose_php = On
    修改為:expose_php = Off 
    #3、支援opcode快取
    找到opcache.enable=0
    修改為opcache.enable=1 
    在最後一行新增:zend_extension=opcache.so #開啟opcode快取功能
    #4、開啟報錯
     display_errors= On
     error_reporting=E_ALL

11、配置Nginx支援PHP

[root@localhost php-5.6.3]# vi /usr/local/nginx/conf/nginx.conf  
    #編輯如下:
    # 1、設定user
    user www www; #首行user去掉註釋,修改Nginx執行組為www www;必須與/usr/local/php/etc/php-fpm.conf中的user,group配置相同,否則php執行出錯
    #2、設定支援php檔案格式
    index index.html index.htm index.php; #新增index.php
    #3、取消FastCGI server部分location的註釋,
    location ~ \.php$ {
    root html;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    #注意fastcgi_param行的引數,改為$document_root$fastcgi_script_name,或者使用絕對路徑

[root@localhost php-5.6.3]# /etc/init.d/nginx restart #重啟nginx
[root@localhost vagrant]# service php-fpm start #啟動php-fpm

測試

[root@localhost vagrant]# cd /usr/local/nginx/html/ #進入nginx預設網站根目錄
[root@localhost html]# rm -rf  * #刪除預設測試頁
[root@localhost html]# vi index.php 
    <?php
        phpinfo();
    ?>
[root@localhost html]#  chown www.www /usr/local/nginx/html/ -R #設定目錄所有者
[root@localhost html]#  chmod 700 /usr/local/nginx/html/ -R #設定目錄許可權

在瀏覽器輸入網址訪問:
這裡寫圖片描述

安裝配置redis

1、安裝redis

#安裝依賴庫
[root@localhost src]# yum -y install tcl
[root@localhost src]# wget http://download.redis.io/releases/redis-4.0.2.tar.gz
[root@localhost src]# tar -zxvf   redis-4.0.2.tar.gz 
[root@localhost src]# cd redis-4.0.2
[root@localhost src]# make
[root@localhost src]# make PREFIX=/usr/local/redis install

2、配置redis

[root@localhost redis-4.0.2]# cd /usr/local/redis/
[root@localhost redis]# cp /usr/local/src/redis-4.0.2/redis.conf  ./
#編輯配置檔案

#修改如下:
daemonize yes
#bind 127.0.0.1

3、安裝php的redis擴充套件

[[email protected] src]# [[email protected] src]# unzip phpredis-php7.zip  
[[email protected] src]# [[email protected] src]# cd phpredis-php7
#用phpize生成configure配置檔案
[[email protected] phpredis-2.2.4]# /usr/local/php/bin/phpize
[[email protected] phpredis-php7]# ./configure --with-php-config=/usr/local/php/bin/php-config
[[email protected] phpredis-php7]# make 
[[email protected] phpredis-php7]# make install
#編輯配置檔案,在最後一行新增以下內容:
extension=redis.so
#設定redis開機啟動
[[email protected] vagrant]# vi /etc/init.d/redis 
#新增如下內容:
###########################
    # chkconfig:   2345 90 10
    # description:  Redis is a persistent key-value database

    PATH=/usr/local/bin:/sbin:/usr/bin:/bin

    REDISPORT=6379
    EXEC=/usr/local/redis/bin/redis-server
    REDIS_CLI=/usr/local/redis/bin/redis-cli

    PIDFILE=/var/run/redis.pid
    CONF="/usr/local/redis/redis.conf"

    case "$1" in
        start)
            if [ -f $PIDFILE ]
            then
                    echo "$PIDFILE exists, process is already running or crashed"
            else
                    echo "Starting Redis server..."
                    $EXEC $CONF
            fi
            if [ "$?"="0" ]
             then
                  echo "Redis is running..."
            fi
            ;;
        stop)
            if [ ! -f $PIDFILE ]
            then
                    echo "$PIDFILE does not exist, process is not running"
            else
                    PID=$(cat $PIDFILE)
                    echo "Stopping ..."
                    $REDIS_CLI -p $REDISPORT SHUTDOWN
                    while [ -x ${PIDFILE} ]
                   do
                        echo "Waiting for Redis to shutdown ..."
                        sleep 1
                    done
                    echo "Redis stopped"
            fi
            ;;
       restart|force-reload)
            ${0} stop
            ${0} start
              ;;
      *)
        echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
            exit 1
    esac
 ###################


[[email protected] vagrant]# chmod +x /etc/init.d/redis 
[[email protected] vagrant]# chkconfig redis on