Linux+Nginx+Apache+Atlas+Mysql+Php+Redis 分部式部署详细版

本文涉及的产品
云数据库 Redis 版,社区版 2GB
推荐场景:
搭建游戏排行榜
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介:

环境描述:


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

  1. #查看apache是否己安装  

  2. rpm -qa httpd  

  3. #卸载  

  4. rpm -e httpd --nodeps  

2>【安装gcc, gcc-c++】

[html] view plain copy

  1. yum install gcc  

  2. yum install gcc-c++  

3>【开放80、3306、22端口】

[html] view plain copy

  1. #关闭防火墙  

  2. service iptables stop  

  3. vi /etc/sysconfig/iptables  

  4. #添加  

  5. -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT  

  6. -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT  

  7. -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT  

  8. #重启防火墙  

  9. service iptables restart  

4>【建立lamp/src目录, 将源码包上传】5>【安装libxml2】

[html] view plain copy

  1. tar -zxvf libxml2-2.6.30.tar.gz  

  2. cd libxml2-2.6.30  

  3. ./configure --prefix=/usr/local/libxml2

  4. make   

  5. make install  

6>【安装libmcrypt】

[html] view plain copy

  1. tar -zxvf libmcrypt-2.5.8.tar.gz  

  2. cd libmcrypt-2.5.8  

  3. ./configure --enable-ltdl-install  

  4. make  

  5. make install  

7>【安装zlib】

[html] view plain copy

  1. tar -zxvf zlib-1.2.3.tar.gz  

  2. cd zlib-1.2.3  

  3. ./configure  

  4. make  

  5. make install  

8>【安装libpng】

[html] view plain copy

  1. tar -zxvf libpng-1.2.31.tar.gz  

  2. cd libpng-1.2.31  

  3. ./configure --prefix=/usr/local/libpng  

  4. make  

  5. mkdir -p /usr/loca/libpng/man/man1

  6. make install  

9>【安装jpegsrc.v6b】

[html] view plain copy

  1. mkdir /usr/local/jpeg6  

  2. mkdir /usr/local/jpeg6/bin  

  3. mkdir /usr/local/jpeg6/lib  

  4. mkdir /usr/local/jpeg6/include  

  5. mkdir -p /usr/local/jpeg6/man/man1  

  6.   

  7. tar -zxvf jpegsrc.v6b.tar.gz  

  8. cd jpeg-6b  

  9. ./configure --prefix=/usr/local/jpeg6 --enable-shared --enable-static  

  10. make  

  11. 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

  1. tar -zxvf freetype-2.3.5.tar.gz  

  2. cd freetype-2.3.5  

  3. ./configure --prefix=/usr/local/freetype  

  4. make && make install && echo OK && cd ..  

11>【安装autoconf】

[html] view plain copy

  1. tar -zxvf autoconf-2.61.tar.gz  

  2. cd autoconf-2.61  

  3. ./configure --prefix=/usr/local/autoconf  

  4. make && make install && echo OK && cd ..

12>【安装gd】

[html] view plain copy

  1. tar -zxvf gd-2.0.35.tar.gz  

  2. cd gd-2.0.35 

  3. ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6 --with-freetype=/usr/local/freetype

  4. make && make install && echo OK && cd ..


13>【安装apache】

[html] view plain copy

  1. tar -zxvf httpd-2.2.9.tar.gz  

  2. cd httpd-2.2.9  

  3. ./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 

  4. make && make install && echo OK 


  5. #启动apache  

  6. /usr/local/apache2/bin/apachectl start  

  7. #如果出现下面的错误,  

  8. #httpd: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName  

  9. #修改配置文件  

  10. vi /etc/httpd/httpd.conf  

  11. #查找ServerName,将注释去掉  

  12. ServerName www.example.com:80  

  13. #添加到自启动  

  14. echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit  

  15. #将apache添加到系统服务中  

  16. cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd  

  17. vi /etc/rc.d/init.d/httpd  

  18. #在#!/bin/sh后添加下面两行(包含"#")  

  19. # chkconfig:2345 85 15  

  20. # description:Apache  

  21. #添加执行权限  

  22. chmod 755 /etc/init.d/httpd  

  23. #添加到系统服务中  

  24. chkconfig --add httpd  

  25. #开启apache  

  26. service httpd start  

14>【安装ncurses】

[html] view plain copy

  1. tar -zxvf ncurses-5.6.tar.gz  

  2. cd ncurses-5.6  

  3. ./configure --prefix=/usr/local/ncurses --with-shared --without-debug --without-ada --enable-overwrite  

  4. make && make install && echo OK && cd ..

  5.  

15>【安装mysql】

[html] view plain copy

  1. groupadd mysql  

  2. useradd -g mysql mysql  

  3. tar -zxvf mysql-5.1.59.tar.gz  

  4. cd mysql-5.1.59  

  5. ./configure --prefix=/usr/local/mysql/ --with-extra-charsets=all 

  6. make && make install && echo OK && cd ..

 

