17.14 memcache安装和配置(自启动)过程
  • memcache 是一个高性能的分布式的内存对象缓存系统,通过在内存中维护一张统一的、巨大的 Hash 表,它能够用来存储各种格式的数据,包括图像、视频、文件及数据库检索的结果等。简单地说就是将数据调用到内存中,然后从内存中读取,从而大大提高读取速度。
  • memcache 有两个软件:
  1. memcache-8.0 是 memcache 模块,也就是客户端;
  2. memcached-1.6.17 是 memcache 服务器端。
  • memcache客户端安装:
#安装底层依赖包zlib-devel,之前源码安装了zlib库的此时就不用安装了
[root@CncLucZK ~]# yum -y install zlib-devel

#进入memcache-8.0解压缩目录
[root@CncLucZK ~]# cd /usr/local/src/memcache-8.0

#用phpize加载memcache模块。这条命令一定要进入memcache目录才能正确执行
[root@CncLucZK memcache-8.0]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20200930
Zend Module Api No:      20200930
Zend Extension Api No:   420200930

#编译前配置。指定php-config文件的位置
[root@CncLucZK memcache-8.0]# ./configure --with-php-config=/usr/local/php/bin/php-config
#编译安装
[root@CncLucZK memcache-8.0]# make && make install
  • memcache服务器端安装
#安装memcache,需要先安装libevent-devel包
[root@CncLucZK memcache-8.0]# yum -y install libevent-devel
#进入memcached-1.6.17解压缩目录
[root@CncLucZK memcache-8.0]# cd /usr/local/src/memcached-1.6.17
#编译前配置
[root@CncLucZK memcached-1.6.17]# ./configure --prefix=/usr/local/memcache
#编译安装
[root@CncLucZK memcached-1.6.17]# make && make install
#添加memcache用户,仅仅是用来启动服务的,不用设置密码
[root@CncLucZK memcached-1.6.17]# useradd memcache

#在后台启动memcache服务器
[root@CncLucZK memcached-1.6.17]# /usr/local/memcache/bin/memcached -u memcache &
[1] 353288
#查看memcached进程信息
[root@CncLucZK memcached-1.6.17]# ps aux | grep memcached 
memcache  353288  0.0  0.3 431592  5972 pts/0    Sl   12:05   0:00 /usr/local/memcache/bin/memcached -u memcache
  • 保证 memcache 开机自启动,将启动命令添加到/etc/rc.local文件中,命令如下:
[root@CncLucZK memcached-1.6.17]# vi /etc/rc.local
...
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/etc/rc.d/init.d/bt start
/usr/local/apache2/bin/apachectl start
/usr/local/mysql/bin/mysqld_safe -u mysql &
/usr/local/memcache/bin/memcached -u memcache &
  • 最终,LAMP 环境需要自启动的服务是 apache、mysql 和 memcache。

docker 缓存过大 docker cached_docker 缓存过大

17.21Docker安装(yum)
  • docker开发文档
  • yum安装时软件时首先要求主机要联网,之后需配置yum源,可以配置一些国内的镜像地址。如:阿里云、腾讯云、新浪云等。以下是官网安装的步骤:
#1.检测系统版本
[root@VM-0-3-centos bin]# cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core) 

#2.安装编译器
[root@VM-0-3-centos bin]# yum -y install gcc
[root@VM-0-3-centos bin]# yum -y install gcc-c++

#3.卸载之前安装的版本
[root@VM-0-3-centos bin]# sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
                  

#4.安装环境。设置Docker的存储库并从中安装
[root@VM-0-3-centos bin]# sudo yum install -y yum-utils

#5.可以使用阿里云镜像http://mirrors.allyun.com/docker-ce/linux/centos/docker-ce.repo

[root@VM-0-3-centos ~]# sudo yum-config-manager \
     --add-repo \
     https://download.docker.com/linux/centos/docker-ce.repo

Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo

#6.安装最新版本的Docker Engine、container和Docker Compose
[root@VM-0-3-centos ~]# sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

