代码编织梦想

1.安装 gcc*

设置yum源可以参考之前的文章
https://blog.csdn.net/w918589859/article/details/109191537

[root@localhost ~]$ yum -y install gcc*

2.安装所需要的包

软件包百度网盘:
链接:https://pan.baidu.com/s/1rQ7_9XU2xSsg691bp-QrPw 提取码:u1mi

[root@localhost ~]$ yum -y install lrzsz unzip #安装lrzsz,源码包直接拖进shell即可
[root@localhost ~]$ unzip redis-mysql.zip && cd redis-mysql

#之前存在的删除掉
[root@localhost ~]$ rpm -qa | grep -i mysql
[root@localhost ~]$ yum remove mysql-libs
[root@localhost ~]$ rpm -qa | grep libstdc++
[root@localhost ~]$ rpm -e libstdc++-4.4.7-23.el6.x86_64 --nodeps



[root@localhost ~]$ yum -y install *  #安装所有软件包

3.配置网站 nginx 并启动 nginx

配置server

[root@localhost ~]$ cd /etc/nginx/
[root@localhost ~]$  vim nginx.conf
include /etc/nginx/conf.d/*.conf;

[root@localhost ~]$ vim /etc/nginx/conf.d/default.conf
server {  #具体的某一网站的配置信息
    listen       80; #监听端口
    server_name  www.abc.com; #修改这里,域名

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /www;  #网页根目录(/usr/local/nginx/html)
        index  index.php 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   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/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   /usr/share/nginx/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           /www;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /www$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;
    #}
    }

启动 nginx

[root@localhost ~]$ service nginx start

修改www.conf文件

[root@localhost ~]$ vim /etc/php-fpm.d/www.conf
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx


4.启动 php 和数据库

[root@localhost ~]$ service php-fpm start
[root@localhost ~]$ service mysqld start

5.授权,使登录数据库时使用‘123456’密码

[root@localhost ~]$ mysqladmin -uroot password 123456
[root@localhost ~]$ mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

6.测试网站和 php 的连通性

[root@localhost ~]$ mkdir /www
[root@localhost ~]$ echo "<?php phpinfo();" > /www/index.php #php测试页面

浏览器输入服务器的ip测试
在这里插入图片描述


7.安装 redis

[root@localhost ~]$ cd /root/redis-mysql
[root@localhost ~]$ tar -zxvf redis-2.8.19.tar.gz && cd redis-2.8.19
[root@localhost ~]$ make #编译
[root@localhost ~]$ make PREFIX=/usr/local/redis install
#指定安装位置,如果没有指定安装位置PREFIX=/usr/local/redis
#则 make install 会把 redis 安装到/usr/local/bin/目录下

[root@localhost ~]$ mkdir /usr/local/redis/etc
[root@localhost ~]$ cp -a ./redis.conf /usr/local/redis/
#复制 Redis 的配置文件到/usr/local/redis/下,便于管理。

8.安装提供 php 和 redis 联系的软件

[root@localhost ~]$ cd /root/redis-mysql
[root@localhost ~]$ unzip phpredis-master.zip && cd phpredis-master && phpize

#检查依赖关系,检查编译工具,指定安装的功能,位置
[root@localhost ~]$ ./configure --with-php-config=/usr/bin/php-config
[root@localhost ~]$ make && make install #编译安装

让php支持redis

[root@localhost ~]$ vim /etc/php.ini
#最末尾添加一行
extension=redis.so #在php文件中添加redis

[root@localhost ~]$ service php-fpm restart

浏览器输入ip地址访问搜索redis
在这里插入图片描述


9.进入 mysql 插数据

[root@localhost ~]$ mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database mytest;
Query OK, 1 row affected (0.00 sec)

mysql> use mytest;
Database changed

mysql> create table test(id int not null auto_increment,name char(20) default null,primary key (id))engine=innodb auto_increment=10 default charset=utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> describe test;
+-------+----------+------+-----+---------+----------------+
| Field | Type     | Null | Key | Default | Extra          |
+-------+----------+------+-----+---------+----------------+
| id    | int(11)  | NO   | PRI | NULL    | auto_increment |
| name  | char(20) | YES  |     | NULL    |                |
+-------+----------+------+-----+---------+----------------+
2 rows in set (0.00 sec)


mysql> insert into test values (1,'a1'),(2,'a2'),(3,'a3');
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0



10.开启 redis,并编写脚本

[root@localhost ~]$ ln -s /usr/local/redis/bin/* /usr/local/bin/ #添加软连接

[root@localhost ~]$ vim /usr/local/redis/redis.conf
daemonize no #修改为 yes #后台启动

[root@localhost ~]$ pkill redis
[root@localhost ~]$ redis-server /usr/local/redis/redis.conf   #启动从服务redis

[root@localhost ~]$ vim /www/redis.php
<?php
		ini_set("display_errors", "On");
		error_reporting(E_ALL | E_STRICT);
		//开启debug 
	
	
		// mysql 库: mytest 表:test 
        $redis = new redis();
        $redis->connect('127.0.0.1',6379);
        $query = "select * from test limit 5";
        for ($key=1;$key<=5;$key++)
        {
                if (!$redis->get($key))
				//判断redis中是否有1 2 3 4 5 的键,没有连接数据库查询mytest库的test表,然后插入到redis中
                {
                        $connect = mysql_connect('127.0.0.1','root','123456');
                        mysql_select_db(mytest);
                        $result = mysql_query($query);
						var_dump ($result);
                        while ($row = mysql_fetch_assoc($result))
                        {
                                $redis->setex($row['id'],30,$row['name']);
								//从MySQL中获取的资源插入到redis中,并设置有效时间为30s
                        }
                        $myserver = 'mysql';
                        break;
                }
                else
				//判断redis中是否有1 2 3 4 5 的键,有直接打印redis中的 1 2 3 4 5 键的值。
                {
                        $myserver = "redis";
                        $data[$key] = $redis->get($key);
                }
        }
                        echo $myserver;
                        echo "<br>";
                        for ($key=1;$key<=5;$key++)
                        {
                                echo "number is <b><font color=#FF0000>$key</font></b>";
                                echo "<br>";
                                echo "name is <b><font color=#FF0000>$data[$key]</font></b>";
                                echo "<br>";
                        }
?>



11.验证 php 访问 redis 和 mysql

浏览器输入ip地址/redis.php

在这里插入图片描述

在这里插入图片描述


版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接: https://blog.csdn.net/w918589859/article/details/111087329

Mybatis-plus:bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErro-爱代码爱编程

记录一个报错信息:在使用Mybatis-plus时,测试查询单个数据时一直报错 bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; c

mysql优化之索引监控Handler_read-爱代码爱编程

mysql> show status like 'Handler_read%'; +-----------------------+-------+ | Variable_name | Value | +-----------------------+-------+ | Handler_read_first | 0 |

什么是横向扩展、纵向扩展?-爱代码爱编程

什么是横向扩展、纵向扩展? 横向扩展英文简称:Scale Out,全称:Scale horizontally,横向扩展,向外扩展。 纵向扩展英文简称:Scale Up,全称:Scale vertically,纵向扩展,向上扩展。 不管横向扩展还是纵向扩展都是一种架构的概念。 横向扩展:比如可以增加一台节点/机器 比如:mysql新增加一个从库、

Mysql 中 Case 的使用介绍-爱代码爱编程

工作中经常需要写各种 sql 来统计线上的各种业务数据,使用 CASE 能让你的统计事半功倍,如果能用好它,不仅SQL 能解决的问题更广泛,写法也会漂亮地多,接下来让我们看看 CASE 的各种妙用吧,在开始之前我们简单学习一下 CASE 表达式的写法 CASE 表达式的两种写法 CASE 表示式有简单表达式和搜索表达式两种,如下 -- 简单 C

一次SQL查询优化原理分析:900W+数据,从17s到300ms-爱代码爱编程

有一张财务流水表,未分库分表,目前的数据量为9555695,分页查询使用到了limit,优化之前的查询耗时16 s 938 ms (execution: 16 s 831 ms, fetching: 107 ms),按照下文的方式调整SQL后,耗时347 ms (execution: 163 ms, fetching: 184 ms); 操作:查询

Spring Boot 整合携程Apollo 配置中心-爱代码爱编程

作者:AaronSimon blog.csdn.net/AaronSimon/article/details/83657612 Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境、不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限、流程治理等特性,适用于微服务配置管理场景。 服务端基于Spr

Centos7下启动tomcat无报错页面浏览报错: HTTP ERROR 404Problem accessing /. Reason: NOT_FOUND-爱代码爱编程

问题环境: 使用vm虚拟机下安装Centos7,开启tomcat正常,启动过程中没有报错,但是开启后无法打开tomcat的初始界面:localhost:8080,报错如上图. 原因: 端口号被防火墙拦截/没有被开放. 解决方法: 修改端口号,防火墙开放对应端口号,问题解决。 修改端口号: 假设tomcat所在目录为/usr/local/apa

各版本liunx/ubuntu宽带拨号方式-爱代码爱编程

liunx/ubuntu拨号 ubuntu拨号 方法一ubuntu拨号 方法二 安装过三四种版本,之前用的方法一,新版本好像只能用方法二。 ubuntu拨号 方法一 打开终端输入 sudo pppoeconf 进入界面全选择“是” 账号,移动校园网可能要加@cmcc 密码 设置完成,可能右上角宽带图标依然显示未连接,不用管,浏览器测试

NGINX的详细安装教程(超详细)-爱代码爱编程

1:先下载NGINX并上传到服务器 下载地址:http://nginx.org/en/download.html 2:安装环境依赖 #安装gcc编译器 yum install gcc-c++ #安装PCRE 用于解析正则表达式 yum install -y pcre pcre-devel #安装zlib 用于解压和压缩依赖

部署kvm虚拟化(二)-爱代码爱编程

6.管理KVM虚拟机 virsh list //查看 正在运行的虚拟机 virsh list --all//查看所有虚拟机 id 名称 状态 centos7.3 runningvirsh start 名字 //启动 virsh shutdown 名字 //关机 virsh destroy 名字 //强制关机 virsh autostart 名

用户怒了!红帽公司宣布CentOS 8将停止维护,“免费” RHEL 寿终正寝-爱代码爱编程

/Python专栏原创/ 12月8日,CentOS 8 项目官网宣布,CentOS 8 将在2021年底停止维护,CentOS 7 将维护到2024年6月30日。 也就是说,“免费版”的“红帽企业Linux”(RHEL),即将落幕。 CentOS 作为广受喜爱的免费Linux系统,在开源社区饱受欢迎,而这次停止维护的消息来得太突然,许多

推荐一款日志切割神器,好用到爆!!-爱代码爱编程

来源:r6d.cn/QN53 对于 Linux 系统安全来说,日志文件是极其重要的工具。不知为何,我发现很多运维同学的服务器上都运行着一些诸如每天切分 Nginx日志之类的 CRON 脚本,大家似乎遗忘了 Logrotate,争相发明自己的轮子,这真是让人沮丧啊!就好比明明身边躺着现成的性感美女,大家却忙着自娱自乐,罪过! logrotate