零、前言
以 VAR
开头的表示用户可配置的变量
以 CONST
开头的表示涉及到的系统常量,例如某个特定文件的地址路径。一般不可变,但是不排除因版本不同需要进行修改。
出现 PATH
表示这是一个路径信息
一、配置
1.1、更换 yum 源
PATH_YUM_CONF="/etc/yum.repos.d/CentOS-Base.repo" && \cat << EOF > $PATH_YUM_CONF
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
EOF# 安装额外的软件仓库epel-release, 大多数rpm包在官方的仓库中找不到
yum install -y epel-release && \# 安装网络工具包
yum install -y net-tools && \# 修改完成后安装vim
yum install -y vim
1.2、配置静态 IP 地址
# 1. 定义变量
VAR_GATEWAY="192.168.248.2" && \
VAR_IPADDR="192.168.248.105" && \
PATH_NETWORK_ENS32="/etc/sysconfig/network-scripts/ifcfg-ens32" && \
# 阿里DNS
VAR_DNS1="223.5.5.5" && \
VAR_DNS2="223.6.6.6" && \# 2. 写入文件内容
cat << EOF > $PATH_NETWORK_ENS32
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens32"
UUID="5bce0633-e13e-4d3a-a835-93e049c4aa55"
DEVICE="ens32"
ONBOOT="yes"
PREFIX="24"
IPV6_PRIVACY="no"
DNS1="$VAR_DNS1"
DNS2="$VAR_DNS2"
GATEWAY="$VAR_GATEWAY"
IPADDR="$VAR_IPADDR"
EOF# 3. 刷新网络配置
systemctl restart network && \# 4. 查看网络配置是否成功
ip address
1.3、关闭防火墙
# 关闭防火墙
systemctl stop firewalld && \# 关闭防火墙开机自启动
systemctl disable firewalld.service && \# 查看防火墙状态, 确保关闭
systemctl status firewalld
1.4、修改主机名
# 自定义hostname
VAR_HOSTNAME="hadoop001" && \# 常量: 系统固定路径
PATH_HOSTNAME="/etc/hostname" && \echo $VAR_HOSTNAME > $PATH_HOSTNAME
1.5、修改主机名映射
PATH_HOSTS="/etc/hosts" && \cat << EOF > $PATH_HOSTS
192.168.248.101 hadoop001
192.168.248.102 hadoop002
192.168.248.103 hadoop003
192.168.248.104 myLinux
EOF
1.6、IP 错误的解决方案
问题描述: 由于在个人电脑学习的过程中经常关闭虚拟机,可能存在重启后突然连接不上虚拟机的问题。使用 ip address
命令查看后发现 ens32(或 ens33)对应的 IP 地址异常,并且使用 systemctl restart network
命令也是报错。
解决方案:
systemctl stop NetworkManager && \
systemctl disable NetworkManager && \
systemctl restart network && \
systemctl restart NetworkManager
二、安装
2.1、安装 Redis
# 1. 定义变量, 供后面重复使用
VAR_PATH_SOFTWARE_DIR="/opt/module" && \
REDIS_VERSION="7.0.11" && \# 2. 进入指定自定义安装目录
cd $VAR_PATH_SOFTWARE_DIR && \# 3. 下载指定版本的redis
wget https://github.com/redis/redis/archive/$REDIS_VERSION.tar.gz && \# 4. 解压缩到安装目录
tar -zxvf $REDIS_VERSION.tar.gz -C $VAR_PATH_SOFTWARE_DIR && \# 5. 默认生成的目录名符合个人偏好, 所以不进行重命名操作
cd $VAR_PATH_SOFTWARE_DIR/redis-$REDIS_VERSION && \# 6. make编译、make install安装
make && make install && \# 7. 使用sed工具修改一些配置项
sed -i "s/bind 127.0.0.1 -::1/bind 0.0.0.0/" redis.conf && \
sed -i "s/protected-mode yes/protected-mode no/" redis.conf && \
sed -i "s/daemonize no/daemonize yes/" redis.conf
2.2、安装 Java
# 由于Oracle对JDK的下载进行验证限制, 这个步骤手工获取
JDK_DOWNLOAD_PATH="" && \
JDK_VERSION="jdk1.8.0_341"
VAR_PATH_SOFTWARE_DIR="/opt/module" && \
PATH_PROFILE_D="/etc/profile.d" && \# 进入安装目录
cd $VAR_PATH_SOFTWARE_DIR && \# 下载JDK
wget $JDK_DOWNLOAD_PATH && \# 解压
tar -zvxf jdk-8u341-linux-x64.tar.gz -C $VAR_PATH_SOFTWARE_DIR && \# 配置环境变量
cat << EOF > $PATH_PROFILE_D/$JDK_VERSION.sh
export JAVA_HOME=$VAR_PATH_SOFTWARE_DIR/$JDK_VERSION
export PATH=$PATH:$JAVA_HOME/bin
EOF# 刷新环境变量设置
source /etc/profile
2.3、安装 Docker
# 1.安装gcc环境
yum -y install gcc gcc-c++ && \# 2. 卸载docker旧版本(可能之前有安装)
yum -y remove docker docker-common docker-selinux docker-engine && \# 3. 安装依赖的软件包
yum install -y yum-utils device-mapper-persistent-data lvm2 && \# 4. 设置stable仓库
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo && \# 5. 更新yum软件包索引
yum makecache fast && \# 6. 安装Docker社区版
yum -y install docker-ce && \# 7. 启动Docker
systemctl start docker && \# 8. 测试是否安装成功
docker version
2.4、安装 Nginx
NGINX_VERSION="nginx-1.24.0" && \
VAR_PATH_SOFTWARE_DIR="/opt/module" && \# 进入到安装目录中下载Nginx
cd $VAR_PATH_SOFTWARE_DIR && \
wget https://nginx.org/download/$NGINX_VERSION.tar.gz && \# 解压后目录名: $NGINX_VERSION
tar -zxvf $NGINX_VERSION.tar.gz && \#安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre-devel && \