How to install and configure memcached

本文详细介绍了如何在Red Hat Enterprise Linux 6和7上安装、配置和管理Memcached服务,包括防火墙设置、禁用UDP、调整最大连接数和缓存大小,以及如何查看日志、统计信息和资源使用情况。

https://access.redhat.com/solutions/1160613

 SOLUTION 已验证 - 已更新 2018年三月5日20:01 - 

English 

环境

  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7

问题

  • How to install memcached.
  • How to configure memcached.
  • How to start and stop memcached.
  • How to capture memcached logs in /var/log/memcached.
  • How to see memcached slabs and stats.
  • High CPU utilization on memcached servers.

决议

What is Memcached.

Memcached is an open source, high-performance, distributed memory object caching system. While it is generic in nature, it is intended for use in speeding up dynamic web applications by alleviating database load.

Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

Memcached allows applications to take memory from parts of system where it has more than it needs and make it accessible to areas where applications have less than they need.

How to install memcached.

rhel-6-server-rpms repository from Red Hat:

Raw

# yum install memcached

How to configure memcached.

Configure a firewall

First and foremost, set up a firewall in your LAN if memcached servers should be accessible only from within your local network. Do not allow external traffic to ports used by memcached (e.g. 11211 as used by default).

Disable UDP

If you are not required to use UDP for memcached, we highly recomment switching to TCP connections for your memcached server (add "-U 0" to the OPTIONS variable in /etc/sysconfig/memcached). If you do require the use of UDP and require remote access to memcached servers (for example, in a clustering scenario), it is recommended to configure a firewall to allow connections only from trusted hosts.

Configure memcached

To configure memcached, edit the file /etc/sysconfig/memcached as follows

Raw

# vi /etc/sysconfig/memcached

Change the values as shown below and add the IP address of your server on which memcached is installed.

Raw

PORT="11211"
USER="memcached"
# max connection 2048
MAXCONN="2048"
# set ram size to 2048 - 2GiB
CACHESIZE="4096"
# disable UDP and listen to loopback ip 127.0.0.1, for network connection use real ip e.g., 10.0.0.5
OPTIONS="-U 0 -l 127.0.0.1"

How to configure your logs to /var/log/memcached.

To configure logs

In order to capture memcached logs, configure /etc/sysconfig/memcached as follows:

Raw

OPTIONS="-vv >> /var/log/memcached 2>&1"

Start memcached

Start or Stop memcached

After the above configurations, it is time to start the memcached service as below:

Raw

# chkconfig memcached on
# service memcached start

In order to stop/restart memcached, run the following commands:

Raw

# service memcached stop
# service memcached restart

根源

  • High resource utilization can happen due to low configurations settings for maximum connections and cachesize.
    Increase the value of "maxconn" and "cachesize"

Raw

# cat /etc/sysconfig/memcached*
PORT="11211"
USER="memcached"
# max connection 2048
MAXCONN="2048"
# set ram size to 4096 - 4GiB
CACHESIZE="4096"

诊断步骤

How to use memcached-tool to verify slabs and stats.

To check and verify memcached slabs

Raw

# memcached-tool IP_ADDRESS:Port
# memcached-tool IP_ADDRESS:Port display
# memcached-tool 127.0.0.1:11211
# memcached-tool 127.0.0.1:11211 display

Sample output.

Raw

#  Item_Size   Max_age  1MB_pages Count   Full?
  1     104 B     5134 s       1      10      no
  2     136 B     5135 s       1      40      no
  3     176 B        0 s       1       0      no
  4     224 B     2648 s       1       7      no
  8     552 B     1810 s       1      12      no
  9     696 B     1810 s       1       6      no
 10     872 B     2935 s       1       8      no

Verify memcached stats

In order to verify memcached statics, run the following commands:

Raw

# memcached-tool IP_Address:Port stats
# memcached-tool 127.0.0.1:11211 stats

Sample output from above command:

Raw

#127.0.0.1:11211   Field       Value
accepting_conns           1
               auth_cmds           0
             auth_errors           0
                   bytes           0
              bytes_read          87
           bytes_written        3205
              cas_badval           0
                cas_hits           0
              cas_misses           0
               cmd_flush           0
                 cmd_get           0
                 cmd_set           0
             conn_yields           0
   connection_structures          11
        curr_connections          10
              curr_items           0
               decr_hits           0
             decr_misses           0
             delete_hits           0
           delete_misses           0
               evictions           0
                get_hits           0
              get_misses           0
               incr_hits           0
             incr_misses           0
          limit_maxbytes  4294967296
     listen_disabled_num           0
                     pid        7679
            pointer_size          64
           rusage_system    0.030995
             rusage_user    0.048992
                 threads           4
                    time  1407726751
       total_connections          17
             total_items           0
                  uptime        4999
                 version       1.4.4
内容概要:本文介绍了一个基于多传感器融合的定位系统设计方案,采用GPS、里程计和电子罗盘作为定位传感器,利用扩展卡尔曼滤波(EKF)算法对多源传感器数据进行融合处理,最终输出目标的滤波后位置信息,并提供了完整的Matlab代码实现。该方法有效提升了定位精度与稳定性,尤其适用于存在单一传感器误差或信号丢失的复杂环境,如自动驾驶、移动采用GPS、里程计和电子罗盘作为定位传感器,EKF作为多传感器的融合算法,最终输出目标的滤波位置(Matlab代码实现)机器人导航等领域。文中详细阐述了各传感器的数据建模方式、状态转移与观测方程构建,以及EKF算法的具体实现步骤,具有较强的工程实践价值。; 适合人群:具备一定Matlab编程基础,熟悉传感器原理和滤波算法的高校研究生、科研人员及从事自动驾驶、机器人导航等相关领域的工程技术人员。; 使用场景及目标:①学习和掌握多传感器融合的基本理论与实现方法;②应用于移动机器人、无人车、无人机等系统的高精度定位与导航开发;③作为EKF算法在实际工程中应用的教学案例或项目参考; 阅读建议:建议读者结合Matlab代码逐行理解算法实现过程,重点关注状态预测与观测更新模块的设计逻辑,可尝试引入真实传感器数据或仿真噪声环境以验证算法鲁棒性,并进一步拓展至UKF、PF等更高级滤波算法的研究与对比。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值