linux-redis学习经历一,安装和简单使用

时间:2021-10-27 05:18:18
[BEGIN] 2018/1/29 11:08:35
[2018/1/29 11:08:35] Last login: Sat Jan 27 01:13:35 2018 from 192.168.0.123

//进入tomcat,logs文件夹下打印日志
[2018/1/29 11:19:43] [root@bogon data]# cd /home/tomcat/apache-tomcat-8.5.27/logs/
[2018/1/29 11:19:45] [root@bogon logs]# ll
[2018/1/29 11:19:45] 总用量 272
[2018/1/29 11:19:45] -rw-r-----. 1 root root  14157 1月  26 22:40 catalina.2018-01-26.log
[2018/1/29 11:19:45] -rw-r-----. 1 root root  70230 1月  27 01:20 catalina.2018-01-27.log
[2018/1/29 11:19:45] -rw-r-----. 1 root root  12023 1月  29 19:16 catalina.2018-01-29.log
[2018/1/29 11:19:45] -rw-r-----. 1 root root 111563 1月  29 19:18 catalina.out
[2018/1/29 11:19:45] -rw-r-----. 1 root root      0 1月  26 22:31 host-manager.2018-01-26.log
[2018/1/29 11:19:45] -rw-r-----. 1 root root      0 1月  27 00:44 host-manager.2018-01-27.log
[2018/1/29 11:19:45] -rw-r-----. 1 root root      0 1月  29 19:16 host-manager.2018-01-29.log
[2018/1/29 11:19:45] -rw-r-----. 1 root root   1209 1月  26 22:40 localhost.2018-01-26.log
[2018/1/29 11:19:45] -rw-r-----. 1 root root   4601 1月  27 01:20 localhost.2018-01-27.log
[2018/1/29 11:19:45] -rw-r-----. 1 root root    465 1月  29 19:16 localhost.2018-01-29.log
[2018/1/29 11:19:45] -rw-r-----. 1 root root  12096 1月  26 23:02 localhost_access_log.2018-01-26.txt
[2018/1/29 11:19:45] -rw-r-----. 1 root root   2534 1月  27 01:27 localhost_access_log.2018-01-27.txt
[2018/1/29 11:19:45] -rw-r-----. 1 root root   1494 1月  29 19:18 localhost_access_log.2018-01-29.txt
[2018/1/29 11:19:45] -rw-r-----. 1 root root      0 1月  26 22:31 manager.2018-01-26.log
[2018/1/29 11:19:45] -rw-r-----. 1 root root  11638 1月  27 01:27 manager.2018-01-27.log
[2018/1/29 11:19:45] -rw-r-----. 1 root root    671 1月  29 19:18 manager.2018-01-29.log
[2018/1/29 11:19:59] [root@bogon logs]# ta
[2018/1/29 11:19:59] tabs     tac      tail     tailf    tar      taskset  
//tail表示打印详情,追加-f表示反应实时内容,后面是文件名字
[2018/1/29 11:20:22] [root@bogon logs]# tail -f catalina.2018-01-29.log 
[2018/1/29 11:20:22] 29-Jan-2018 19:16:28.816 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/home/tomcat/apache-tomcat-8.5.27/webapps/docs] has finished in [476] ms
[2018/1/29 11:20:22] 29-Jan-2018 19:16:28.817 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/home/tomcat/apache-tomcat-8.5.27/webapps/examples]
[2018/1/29 11:20:22] 29-Jan-2018 19:16:40.355 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/home/tomcat/apache-tomcat-8.5.27/webapps/examples] has finished in [11,538] ms
[2018/1/29 11:20:22] 29-Jan-2018 19:16:40.355 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/home/tomcat/apache-tomcat-8.5.27/webapps/host-manager]
[2018/1/29 11:20:22] 29-Jan-2018 19:16:40.593 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/home/tomcat/apache-tomcat-8.5.27/webapps/host-manager] has finished in [237] ms
[2018/1/29 11:20:22] 29-Jan-2018 19:16:40.593 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/home/tomcat/apache-tomcat-8.5.27/webapps/manager]
[2018/1/29 11:20:22] 29-Jan-2018 19:16:40.924 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/home/tomcat/apache-tomcat-8.5.27/webapps/manager] has finished in [330] ms
[2018/1/29 11:20:22] 29-Jan-2018 19:16:40.953 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-80"]
[2018/1/29 11:20:22] 29-Jan-2018 19:16:40.996 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
[2018/1/29 11:20:22] 29-Jan-2018 19:16:41.044 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 19357 ms
…………
//使用redis需要c要编译,所以要先下载gcc编译器,可以编译c,c++等
[2018/1/29 14:04:44] [root@bogon ~]# yum -y install gcc-c++
[2018/1/29 14:04:45] 已加载插件:fastestmirror
…………
//下载redis,最新是4.x ;然后解压
[root@bogon ~]# wget http://download.redis.io/releases/redis-3.2.11.tar.gz
……
[root@bogon ~]# tar -xzvf redis-3.2.11.tar.gz
……
[2018/1/29 14:13:55] [root@bogon ~]# ll
[2018/1/29 14:13:55] 总用量 1556
[2018/1/29 14:13:55] -rw-------. 1 root root     946 1月  24 19:39 anaconda-ks.cfg
[2018/1/29 14:13:55] -rw-r--r--. 1 root root     115 1月  25 23:04 javafile12.tar.bz2
[2018/1/29 14:13:55] -rw-r--r--. 1 root root       0 1月  25 18:17 java编程思想
[2018/1/29 14:13:55] drwxr-xr-x. 2 root root       6 1月  25 18:31 java编码思想
[2018/1/29 14:13:55] -rw-r--r--. 1 root root   25680 4月  27 2017 mysql57-community-release-el7-11.noarch.rpm
[2018/1/29 14:13:55] drwxr-xr-x. 2 root root       6 1月  24 23:46 new-folder1
[2018/1/29 14:13:55] drwxrwxr-x. 6 root root    4096 9月  21 22:20 redis-3.2.11
[2018/1/29 14:13:55] -rw-r--r--. 1 root root 1550452 9月  21 22:20 redis-3.2.11.tar.gz
[2018/1/29 14:14:21] [root@bogon ~]# cd redis-3.2.11
[2018/1/29 14:14:22] [root@bogon redis-3.2.11]# ll
[2018/1/29 14:14:22] 总用量 212
[2018/1/29 14:14:22] -rw-rw-r--.  1 root root 92766 9月  21 22:20 00-RELEASENOTES
[2018/1/29 14:14:22] -rw-rw-r--.  1 root root    53 9月  21 22:20 BUGS
[2018/1/29 14:14:22] -rw-rw-r--.  1 root root  1805 9月  21 22:20 CONTRIBUTING
[2018/1/29 14:14:22] -rw-rw-r--.  1 root root  1487 9月  21 22:20 COPYING
[2018/1/29 14:14:22] drwxrwxr-x.  7 root root  4096 9月  21 22:20 deps
[2018/1/29 14:14:22] -rw-rw-r--.  1 root root    11 9月  21 22:20 INSTALL
[2018/1/29 14:14:22] -rw-rw-r--.  1 root root   151 9月  21 22:20 Makefile
[2018/1/29 14:14:22] -rw-rw-r--.  1 root root  4223 9月  21 22:20 MANIFESTO
[2018/1/29 14:14:22] -rw-rw-r--.  1 root root  6834 9月  21 22:20 README.md
[2018/1/29 14:14:22] -rw-rw-r--.  1 root root 46695 9月  21 22:20 redis.conf
[2018/1/29 14:14:22] -rwxrwxr-x.  1 root root   271 9月  21 22:20 runtest
[2018/1/29 14:14:22] -rwxrwxr-x.  1 root root   280 9月  21 22:20 runtest-cluster
[2018/1/29 14:14:22] -rwxrwxr-x.  1 root root   281 9月  21 22:20 runtest-sentinel
[2018/1/29 14:14:22] -rw-rw-r--.  1 root root  7606 9月  21 22:20 sentinel.conf
[2018/1/29 14:14:22] drwxrwxr-x.  2 root root  4096 9月  21 22:20 src
[2018/1/29 14:14:22] drwxrwxr-x. 10 root root  4096 9月  21 22:20 tests
[2018/1/29 14:14:22] drwxrwxr-x.  7 root root  4096 9月  21 22:20 utils
//编译redis
[2018/1/29 14:14:30] [root@bogon redis-3.2.11]# make
[2018/1/29 14:14:30] cd src && make all
[2018/1/29 14:14:30] make[1]: 进入目录“/root/redis-3.2.11/src”
…………
//redis的主要文件
[2018/1/29 14:18:22] [root@bogon redis]# ll
[2018/1/29 14:18:22] 总用量 4
[2018/1/29 14:18:22] drwxr-xr-x. 2 root root 4096 1月  29 22:17 bin
[2018/1/29 14:19:23] [root@bogon redis]# ll bin/
[2018/1/29 14:19:24] 总用量 15076
[2018/1/29 14:19:24] -rwxr-xr-x. 1 root root 2432584 1月  29 22:17 redis-benchmark
[2018/1/29 14:19:24] -rwxr-xr-x. 1 root root   25165 1月  29 22:17 redis-check-aof
[2018/1/29 14:19:24] -rwxr-xr-x. 1 root root 5191333 1月  29 22:17 redis-check-rdb
[2018/1/29 14:19:24] -rwxr-xr-x. 1 root root 2585443 1月  29 22:17 redis-cli
[2018/1/29 14:19:24] lrwxrwxrwx. 1 root root      12 1月  29 22:17 redis-sentinel -> redis-server
[2018/1/29 14:19:24] -rwxr-xr-x. 1 root root 5191333 1月  29 22:17 redis-server
//将redis的存放路径,放在/usr/local/redis/下后,同时也将redis.conf复制过去,因为需要改成后台运行
[2018/1/29 14:21:57] [root@bogon redis-3.2.11]# cp redis.conf /usr/local/redis/
[2018/1/29 14:22:00] [root@bogon redis-3.2.11]# ll
[2018/1/29 14:22:00] 总用量 216
[2018/1/29 14:22:00] -rw-rw-r--.  1 root root 92766 9月  21 22:20 00-RELEASENOTES
[2018/1/29 14:22:00] -rw-rw-r--.  1 root root    53 9月  21 22:20 BUGS
[2018/1/29 14:22:00] -rw-rw-r--.  1 root root  1805 9月  21 22:20 CONTRIBUTING
[2018/1/29 14:22:00] -rw-rw-r--.  1 root root  1487 9月  21 22:20 COPYING
[2018/1/29 14:22:00] drwxrwxr-x.  7 root root  4096 1月  29 22:14 deps
[2018/1/29 14:22:00] -rw-rw-r--.  1 root root    11 9月  21 22:20 INSTALL
[2018/1/29 14:22:00] -rw-rw-r--.  1 root root   151 9月  21 22:20 Makefile
[2018/1/29 14:22:00] -rw-rw-r--.  1 root root  4223 9月  21 22:20 MANIFESTO
[2018/1/29 14:22:00] -rw-rw-r--.  1 root root  6834 9月  21 22:20 README.md
[2018/1/29 14:22:00] -rw-rw-r--.  1 root root 46695 9月  21 22:20 redis.conf
[2018/1/29 14:22:00] -rwxrwxr-x.  1 root root   271 9月  21 22:20 runtest
[2018/1/29 14:22:00] -rwxrwxr-x.  1 root root   280 9月  21 22:20 runtest-cluster
[2018/1/29 14:22:00] -rwxrwxr-x.  1 root root   281 9月  21 22:20 runtest-sentinel
[2018/1/29 14:22:00] -rw-rw-r--.  1 root root  7606 9月  21 22:20 sentinel.conf
[2018/1/29 14:22:00] drwxrwxr-x.  2 root root  4096 1月  29 22:15 src
[2018/1/29 14:22:00] drwxrwxr-x. 10 root root  4096 9月  21 22:20 tests
[2018/1/29 14:22:00] drwxrwxr-x.  7 root root  4096 9月  21 22:20 utils
[2018/1/29 14:22:08] [root@bogon redis-3.2.11]# ll /usr/local/redis/
[2018/1/29 14:22:08] 总用量 52
[2018/1/29 14:22:08] drwxr-xr-x. 2 root root  4096 1月  29 22:17 bin
[2018/1/29 14:22:08] -rw-r--r--. 1 root root 46695 1月  29 22:21 redis.conf
//启动:前台运行
[2018/1/29 14:23:58] [root@bogon redis]# bin/redis-server 
[2018/1/29 14:23:58] 8546:C 29 Jan 22:23:58.796 # Warning: no config file specified, using the default config. In order to specify a config file use bin/redis-server /path/to/redis.conf
[2018/1/29 14:23:58] 8546:M 29 Jan 22:23:58.799 * Increased maximum number of open files to 10032 (it was originally set to 1024).
[2018/1/29 14:23:58]                 _._                                                  
[2018/1/29 14:23:58]            _.-``__ ''-._                                             
[2018/1/29 14:23:58]       _.-``    `.  `_.  ''-._           Redis 3.2.11 (00000000/0) 64 bit
[2018/1/29 14:23:58]   .-`` .-```.  ```\/    _.,_ ''-._                                   
[2018/1/29 14:23:58]  (    '      ,       .-`  | `,    )     Running in standalone mode
[2018/1/29 14:23:58]  |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
[2018/1/29 14:23:58]  |    `-._   `._    /     _.-'    |     PID: 8546
[2018/1/29 14:23:58]   `-._    `-._  `-./  _.-'    _.-'                                   
[2018/1/29 14:23:58]  |`-._`-._    `-.__.-'    _.-'_.-'|                                  
[2018/1/29 14:23:58]  |    `-._`-._        _.-'_.-'    |           http://redis.io        
[2018/1/29 14:23:58]   `-._    `-._`-.__.-'_.-'    _.-'                                   
[2018/1/29 14:23:58]  |`-._`-._    `-.__.-'    _.-'_.-'|                                  
[2018/1/29 14:23:58]  |    `-._`-._        _.-'_.-'    |                                  
[2018/1/29 14:23:58]   `-._    `-._`-.__.-'_.-'    _.-'                                   
[2018/1/29 14:23:58]       `-._    `-.__.-'    _.-'                                       
[2018/1/29 14:23:58]           `-._        _.-'                                           
[2018/1/29 14:23:58]               `-.__.-'                                               
[2018/1/29 14:23:58] 
[2018/1/29 14:23:58] 8546:M 29 Jan 22:23:58.817 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
[2018/1/29 14:23:58] 8546:M 29 Jan 22:23:58.820 # Server started, Redis version 3.2.11
[2018/1/29 14:23:58] 8546:M 29 Jan 22:23:58.821 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[2018/1/29 14:23:58] 8546:M 29 Jan 22:23:58.822 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
[2018/1/29 14:23:58] 8546:M 29 Jan 22:23:58.823 * The server is now ready to accept connections on port 6379
//用ctrl+c退出
[2018/1/29 14:24:28] ^C8546:signal-handler (1517235868) Received SIGINT scheduling shutdown...
[2018/1/29 14:24:28] 8546:M 29 Jan 22:24:28.552 # User requested shutdown...
[2018/1/29 14:24:28] 8546:M 29 Jan 22:24:28.552 * Saving the final RDB snapshot before exiting.
[2018/1/29 14:24:28] 8546:M 29 Jan 22:24:28.573 * DB saved on disk
[2018/1/29 14:24:28] 8546:M 29 Jan 22:24:28.574 # Redis is now ready to exit, bye bye...
//修改成后台访问,redis.conf 内的daemonize参数改为yes
[2018/1/29 14:24:46] [root@bogon redis]# ll
[2018/1/29 14:24:46] 总用量 56
[2018/1/29 14:24:46] drwxr-xr-x. 2 root root  4096 1月  29 22:17 bin
[2018/1/29 14:24:46] -rw-r--r--. 1 root root    77 1月  29 22:24 dump.rdb
[2018/1/29 14:24:46] -rw-r--r--. 1 root root 46695 1月  29 22:21 redis.conf
[2018/1/29 14:24:52] [root@bogon redis]# vi redis.conf 
//备注的日志,顺序好像有点问题,这里是创建文件夹并在创建路径下安装redis
[root@bogon redis-3.2.11]# mkdir -p /usr/local/redis
[root@bogon redis-3.2.11]# make PREFIX=/usr/local/redis install
[root@bogon redis-3.2.11]# cp redis.conf /usr/local/redis/
//启动redis,带上配置,就会在后台运行,不然前台运行时候无法做其它操作
[root@bogon redis]# bin/redis-server redis.conf 
//查看redis进程,ps -ef表示显示所有进程消息,|是管道命令,表示和grep同时执行,grep -i redis表示查询有字符串redis的进程,-i忽略大小写
//-e:显示所有进程,-f显示UID,PPIP,C与STIME栏位。
//UID 程序被该 UID 所拥有。PID 就是这个程序的 ID 。PPID 则是其上级父程序的ID。C CPU 使用的资源百分比。
//STIME 系统启动时间。TTY 登入者的终端机位置。TIME 使用掉的 CPU 时间。CMD 所下达的指令为何、
//!所以显然第一条是redis进程,第二条是grep查询本身的进程
[2018/1/29 14:27:09] [root@bogon redis]# ps -ef | grep -i redis
[2018/1/29 14:27:09] root       8552      1  0 22:26 ?        00:00:00 bin/redis-server 127.0.0.1:6379
[2018/1/29 14:27:09] root       8557   2649  0 22:27 pts/0    00:00:00 grep --color=auto -i redis
//关闭redis
[2018/1/29 14:38:42] [root@bogon redis]# bin/redis-cli shutdown
[2018/1/29 14:38:59] [root@bogon redis]# ps -ef | grep -i redis
[2018/1/29 14:38:59] root       8590   2649  0 22:38 pts/0    00:00:00 grep --color=auto -i redis
[2018/1/29 14:39:13] [root@bogon redis]# bin/redis-server redis.conf 
//进入redis客户端进行操作
[2018/1/29 14:39:57] [root@bogon redis]# bin/redis-cli 
//redis是nosql的,通过key-value保存数据,这里set是保存,get是获取,keys *是查看所以的key,del是删除
[2018/1/29 14:40:41] 127.0.0.1:6379> set name gaocc
[2018/1/29 14:40:41] OK
[2018/1/29 14:40:54] 127.0.0.1:6379> get name
[2018/1/29 14:40:54] "gaocc"
[2018/1/29 14:41:19] 127.0.0.1:6379> keys *
[2018/1/29 14:41:19] 1) "name"
[2018/1/29 14:41:50] 127.0.0.1:6379> del name
[2018/1/29 14:41:50] (integer) 1
[2018/1/29 14:42:00] 127.0.0.1:6379> keys *
[2018/1/29 14:42:00] (empty list or set)
[END] 2018/1/29 14:44:51