使用 ISO 安装 CentOS7 虚拟机
配置静态 IP(参考 Mac VMware Fusion CentOS7 配置静态 IP https://www.jb51.net/article/162824.htm )
安装 VIM
- [root@localhost java]# rpm -qa|grep VIM
- VIM-minimal-7.4.629-6.el7.x86_64
- [root@localhost java]# yum -y install VIM*
- ...
安装 jdk
使用 FileZilla 上传 jdk 到 Linux 系统的 / home/software
- [root@localhost software]# mkdir /usr/java
- ...
- [root@localhost software]# mkdir /home/software
- ...
- [root@localhost software]# tar -zxvf jdk-8u231-Linux-x64.tar.gz
- ...
- [root@localhost software]# mv jdk1.8.0_231 /usr/java/
- ...
配置 java 环境变量
- [root@localhost java]# VIM /etc/profile
- ...
- #最下方添加下面三条
- export JAVA_HOME=/usr/java/jdk1.8.0_231
- export CLASSPATH=.:%JAVA_HOME%/lib/dt.jar:%JAVA_HOME%/lib/tools.jar
- export PATH=$PATH:$JAVA_HOME/bin
- ...
- [root@localhost java]# source /etc/profile
- [root@localhost java]# java -version
- java version "1.8.0_231"
- Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
- Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
安装 Redis
https://redis.io/download 下载稳定版本
使用 FileZilla 上传 Redis 到 Linux 系统的 / home/software
解压压缩包
[root@localhost software]# tar -zxvf Redis-5.0.7.tar.gz
因为需要编译和生成 Redis, 因此需要安装 gcc
- [root@localhost software]# yum -y install gcc-c++
- ...
已安装:
gcc-c++.x86_64 0:4.8.5-39.el7
作为依赖被安装:
- cpp.x86_64 0:4.8.5-39.el7 gcc.x86_64 0:4.8.5-39.el7 glibc-devel.x86_64 0:2.17-292.el7 glibc-headers.x86_64 0:2.17-292.el7 kernel-headers.x86_64 0:3.10.0-1062.9.1.el7 libmpc.x86_64 0:1.0.1-3.el7
- libstdc++-devel.x86_64 0:4.8.5-39.el7 mpfr.x86_64 0:3.1.1-4.el7
完毕!
进入 Redis-5.0.7 解压目录, 执行安装:
[root@localhost Redis-5.0.7]# make && make install
配置 Redis
[root@localhost utils]# ll
总用量 52
-rw-rw-r--. 1 root root 593 11 月 20 01:05 build-static-symbols.tcl
-rw-rw-r--. 1 root root 1303 11 月 20 01:05 cluster_fail_time.tcl
-rw-rw-r--. 1 root root 1098 11 月 20 01:05 corrupt_rdb.c
drwxrwxr-x. 2 root root 60 11 月 20 01:05 create-cluster
-rwxrwxr-x. 1 root root 2149 11 月 20 01:05 generate-command-help.rb
drwxrwxr-x. 3 root root 31 11 月 20 01:05 graphs
drwxrwxr-x. 2 root root 39 11 月 20 01:05 hashtable
drwxrwxr-x. 2 root root 70 11 月 20 01:05 hyperloglog
-rwxrwxr-x. 1 root root 9567 11 月 20 01:05 install_server.sh
drwxrwxr-x. 2 root root 63 11 月 20 01:05 lru
-rw-rw-r--. 1 root root 1277 11 月 20 01:05 Redis-copy.rb
-rwxrwxr-x. 1 root root 1352 11 月 20 01:05 redis_init_script
-rwxrwxr-x. 1 root root 1047 11 月 20 01:05 redis_init_script.tpl
-rw-rw-r--. 1 root root 1762 11 月 20 01:05 Redis-sha1.rb
drwxrwxr-x. 2 root root 135 11 月 20 01:05 releasetools
-rwxrwxr-x. 1 root root 3787 11 月 20 01:05 speed-regression.tcl
-rwxrwxr-x. 1 root root 693 11 月 20 01:05 whatisdoing.sh
如上所示, 在 utils 目录下, 有一个 redis_init_script 文件, 复制该文件到 / etc/init.d / 目录下, 目的是为了配置 Redis 为开机自启动.
- [root@localhost utils]# cp redis_init_script /etc/init.d/
- [root@localhost utils]# mkdir /usr/local/Redis -p
- [root@localhost Redis-5.0.7]# cp Redis.conf /usr/local/Redis/
创建 / usr/local/Redis 目录, 用于存放 Redis 配置文件.
修改 Redis 配置文件
- ################################# GENERAL #####################################
- # 修改 daemonize no 为 yes, 目的是启动 Redis 以后台进程运行
- daemonize yes
- # 修改 Redis 工作路径 (数据存储位置)
- dir /usr/local/Redis/workingdb
- # 代表可以被远程访问, 不受 ip 限制
- #bind 127.0.0.1
- bind 0.0.0.0
- # 修改密码
- requirepass 12345678
修改 redis_init_script 文件中 Redis 核心配置, 修改文件权限
- REDISPORT=6379
- EXEC=/usr/local/bin/Redis-server
- CLIEXEC=/usr/local/bin/Redis-cli
- PIDFILE=/var/run/redis_${
- REDISPORT
- }.pid
- CONF="/usr/local/redis/redis.conf"
- [root@localhost init.d]# chmod 777 redis_init_script
- # 启动 Redis
- [root@localhost init.d]# ./redis_init_script start
设置开机自启动
在 / etc/init.d 路径下的启动脚本文件中添加
- #chkconfig: 22345 10 90
- &
- #description: Start and Stop Redis
- [root@iZ2ze7s2v0b78922wia32rZ init.d]# VIM redis_init_script
- #!/bin/sh
- #
- # Simple Redis init.d script conceived to work on Linux systems
- # as it does use of the /proc filesystem.
- ### BEGIN INIT INFO
- # Provides: redis_6379
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: Redis data structure server
- # Description: Redis data structure server. See https://redis.io
- ### END INIT INFO
- #chkconfig: 22345 10 90
- #description: Start and Stop Redis
- REDISPORT=6379
- EXEC=/usr/local/bin/Redis-server
- CLIEXEC=/usr/local/bin/Redis-cli
- PIDFILE=/var/run/redis_${
- REDISPORT
- }.pid
- CONF="/usr/local/redis/redis.conf"
执行 chkconfig redis_init_script on, 启动配置.
关闭 Redis
- [root@localhost Redis]# /etc/init.d/redis_init_script stop
- Stopping ...
- (error) NOAUTH Authentication required.
- Waiting for Redis to shutdown ...
- Waiting for Redis to shutdown ...
- [root@localhost Redis]# VIM /etc/init.d/redis_init_script
- # 在脚本中也需要添加密码验证, 才能关闭 Redis
- stop)
- if [ ! -f $PIDFILE ]
- then
- echo "$PIDFILE does not exist, process is not running"
- else
- PID=$(cat $PIDFILE)
- echo "Stopping ..."
- $CLIEXEC -a "12345678" -p $REDISPORT shutdown
- while [ -x /proc/${PID} ]
- do
- echo "Waiting for Redis to shutdown ..."
- sleep 1
- done
- echo "Redis stopped"
- fi
- ;;
- *)
安装之后, 远程连接失败, 因为在 CentOS7 默认开启防火墙
- # 停止防火墙
- [root@localhost ~]# systemctl stop firewalld.service
- # 禁止防火墙开机启动
- [root@localhost ~]# systemctl disable firewalld.service
- Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
- Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
或者执行下述命令来开放 6379 端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
完整克隆虚拟机
直接在 VM ware fusion 中需要克隆的机器上右键, 选择 创建完整克隆
CentOS 7. 直接修改 Ip
VIM /etc/sysconfig/network-scripts/ifcfg-ens33 # 修改 IP 配置
service network restart 重置网络
CentOS 6 或某些版本, 需要更改 Mac 地址和 IP
- VIM /etc/udev/rule.d/70-persistent-ipoib.rules
- VIM /etc/sysconfig/network-scripts/ifcfg-ens33 # 修改 IP 配置
service network restart 重置网络
Mac 下配置环境变量失效问题
自己在 ~/.bash_profile 中配置环境变量, 可是每次重启终端后配置的不生效. 需要重新执行 : $source ~/.bash_profile
发现 zsh 加载的是 ~/.zshrc 文件, 而 '.zshrc' 文件中并没有定义任务环境变量.
解决办法
在~/.zshrc 文件最后, 增加一行:
source ~/.bash_profile
来源: https://www.cnblogs.com/zhangpan1244/p/12155141.html