[html] view plain copy

  1. cp support-files/my-medium.cnf /etc/my.cnf  

  2. /usr/local/mysql/bin/mysql_install_db --user=mysql  

  3. chown -R root /usr/local/mysql  

  4. chown -R mysql /usr/local/mysql/var  

  5. chgrp -R mysql /usr/local/mysql  

  6.   

  7. /usr/local/mysql/bin/mysqld_safe  --user=mysql &  

  8. cp /lamp/src/mysql-5.1.59/support-files/mysql.server /etc/rc.d/init.d/mysqld  

  9. chown root.root /etc/rc.d/init.d/mysqld  

  10. chmod 755 /etc/rc.d/init.d/mysqld  

  11. chkconfig --add mysqld  

  12. chkconfig --list mysqld  

  13. chkconfig --levels 245 mysqld off 

[html] view plain copy

  1. #配置mysql  

  2. cd /usr/local/mysql  

  3. bin/mysqladmin version //简单的测试  

  4. bin/mysqladmin Variables //查看所有mysql参数  

  5. bin/mysql -uroot //没有密码可以直接登录本机服务器  

  6. DELETE FROM mysql.user WHERE Host='localhost' AND User='';  

  7. FLUSH PRIVILEGES;  

  8. #设置root密码为123456  

  9. SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');  

  10. #配置可远程连接mysql  

  11. use mysql  

  12. SELECT user,password,host FROM user;  

  13. DELETE FROM user WHERE host='localhsot.localdomain'  

  14. DELETE FROM user WHERE host='127.0.0.1';  

  15. UPDATE user SET host='%' WHERE user='root';  

  16. #重启mysql  

  17. service mysqld restart 


16>【安装php】

[html] view plain copy

  1. tar -zxvf php-5.2.6.tar.gz  

  2. cd php-5.2.6  

  3. ./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  

  4. 注:如果出现报错:

  5. 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 解决此问题!

  6. make && make install && echo OK && cd ..

  7.   

  8. cp php.ini-development /usr/local/php/etc/php.ini

  17>【apache配置】

[html] view plain copy

  1. #建立工作目录  

  2. mkdir -p /var/www/html  

  3. #修改httpd.conf  

  4. vi /etc/httpd/httpd.conf  

  5. #功能: 设置工作目录  

  6. #说明: 搜索DocumentRoot, 修改为  

  7. DocumentRoot "/var/www/html"  

  8.   

  9. #功能: 设置目录选项  

  10. #说明: 搜索<Directory "/usr/local/apache2//htdocs">, 修改为  

  11. <Directory "/var/www/html">  

  12.   

  13. #功能: 设置默认文档  

  14. #说明: 搜索<IfModule dir_module>, 修改为  

  15. DirectoryIndex index.html index.php  

  16.   

  17. #功能: 增加php类型  

  18. #说明: 搜索 AddType application/x-gzip .gz .tgz在后面添加  

  19. AddType application/x-httpd-php .html .php  

  20.   

  21. 功能: 不允许访问目录  

  22. 说明: 搜索Options Indexes FollowSymLinks项并注释  

  23. #Options Indexes FollowSymLinks  

  24.   

  25. #注意: 修改配置文件后, 重启apache才能生效  

  26. #重启apache  

  27. service httpd restart 

  28.  

18>【添加PDO_MYSQL扩展】

[html] view plain copy

  1. cd /lamp/src/php-5.2.6/ext/pdo_mysql  

  2. /usr/local/php/bin/phpize  

  3. ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql  

  4. make  

  5. make install  

[html] view plain copy

  1. #执行完make install后会生成  

  2. #Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/  

  3. #修改php.ini  

  4. vi /usr/local/php/etc/php.ini  

  5. #查找extension_dir,修改为  

  6. extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"  

  7. #添加pdo_mysql  

  8. extension = pdo_mysql.so  

  9. #重启apache  

  10. service httpd restart  

19>【apache虚拟主机配置】

