环境描述:
192.168.30.131 Nginx-proxy.test.com
192.168.30.132 Apache1.test.com
192.168.30.133 Apache2.test.com
192.168.30.134 redis.test.com
192.168.30.135 MySQL.test.com
首先在Apache1和Apache2上部署Apache+Php:
1>【卸载系统自带的apache】
[html] view plain copy
-
#查看apache是否己安装
-
rpm -qa httpd
-
#卸载
-
rpm -e httpd --nodeps
2>【安装gcc, gcc-c++】
[html] view plain copy
-
yum install gcc
-
yum install gcc-c++
3>【开放80、3306、22端口】
[html] view plain copy
-
#关闭防火墙
-
service iptables stop
-
vi /etc/sysconfig/iptables
-
#添加
-
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -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 22 -j ACCEPT
-
#重启防火墙
-
service iptables restart
4>【建立lamp/src目录, 将源码包上传】5>【安装libxml2】
[html] view plain copy
-
tar -zxvf libxml2-2.6.30.tar.gz
-
cd libxml2-2.6.30
-
./configure --prefix=/usr/local/libxml2
-
make
-
make install
6>【安装libmcrypt】
[html] view plain copy
-
tar -zxvf libmcrypt-2.5.8.tar.gz
-
cd libmcrypt-2.5.8
-
./configure --enable-ltdl-install
-
make
-
make install
7>【安装zlib】
[html] view plain copy
-
tar -zxvf zlib-1.2.3.tar.gz
-
cd zlib-1.2.3
-
./configure
-
make
-
make install
8>【安装libpng】
[html] view plain copy
-
tar -zxvf libpng-1.2.31.tar.gz
-
cd libpng-1.2.31
-
./configure --prefix=/usr/local/libpng
-
make
-
mkdir -p /usr/loca/libpng/man/man1
-
make install
9>【安装jpegsrc.v6b】
[html] view plain copy
-
mkdir /usr/local/jpeg6
-
mkdir /usr/local/jpeg6/bin
-
mkdir /usr/local/jpeg6/lib
-
mkdir /usr/local/jpeg6/include
-
mkdir -p /usr/local/jpeg6/man/man1
-
-
tar -zxvf jpegsrc.v6b.tar.gz
-
cd jpeg-6b
-
./configure --prefix=/usr/local/jpeg6 --enable-shared --enable-static
-
make
-
make install
[root@bogon jpeg-6b]# make; make install
./libtool --mode=compile gcc -O2 -I. -c ./jcapimin.c
make: ./libtool:命令未找到
make: *** [jcapimin.lo] 错误 127
./libtool --mode=compile gcc -O2 -I. -c ./cjpeg.c
make: ./libtool:命令未找到
make: *** [cjpeg.lo] 错误 127
解决办法:
首先看有没有安装libtool 及 libtool-ltdl-devel
rpm -qa | grep libtool
错误分析:由于libtool版本过低导致的,重新下载新版本的libtool以默认方式安装,执行以下命令: ./configure --prefix=/usr/local/libtool make make install
然后进入jpeg-6b的源码目录,然后执行以下步骤,切记!COPY到当前目录注意后面的点(.)
cp /usr/share/libtool/config/config.sub .
cp /usr/share/libtool/config/config.guess .
也就是把 libtool里面的两个配置文件拿来覆盖掉jpeg-6b目录下的对应文件
make clean 再重新configure
10>【安装freetype】
[html] view plain copy
-
tar -zxvf freetype-2.3.5.tar.gz
-
cd freetype-2.3.5
-
./configure --prefix=/usr/local/freetype
-
make && make install && echo OK && cd ..
11>【安装autoconf】
[html] view plain copy
-
tar -zxvf autoconf-2.61.tar.gz
-
cd autoconf-2.61
-
./configure --prefix=/usr/local/autoconf
-
make && make install && echo OK && cd ..
-
12>【安装gd】
[html] view plain copy
-
tar -zxvf gd-2.0.35.tar.gz
-
cd gd-2.0.35
-
./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6 --with-freetype=/usr/local/freetype
-
make && make install && echo OK && cd ..
-
13>【安装apache】
[html] view plain copy
-
tar -zxvf httpd-2.2.9.tar.gz
-
cd httpd-2.2.9
-
./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --with-included-apr --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support
-
make && make install && echo OK
-
-
#启动apache
-
/usr/local/apache2/bin/apachectl start
-
#如果出现下面的错误,
-
#httpd: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName
-
#修改配置文件
-
vi /etc/httpd/httpd.conf
-
#查找ServerName,将注释去掉
-
ServerName www.example.com:80
-
#添加到自启动
-
echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit
-
#将apache添加到系统服务中
-
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
-
vi /etc/rc.d/init.d/httpd
-
#在#!/bin/sh后添加下面两行(包含"#")
-
# chkconfig:2345 85 15
-
# description:Apache
-
#添加执行权限
-
chmod 755 /etc/init.d/httpd
-
#添加到系统服务中
-
chkconfig --add httpd
-
#开启apache
-
service httpd start
14>【安装ncurses】
[html] view plain copy
-
tar -zxvf ncurses-5.6.tar.gz
-
cd ncurses-5.6
-
./configure --prefix=/usr/local/ncurses --with-shared --without-debug --without-ada --enable-overwrite
-
make && make install && echo OK && cd ..
-
15>【安装mysql】
[html] view plain copy
-
groupadd mysql
-
useradd -g mysql mysql
-
tar -zxvf mysql-5.1.59.tar.gz
-
cd mysql-5.1.59
-
./configure --prefix=/usr/local/mysql/ --with-extra-charsets=all
-
make && make install && echo OK && cd ..
[html] view plain copy
-
cp support-files/my-medium.cnf /etc/my.cnf
-
/usr/local/mysql/bin/mysql_install_db --user=mysql
-
chown -R root /usr/local/mysql
-
chown -R mysql /usr/local/mysql/var
-
chgrp -R mysql /usr/local/mysql
-
-
/usr/local/mysql/bin/mysqld_safe --user=mysql &
-
cp /lamp/src/mysql-5.1.59/support-files/mysql.server /etc/rc.d/init.d/mysqld
-
chown root.root /etc/rc.d/init.d/mysqld
-
chmod 755 /etc/rc.d/init.d/mysqld
-
chkconfig --add mysqld
-
chkconfig --list mysqld
-
chkconfig --levels 245 mysqld off
[html] view plain copy
-
#配置mysql
-
cd /usr/local/mysql
-
bin/mysqladmin version //简单的测试
-
bin/mysqladmin Variables //查看所有mysql参数
-
bin/mysql -uroot //没有密码可以直接登录本机服务器
-
DELETE FROM mysql.user WHERE Host='localhost' AND User='';
-
FLUSH PRIVILEGES;
-
#设置root密码为123456
-
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
-
#配置可远程连接mysql
-
use mysql
-
SELECT user,password,host FROM user;
-
DELETE FROM user WHERE host='localhsot.localdomain'
-
DELETE FROM user WHERE host='127.0.0.1';
-
UPDATE user SET host='%' WHERE user='root';
-
#重启mysql
-
service mysqld restart
-
16>【安装php】
[html] view plain copy
-
tar -zxvf php-5.2.6.tar.gz
-
cd php-5.2.6
-
./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg6/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets
-
注:如果出现报错:
-
configure: error: GD build test failed. Please check the config.log for deta
查看当前目录下的config.log中找到
发现错误如下:
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_destroy_decompress@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_CreateCompress@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_read_header@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_read_scanlines@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_start_compress@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_destroy_compress@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_set_quality@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_finish_decompress@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_set_defaults@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_write_marker@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_start_decompress@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_destroy@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_resync_to_restart@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_simple_progression@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_write_scanlines@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_save_markers@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_CreateDecompress@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_std_error@LIBJPEG_6.2'
/usr/local/gd2//lib/libgd.so: undefined reference to `jpeg_finish_compress@LIBJPEG_6.2'
解决方法:
rm -rf /usr/local/gd
重新安装gd就行了,仔细点我的是在/usr/local/gd/后多了一个/
然后重新编译php就行了
如果还未解决,把--with-gd=/usr/local/gd2改成--with-gd 解决此问题!
-
make && make install && echo OK && cd ..
-
-
cp php.ini-development /usr/local/php/etc/php.ini
17>【apache配置】
[html] view plain copy
-
#建立工作目录
-
mkdir -p /var/www/html
-
#修改httpd.conf
-
vi /etc/httpd/httpd.conf
-
#功能: 设置工作目录
-
#说明: 搜索DocumentRoot, 修改为
-
DocumentRoot "/var/www/html"
-
-
#功能: 设置目录选项
-
#说明: 搜索<Directory "/usr/local/apache2//htdocs">, 修改为
-
<Directory "/var/www/html">
-
-
#功能: 设置默认文档
-
#说明: 搜索<IfModule dir_module>, 修改为
-
DirectoryIndex index.html index.php
-
-
#功能: 增加php类型
-
#说明: 搜索 AddType application/x-gzip .gz .tgz在后面添加
-
AddType application/x-httpd-php .html .php
-
-
功能: 不允许访问目录
-
说明: 搜索Options Indexes FollowSymLinks项并注释
-
#Options Indexes FollowSymLinks
-
-
#注意: 修改配置文件后, 重启apache才能生效
-
#重启apache
-
service httpd restart
-
18>【添加PDO_MYSQL扩展】
[html] view plain copy
-
cd /lamp/src/php-5.2.6/ext/pdo_mysql
-
/usr/local/php/bin/phpize
-
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
-
make
-
make install
[html] view plain copy
-
#执行完make install后会生成
-
#Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
-
#修改php.ini
-
vi /usr/local/php/etc/php.ini
-
#查找extension_dir,修改为
-
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
-
#添加pdo_mysql
-
extension = pdo_mysql.so
-
#重启apache
-
service httpd restart
19>【apache虚拟主机配置】
[html] view plain copy
-
#建立dev目录
-
mkdir -p /var/www/html/dev
-
cd /var/www/html/dev
-
vi index.php
-
#添加
-
<?php
-
phpinfo();
-
?>
-
#保存,退出
-
#打开httpd.conf
-
vi /etc/httpd/httpd.conf
-
#查找Include /etc/httpd//extra/httpd-vhosts.conf并取消注释
-
Include /etc/httpd//extra/httpd-vhosts.conf
-
#打开httpd-vhosts.conf
-
vi /etc/httpd//extra/httpd-vhosts.conf
-
#将下面几行注释
-
#<VirtualHost *:80>
-
# ServerAdmin webmaster@dummy-host.example.com
-
# DocumentRoot "/usr/local/apache2//docs/dummy-host.example.com"
-
# ServerName dummy-host.example.com
-
# ServerAlias www.dummy-host.example.com
-
# ErrorLog "logs/dummy-host.example.com-error_log"
-
# CustomLog "logs/dummy-host.example.com-access_log" common
-
#</VirtualHost>
-
-
-
#<VirtualHost *:80>
-
# ServerAdmin webmaster@dummy-host2.example.com
-
# DocumentRoot "/usr/local/apache2//docs/dummy-host2.example.com"
-
# ServerName dummy-host2.example.com
-
# ErrorLog "logs/dummy-host2.example.com-error_log"
-
# CustomLog "logs/dummy-host2.example.com-access_log" common
-
#</VirtualHost>
-
#添加
-
<VirtualHost *:80>
-
ServerName dev.dev
-
DocumentRoot "/var/www/html/dev"
-
<Directory "/var/www/html/dev/">
-
AllowOverride All
-
</Directory>
-
</VirtualHost>
-
#保存, 退出
-
#重启apache
-
service httpd restart
-
#修改hosts文件
-
vi /etc/hosts
-
#添加
-
127.0.0.1 dev.dev localhost
-
#保存, 退出
-
#在浏览器输入http://dev.dev访问,查看能否输出php信息
-
-
Apache优化项:
-
找到以下代码并根据提示修改
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all //这句改为Allow from all
</Directory>
找到这一段并修改,以使Apache支持rewrite(伪静态):
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
更改为
AllowOverride All
将以下代码注释掉,禁止目录列表:
Options Indexes FollowSymLinks
找到以下代码,修改用户为 www
<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>
User daemon //改为www
Group daemon //改为www
</IfModule>
</IfModule>
设置 ServerAdmin you@example.com 改为你自己的mail地址
查找:
Listen 80
改为
Listen 81
分别找到以下四段代码,将之前的注释#去除:
Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-info.conf
Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-default.conf
编辑 Include conf/extra/httpd-mpm.conf 找到如下选项,并改成对应的数值
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 1000
</IfModule>
编辑 conf/extra/httpd-default.conf
Timeout 60 #与nginx的保持一至
KeepAlive On
MaxKeepAliveRequests 1000
KeepAliveTimeout 5
创建以下用户及文件夹: -
groupadd www
-
useradd -g www -s /sbin/nologin -M www
-
mkdir -p /usr/local/apache2/docs/dummy-host.example.com
mkdir -p /usr/local/apache2/docs/dummy-host2.example.com
这样以后Apache 启动、关闭、重启只需要输入以下命令:
service httpd start/stop/restart
其次在Nginx-proxy上安装Nginx并做代理:
20 【Nginx安装】
yum -y install pcre-devel
wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz
tar xf libunwind-1.1.tar.gz
./configure --prefix=/usr/local/libunwind
make && make install && echo OK
yum -y install gperftool*
一般情况下 都没什么错误出现的。安装完成后还不能直接使用。得执行 ldconfig 重建系统动态链接库。
配置 nginx 和 google perftools :
mkdir /usr/local/nginx/tmp/tcmalloc && chown www:www /usr/local/nginx/tmp/tcmalloc
最后google_perftools 工具这样安装后还不能被Nginx调用。要给其指定该工具的动态链接库路径并重新加载系统动态链接库:
echo ‘/usr/local/gperftools/lib’>/etc/ld.so.conf.d/my_app_lib.conf
到这里。Google_perftools 工具已经安装完成,上面错误提示是在编译安装Nginx 1.4.7的时候出现的错误解决方法如图:
具体图文请参考:
编译安装 google_perftools : http://zlyang.blog.51cto.com/1196234/1752207
wget http://nginx.org/download/nginx-1.9.12.tar.gz
tar xf nginx-1.9.12.tar.gz
cd nginx-1.9.12
./configure --user=www --group=www --prefix=/usr/local/nginx --pid-path=/usr/local/nginx/logs/nginx.pid --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --with-http_stub_status_module --with-http_ssl_module --http-client-body-temp-path=/tmp/nginx_client --http-proxy-temp-path=/tmp/nginx_proxy --http-fastcgi-temp-path=/tmp/nginx_fastcgi --with-http_gzip_static_module --with-google_perftools_module --with-ld-opt='-ltcmalloc_minimal' --with-ipv6
make && make install && echo OK
修改配置文件:nginx.conf
#user nobody;
#worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
################# Nginx Setup ######################
user www;
worker_processes 4;
error_log logs/error.log;
pid logs/nginx.pid;
google_perftools_profiles /usr/local/nginx/tmp/tcmalloc;
worker_rlimit_nofile 51200;
events {
use epoll;
worker_connections 51200;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
################# Nginx Setup ###############
server_names_hash_bucket_size 128;
client_header_buffer_size 256k;
large_client_header_buffers 4 256k;
client_max_body_size 50m;
client_body_buffer_size 256k;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on;
#tcp_nopush on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 120;
#gzip on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_vary on;
include vhost/*.conf;
#################### load balancing ####################
upstream www.zlyang.com { #负责均衡
server 192.168.30.132:81; #Node节点
server 192.168.30.133:81; #Node节点
}
server {
listen 80;
server_name www.zlyang.com; #网站域名
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://www.zlyang.com; #网站域名
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# location / {
# root html;
# index index.html index.htm;
# }
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
重启nginx服务:
service nginx restart
安装 Redis:
wget http://download.redis.io/releases/redis-2.8.24.tar.gz
tar xf redis-2.8.24.tar.gz
ln -s redis-2.6.14 redis #建立一个链接
cd redis
make PREFIX=/usr/local/redis install #安装到指定目录中
注意上面的最后一行,我们通过PREFIX指定了安装的目录。如果make失败,一般是你们系统中还未安装gcc,那么可以通过yum安装:
yum -y install gcc*
将redis做成一个服务
cp utils/redis_init_script /etc/rc.d/init.d/redis
vim /etc/rc.d/init.d/redis
在#!/bin/bash 下面加入以下代码:
#chkconfig: 2345 80 90
修改
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
在start)函数中修改:
$EXEC $CONF
为:
$EXEC $CONF &
保存退出
创建Redis的配置文件目录:
mkdir /etc/redis
find / -name redis.conf
grep "REDISPORT=" /etc/rc.d/init.d/redis
cp /soft/redis-2.8.24/redis.conf /etc/redis/6379.conf
chkconfig --add redis
将Redis的命令所在目录添加到系统参数PATH中
修改profile文件:
vi /etc/profile
在最后加入:
export PATH=
"$PATH:/usr/local/redis/bin"
启动Redis:
/usr/local/redis/bin/redis-server /etc/redis/6379.conf &
这样就可以直接调用redis-cli的命令了,如下所示:
$ redis-cli
redis 127.0.0.1:6379> auth superman
OK
redis 127.0.0.1:6379> ping
PONG
redis 127.0.0.1:6379>
至此,redis 就成功安装了。
如果在执行redis-cli中报错:
[root@Redis redis]# redis-cli
127.0.0.1:6379> auth superman
(error) ERR Client sent AUTH, but no password is set
原因是redis没有设置验证口令!
解决方法:
设置Redis密码:
vim /etc/redis/redis.conf
# requirepass foobared
修改为:
requirepass auth密码
将redis写成服务脚本
vim /etc/init.d/redis
#!/bin/sh
#
# Author: Zlyang
# Date : 2016-6-14
#
# chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
#REDISPORT=6379
#EXEC=/usr/local/bin/redis-server
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
PID=`ps -ef|grep 6379|grep -Ev "grep" |awk '{print $2}'`
PID_NUM=`ps -ef|grep 6379|grep -Ev "grep" |awk '{print $2}'|wc -l`
#PIDFILE=/var/run/redis_${REDISPORT}.pid
#CONF="/etc/redis/${REDISPORT}.conf"
CONF="/etc/redis/redis.conf"
function start()
{
if [ "$PID_NUM" != 0 ]
then
echo "Redis service is already running ..."
else
echo "Starting Redis server..."
$EXEC $CONF 2>&1 > /dev/null &
sleep 1
if [ `ps -ef|grep 6379|grep -Ev "grep" |awk '{print $2}'|wc -l` != 0 ]
then
echo -e "Start Redis service.............................. [\E[1;32m OK \E[0m]"
fi
fi
}
function stop()
{
if [ $PID_NUM == 0 ]
then
echo "Redis service is not running !"
else
echo "Waiting for Redis to stop ..."
kill -9 $PID
sleep 1
echo -e "Stop Redis service............................... [\E[1;32m OK \E[0m]"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
if [ "$PID_NUM" != 0 ]
then
echo "Redis service is already running ..."
else
echo "Redis service is stoped !"
fi
;;
restart)
if [ "$PID_NUM" != 0 ]
then
stop
sleep 1
echo "Starting Redis server..."
$EXEC $CONF 2>&1 > /dev/null &
sleep 1
if [ `ps -ef|grep 6379|grep -Ev "grep" |awk '{print $2}'|wc -l` != 0 ]
then
echo -e "Start Redis service.............................. [\E[1;32m OK \E[0m]"
fi
else
start
fi
;;
*)
echo -e "\E[1;35m Usage: /etc/init.d/redos {start|stop|status|restart|}\E[0m"
;;
esac
保存退出:
将redis添加为服务:
chkconfig --add redis
chkconfig redis on
本文转自yangxuncai110 51CTO博客,原文链接:http://blog.51cto.com/zlyang/1752284,如需转载请自行联系原作者