#6.或者是先查询repo中可用版本,然后选择并安装:
#例如: docker-ce-18.09.1.
[root@VM-0-3-centos ~]# yum list docker-ce --showduplicates | sort -r
Last metadata expiration check: 0:00:32 ago on Mon 12 Dec 2022 06:41:34 PM CST.
Installed Packages
docker-ce.x86_64               3:20.10.9-3.el8                 docker-ce-stable 
docker-ce.x86_64               3:20.10.8-3.el8                 docker-ce-stable 
docker-ce.x86_64               3:20.10.7-3.el8                 docker-ce-stable 
docker-ce.x86_64               3:20.10.6-3.el8                 docker-ce-stable 
docker-ce.x86_64               3:20.10.5-3.el8                 docker-ce-stable 
docker-ce.x86_64               3:20.10.4-3.el8                 docker-ce-stable 
docker-ce.x86_64               3:20.10.3-3.el8                 docker-ce-stable 
docker-ce.x86_64               3:20.10.2-3.el8                 docker-ce-stable 
docker-ce.x86_64               3:20.10.21-3.el8                docker-ce-stable 
docker-ce.x86_64               3:20.10.21-3.el8                @docker-ce-stable
...
docker-ce.x86_64  				3:18.09.1-3.el7                docker-ce-stable
docker-ce.x86_64    			3:18.09.0-3.el7                docker-ce-stable
docker-ce.x86_64  				18.06.1.ce-3.el7                docker-ce-stable
docker-ce.x86_64  				18.06.0.ce-3.el7                docker-ce-stable

#VERSION_STRING上诉命令的版本号
#例如: docker-ce-20.10.9
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-compose-plugin

[root@VM-0-3-centos ~]# sudo yum install docker-ce-20.10.9 docker-ce-cli-20.10.9 containerd.io docker-compose-plugin


#7.启动Docker:
[root@VM-0-3-centos ~]# sudo systemctl start docker

#8.通过运行hello world映像验证Docker Engine是否正确安装。
#此命令下载测试图像并在容器中运行。当容器运行时,它将打印一条消息并退出。
[root@VM-0-3-centos ~]# sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

#注意:第5步已经安装了最新版的docker,但是运行run hello-world时不能找到hello-world:会自动远程拉取hello-world图像库然后显示运行结果
#而执行第6步自定义版本安装后,运行run hello-world时直接显示运行结果
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:faa03e786c97f07ef34423fccceeec2398ec8a5759259f94d99078f264e9d7af
Status: Downloaded newer image for hello-world:latest


#9.docker版本
[root@VM-0-3-centos ~]# sudo docker version
Client: Docker Engine - Community
 Version:           20.10.9
 API version:       1.41
 Go version:        go1.16.8
 Git commit:        c2ea9bc
 Built:             Mon Oct  4 16:08:25 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.9
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.8
  Git commit:       79ea9d3
  Built:            Mon Oct  4 16:06:48 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.12
  GitCommit:        a05d175400b1145e5e6a735a6710579d181e7fb0
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

#10.docker仓库拉取的类信息
[root@VM-0-3-centos ~]# sudo docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    feb5d9fea6a5   13 months ago   13.3kB

#11.docker运行进程
[root@VM-0-3-centos ~]# ps aux|grep docker
root     1265344  0.0  4.6 1442892 82064 ?       Ssl  19:17   0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root     1266173  0.0  0.0  12140  1072 pts/0    S+   19:21   0:00 grep --color=auto docker


#升级Docker引擎

#要升级Docker Engine,请下载更新的包文件,并使用yum-y upgrade而不是yum-y install重复安装过程,然后指向新文件。
  • 从软件包安装:如果无法使用Docker的存储库来安装Docker,您可以下载.rpm文件并手动安装。每次升级Docker Engine时都需要下载一个新文件。
1.去https://download.docker.com/linux/centos/并选择您的CentOS版本。然后浏览到x86_64/stable/Packages/并下载要安装的Docker版本的.rpm文件。

2.安装Docker Engine,将下面的路径更改为下载Docker包的路径。
sudo yum install /path/to/package.rpm
#Docker已安装但未启动。将创建docker组,但不会向该组添加任何用户。

3.启动Docker.
sudo systemctl start docker

3.通过运行hello world映像验证Docker Engine是否正确安装。
sudo docker run hello-world
下一篇:Linux学习-86-phpmyadmin安装及配置过程