[html] view plain copy

  1. #建立dev目录  

  2. mkdir -p /var/www/html/dev  

  3. cd /var/www/html/dev  

  4. vi index.php  

  5. #添加  

  6. <?php  

  7.     phpinfo();  

  8. ?>  

  9. #保存,退出  

  10. #打开httpd.conf  

  11. vi /etc/httpd/httpd.conf  

  12. #查找Include /etc/httpd//extra/httpd-vhosts.conf并取消注释  

  13. Include /etc/httpd//extra/httpd-vhosts.conf  

  14. #打开httpd-vhosts.conf  

  15. vi /etc/httpd//extra/httpd-vhosts.conf  

  16. #将下面几行注释  

  17. #<VirtualHost *:80>  

  18. #    ServerAdmin webmaster@dummy-host.example.com  

  19. #    DocumentRoot "/usr/local/apache2//docs/dummy-host.example.com"  

  20. #    ServerName dummy-host.example.com  

  21. #    ServerAlias www.dummy-host.example.com  

  22. #    ErrorLog "logs/dummy-host.example.com-error_log"  

  23. #    CustomLog "logs/dummy-host.example.com-access_log" common  

  24. #</VirtualHost>  

  25.   

  26.   

  27. #<VirtualHost *:80>  

  28. #    ServerAdmin webmaster@dummy-host2.example.com  

  29. #    DocumentRoot "/usr/local/apache2//docs/dummy-host2.example.com"  

  30. #    ServerName dummy-host2.example.com  

  31. #    ErrorLog "logs/dummy-host2.example.com-error_log"  

  32. #    CustomLog "logs/dummy-host2.example.com-access_log" common  

  33. #</VirtualHost>  

  34. #添加  

  35. <VirtualHost *:80>  

  36.         ServerName dev.dev  

  37.         DocumentRoot "/var/www/html/dev"  

  38.         <Directory "/var/www/html/dev/">  

  39.                 AllowOverride All  

  40.         </Directory>  

  41. </VirtualHost>  

  42. #保存, 退出  

  43. #重启apache  

  44. service httpd restart  

  45. #修改hosts文件  

  46. vi /etc/hosts  

  47. #添加  

  48. 127.0.0.1       dev.dev localhost  

  49. #保存, 退出  

  50. #在浏览器输入http://dev.dev访问,查看能否输出php信息  


  51. Apache优化项:

  52. 找到以下代码并根据提示修改

    <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

    创建以下用户及文件夹:

  53. groupadd www

  54. useradd -g www -s /sbin/nologin -M www


  55. 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

cd libunwind-1.1

./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,如需转载请自行联系原作者









相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
16天前
|
应用服务中间件 网络安全 nginx
快速上手!使用Docker和Nginx部署Web服务的完美指南
快速上手!使用Docker和Nginx部署Web服务的完美指南
|
16天前
|
负载均衡 Java 应用服务中间件
nginx安装在linux上
nginx安装在linux上
42 2
|
16天前
|
JavaScript 前端开发 应用服务中间件
angular引入包、路由权限配置、打包问题与nginx配置问题(简单部署)
angular引入包、路由权限配置、打包问题与nginx配置问题(简单部署)
24 0
|
4天前
|
应用服务中间件 nginx
如何在树莓派部署Nginx并实现无公网ip远程访问内网制作的web网站
如何在树莓派部署Nginx并实现无公网ip远程访问内网制作的web网站
8 0
|
5天前
|
安全 Linux 网络安全
Linux _ apache服务器部署 不同域名—访问不同网站(多网站)
Linux _ apache服务器部署 不同域名—访问不同网站(多网站)
|
11天前
|
负载均衡 网络协议 应用服务中间件
【亮剑】在Linux中构建高可用性和高性能网络服务的负载均衡工具HAProxy、Nginx和Keepalived。
【4月更文挑战第30天】本文介绍了在Linux中构建高可用性和高性能网络服务的负载均衡工具HAProxy、Nginx和Keepalived。HAProxy是一个高性能的开源TCP和HTTP负载均衡器,适合处理大量并发连接;Nginx是一个多功能Web服务器和反向代理,支持HTTP、HTTPS和TCP负载均衡,同时提供缓存和SSL功能;Keepalived用于监控和故障切换,通过VRRP实现IP热备份,保证服务连续性。文中详细阐述了如何配置这三个工具实现负载均衡,包括安装、配置文件修改和启动服务,为构建可靠的负载均衡系统提供了指导。
|
12天前
|
Ubuntu 应用服务中间件 Linux
Linux下制作Nginx绿色免安装包
linux下安装nginx比较繁琐,遇到内网部署环境更是麻烦,所以研究了下nginx绿色免安装版的部署包制作,开箱即用,特此记录分享,一下操作在centos8环境下安装,如果需要其他内核系统的安装(Debian/Ubuntu等),请在对应环境虚拟机下安装制作
21 0
|
12天前
|
运维 Serverless 应用服务中间件
Serverless 应用引擎产品使用之在阿里云Serverless中函数计算FC nginx 部署上去之后放置静态页面如何解决
阿里云Serverless 应用引擎(SAE)提供了完整的微服务应用生命周期管理能力,包括应用部署、服务治理、开发运维、资源管理等功能,并通过扩展功能支持多环境管理、API Gateway、事件驱动等高级应用场景,帮助企业快速构建、部署、运维和扩展微服务架构,实现Serverless化的应用部署与运维模式。以下是对SAE产品使用合集的概述,包括应用管理、服务治理、开发运维、资源管理等方面。
218 0
|
1天前
|
关系型数据库 MySQL 数据库
docker MySQL删除数据库时的错误(errno: 39)
docker MySQL删除数据库时的错误(errno: 39)
|
1天前
|
关系型数据库 MySQL 数据库连接
用Navicat备份Mysql演示系统数据库的时候出:Too Many Connections
用Navicat备份Mysql演示系统数据库的时候出:Too Many Connections