标签:answer 创建 table int -- url extension firewall http
什么是Memcached ?Memcached是一套分布式内存对象缓存系统,用于在动态系统中减少数据库负载,进而提升系统性能。Memcache多数情况是作为数据库的前端Cache来使用,因为它比数据库少了很多sql解析、磁盘操作等开销,而且使用内存来管理数据,所以它可以提供比直接读取数据库更好的性能。
缓存一般用来保存一些经常存取的对象或数据(例如,浏览器会把经常访问的网页缓存起来),通过缓存来存取对象或数据要比磁盘快很多。Memcache是一种内存缓存,把经常存取的对象或数据存在内存中,内存中缓存的数据通过API的方式被存取,数据就像一张大的HASH表,以key-value对的方式存在。
- 检查客户端请求的数据是否在Memcache中存在,如果在,直接把请求的数据返回,不再对数据进行任何操作;
- 如果请求的数据不在Memcache中,就在查询数据库,把从数据库中获取的数据返回给客户端,同时把数据缓存一份到Memcache中;
- 每次更新数据库(如更新、删除数据库的数据)的同时更新Memcache中的数据,保证Memcache中的数据和数据库中的数据一致。
- 当分配给Memcache内存空间用完之后,会使用LRU(最近最少使用)策略加到期失效策略,失效的数据首先被替换掉,然后再替换掉最近未使用的数据。
主机名 | 操作系统 | IP地址 | 服务名 |
---|---|---|---|
memcached | centos7.4 | 192.168.96.22 | memcached-1.5.9.tar.gz、libevent-2.0.21-stable.tar.gz |
web1 | centos7.4 | 192.168.96.23 | LAMP、memcache-2.2.7.tgz |
客户端 | windows 10 | 192.168.96.2 | 网页浏览器 |
关闭防火墙及Selinux
systemctl stop firewalld
setenforce 0
相关软件包百度云盘 密码:j2v3
#解压
tar -zxvf libevent-2.0.21-stable.tar.gz -C /opt
#进入目录
cd /opt/libevent-2.0.21-stable/
#配置
./configure
#编译及安装
make && make install
#解压
tar zxvf memcached-1.5.9.tar.gz -C /opt
#进入目录
cd /opt/memcached-1.5.9/
#配置
./configure
#编译及安装
make && make install
memcached -m 32m -p 11211 -d -u root -P /var/run/memcached.pid -c256
以上选项说明如下:
-p:使用的tcp端口,默认为11211
-m:最大内存大小,默认为64M
-vv:以very vrebose模式启动,将调试信息和错误输出到控制台
-d:作为守护进程的后台运行
-c:最大运行的并发连接数,默认是1024,一般按照服务器的负载量来设置
-P:设置保存Memcached的pid文件
-l:监听的服务器IP地址,若有多个地址
-u:运行Memcached的用户,默认不能用root启动,若使用需要-u来指定root用户
netstat -tunlp | grep memcached
telnet 192.168.96.22 11211
1. set
2. add
3. replace
4. get
5. delete
command <key> <flags> <expiration time> <bytes>
<value>
参数 | 用法 |
---|---|
key | key用于查找缓存值 |
flags | 可以包括键值对的整型参数,客户机使用它存储关于键值对的额外信息 |
expiration time | 在缓存中保存键值对的时间长度(以秒为单位,0 表示永远) |
bytes | 在缓存中存储的字节点 |
value | 存储的值(始终位于第二行) |
1.set
set命令用于向缓存添加新的键值对,如果已经存在,则之前的值将被替换,响应STORED
2.add
当缓存中不存在键时,add命令才会向缓存中添加一个键值对,如果缓存中已经存在该键,则之前的值将仍将保持不变,并返回响应NOT_STORED
3.append username 0 0 4 //键值后追加4个字节
4.prepend username 0 0 2 //键值前追加2个字节
5.replace
仅当键已经存在时,replace命令才会替换缓存中的键,如果缓存中不存在该键,则返回响应NOT_STORED
6.get
用于检索与之前添加的键值对相关的值
7.delete
用于删除memcached中的任何现有值,将使用一个键调用delete,如果该键存在于缓存中,则删除该值。如果不存在,则返回一条NOT_FOUND消息。
8.stats
转储所连接的 memcached 实例的当前统计数据。
9.flush_all
仅用于清理缓存中的所有名称/值对。如果需要将缓存重置到干净的状态,则 flush_all 能提供很大的用处。
10.quit //退出
yum install httpd httpd-devel -y
systemctl enable httpd
systemctl start httpd
netstat -tunlp | grep httpd
yum install mariadb mariadb-server mariadb-libs mariadb-devel -y
rpm -qa | grep mariadb
systemctl enable mariadb
systemctl start mariadb
netstat -tunlp | grep mysql
mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we‘ll need the current
password for the root user. If you‘ve just installed MariaDB, and
you haven‘t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): #直接“回车”
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
You already have a root password set, so you can safely answer ‘n‘.
Change the root password? [Y/n] y #输入“y”
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y #输入“y”
... Success!
Normally, root should only be allowed to connect from ‘localhost‘. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y #输入“y”
... Success!
By default, MariaDB comes with a database named ‘test‘ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y #输入“y”
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y #输入“y”
... Success!
Cleaning up...
All done! If you‘ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
mysql -u root -p
yum -y install php php-devel
rpm -ql php
yum install php-mysql
rpm -ql php-mysql
yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath
cd /var/www/html
vim info.php
<?php
phpinfo();
?>
systemctl restart httpd
客户端访问http://192.168.96.22/info.php
#安装autoconf软件包
yum install autoconf -y
#解压
tar xf memcache-2.2.7.tgz -C /opt/
#进入目录
cd /opt/memcache-2.2.7
#增加为PHP的模块后再对memcache进行配置编译
/usr/bin/phpize
![](http://i2.51cto.com/images/blog/201807/25/7f0ba593f9d05d86f8e0f75065739d88.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
#配置
./configure --enable-memcache --with-php-config=/usr/bin/php-config
#编译及安装
make && make install
vim /etc/php.ini
#732行,新增以下命令
extension_dir = "/usr/lib64/php/modules/"
#864行,新增以下命令
extension = memcache.so
vim /var/www/html/index.php
<?php
$memcache = new Memcache();
$memcache->connect(‘192.168.96.22‘,11211);
$memcache->set(‘key‘,‘Memcache test Successfull!‘,0,60);
$result = $memcache->get(‘key‘);
unset($memcache);
echo $result;
?>
service httpd restart
标签:answer 创建 table int -- url extension firewall http
原文地址:http://blog.51cto.com/10316297/2150218