顯示具有 Server::Redis Server 標籤的文章。 顯示所有文章
顯示具有 Server::Redis Server 標籤的文章。 顯示所有文章

2017年5月10日 星期三

在 CentOS / RHEL 7 上,架設多個 Redis 服務 !!

學習目標:
  • 利用不同的 port ,啟動多個 Redis 服務!
  • 架設 Redis Server ,請參考這一篇
操作流程:
  1. 複製主要設定檔:
    # cp -a /etc/redis.conf /etc/redis6479.conf
    
  2. 編修設定檔 /etc/redis6479.conf:
    # vim /etc/redis6479.conf
    (修改下列項目...)
    port 6479
    tcp-backlog 611
    pidfile /var/run/redis_6479.pid
    logfile /var/log/redis/redis_6479.log
    
  3. 修正設定檔 /etc/redis6479.conf 權限:
    # chown redis /etc/redis6479.conf
    
  4. 切換到系統服務目錄,修改設定檔:
    # cd /usr/lib/systemd/system/
    # cp -a redis.service redis6479.service
    # vim redis6479.service
    (修改下列項目...)
    ExecStart=/usr/bin/redis-server /etc/redis6479.conf --daemonize no
    ExecStop=/usr/libexec/redis-shutdown redis6479
    
  5. 切換到系統服務目錄的設定目錄,新增設定目錄:
    #cd /etc/systemd/system/
    # cp -a redis.service.d/ redis6479.service.d/
    
  6. 新增記錄檔:
    #touch /var/log/redis/redis_6479.log
    # chown redis.redis /var/log/redis/redis_6479.log
    
  7. SELinux 的設定與修正:
    #chcon --reference=/etc/redis.conf /etc/redis6479.conf
    #chcon --reference=/usr/lib/systemd/system/redis.service /usr/lib/systemd/system/redis6479.service
    #chcon -R --reference=/etc/systemd/system/redis.service.d/ /etc/systemd/system/redis6479.service.d/
    #chcon --reference=/var/log/redis/redis.log /var/log/redis/redis_6479.log
    #semanage port -a -t redis_port_t -p tcp 6479
    #semanage port -l | grep redis
    
  8. 防火牆設定:
    #firewall-cmd --permanent --add-port=6479/tcp
    #firewall-cmd --reload
    
  9. 啟動服務:
    #systemctl enable redis6479.service
    # systemctl start redis6479.service
    # systemctl status redis6479.service -l
    
  10. 測試服務:
    # redis-cli -p 6479 -a 123456
    127.0.0.1:6479> exit
    

參考文獻:
  • https://www.cnyunwei.cc/archives/996
  • https://read01.com/eE2GGK.html
  • http://wangxin123.com/2016/09/18/Redis%E5%A4%9A%E5%AE%9E%E4%BE%8B%E5%8F%8A%E4%B8%BB%E4%BB%8E%E6%90%AD%E5%BB%BA/

2016年7月6日 星期三

用 CentOS7/RHEL7 架設 Redis Cluster Servers

參考文獻:

  1. http://blog.csdn.net/dc_726/article/details/48552531
  2. http://redis.io/topics/replication
  3. https://www.digitalocean.com/community/tutorials/how-to-configure-a-redis-cluster-on-ubuntu-14-04
  4. https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-redis-on-ubuntu-16-04

2016年6月26日 星期日

在 CentOS7/RHEL7 上架設 Redis Server

基本安裝流程:
  1. 安裝 EPEL 套件:
    #yum -y install epel-release
    
  2. 安裝 redis 相關套件:
    #yum install -y redis
    
  3. 開啟防火牆設定:
    #firewall-cmd --permanent --add-port=6379/tcp
    #firewall-cmd --reload
    
  4. 啟動 Redis Server 服務:
    #systemctl enable redis.service
    #systemctl start redis.service
    
  5. 查詢開啟的 port 號:
    #netstat -antlp | grep redis
    
  6. 測試 Redis Server 服務:
    #rdis-cli ping
    
  7. ※重要設定檔:
    • /etc/redis.conf
    • /etc/redis-sentinel.conf

基本設定:
  1. 修改登入密碼:
    #vim /etc/redis.conf
    (移除前方的註解符號)
    requirepass redhat
    
  2. 重新啟動 Redis Server 服務:
    #systemctl restart redis.service
    
  3. 再次測試 Redis Server 服務:
    #redis-cli -a 'redhat' -h 192.168.5.61 ping
    

利用 PHP 連結 Redis Server:
  1. 安裝相關所需要的套件:
    #yum -y install http php php-mbstring php-mcrypt php-gd php-redis
    
  2. 重新啟動 Httpd Server 服務:
    #systemctl restart httpd.service
    
    ※注意::要開啟 Http Server 的防火牆設定:
    #firewall-cmd --permanent --add-service=http
    #firewall-cmd --reload
    

    ※注意::要開啟 SELinux 相關設定:
    #setsebool -P httpd_can_network_connect on
    
  3. 寫一支 PHP 的程式,測試是否可以運作 Redis :
    #vim /var/www/html/test.php
    (內容如下:)
    <?php
     $redis = new Redis();
     $redis->connect('127.0.0.1', 6379);
     $redis->set("foo", "bar");
     echo $redis->get("foo");
    ?>
    

安裝 Redis Server 管理後台--phpRedisAdmin:
  1. 下載 phpRedisAdmin 套件:
    #git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git
    #cd phpRedisAdmin
    #git clone https://github.com/nrk/predis.git vendor
    
  2. 修改 phpRedisAdmin 連線設定:
    #cd includes/
    #cp config.sample.inc.php config.inc.php
    #vim config.inc.php
    (修改下列設定,並移去註解符號)
    'auth' => 'redhat'
    
  3. 開啟 Firefox ,輸入網址 http://127.0.0.1/phpRedisAdmin ,即可看見!

將 php 的 session ,交給 Redis Server
  1. 修改 php.ini 檔案:
    #vim /etc/php.ini
    session.save_handler = redis
    session.save_path = "tcp://192.168.1.61:6379?weight=1"
    
  2. ※注意:http://blog.51yip.com/php/1616.html
  3. 重新啟動 httpd :
    #systemctl restart httpd
    
參考文獻:
  1. https://magiclen.org/ubuntu-redis-php/
  2. https://bepsvpt.wordpress.com/2016/04/08/install-redis-and-deal-with-warning-message/
  3. https://laravel.tw/docs/5.1/redis
  4. http://www.runoob.com/redis/redis-tutorial.html
  5. http://ithelp.ithome.com.tw/articles/10105731
  6. http://kejyun.github.io/Laravel-4-Documentation-Traditional-Chinese/docs/redis/
  7. http://xyz.cinc.biz/2015/09/centos7-redis-php.html
  8. https://dotblogs.com.tw/supershowwei/2016/02/02/112238
  9. http://sharadchhetri.com/2014/10/04/install-redis-server-centos-7-rhel-7/
  10. https://github.com/erikdubbelboer/phpRedisAdmin
  11. https://bepsvpt.wordpress.com/2016/04/08/install-redis-and-deal-with-warning-message/