一、虚拟机下载安装
1、VirtualBox下载
2、Vagrant下载
3、Box下载 - 类比镜像
4、详细安装参考:Vagrant 与 VirtualBox 的保姆级安装教程
5、使用 Vagrant
在 VirtualBox
上初始化一台虚拟机:
# 根据 .box 文件生成系统镜像到 vagrant
vagrant box add centos7 ..../centos7.box
vagrant box list # 列出已加载的 box
vagrant box remove boxname # 移除 box
# vagrant environment init.
# 生成 Vagrantfile 配置文件
vagrant init test-vm
vagrant up # 根据配置启动 VM
vagrant ssh # 连接到 VM。默认用户 vagrant/vagrant、root/vagrant
# 修改配置,使xshell等能连接
# sudo vi /etc/ssh/sshd_config
> PermitRootLogin yes # 修改
> PasswordAuthentication yes # 修改
sudo systemctl restart sshd # 重启sshd服务
sudo passwd root # 两次确认修改root密码
二、docker安装
1、官方参考文档
2、简略过程
# 1.Uninstall old versions
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# 2.Install the yum-utils package
sudo yum install -y yum-utils
# 3.Set up the repository
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
# 4.Install Docker Engine
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# https://68qxu081.mirror.aliyuncs.com
# 5.Start Docker
sudo systemctl start docker
sudo systemctl enable docker
三、docker相关组件安装
1、mysql
docker pull mysql:5.7
# 启动容器及配置
docker run -d \
--name mysql \
--restart=always \
-p 3306:3306 \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
mysql:5.7
# /mydata/mysql/conf/my.conf,mysql的外挂配置信息
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
2、redis
mkdir -p /mydata/redis/conf
touch /mydata/redis/conf/redis.conf
echo "appendonly yes" >> /mydata/redis/conf/redis.conf
docker pull redis
docker run \
--name redis \
--restart=always \
-p 6379:6379 \
-v /mydata/redis/data:/data \
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
-d redis redis-server /etc/redis/redis.conf
3、nacos
docker pull nacos/nacos-server
docker run -d \
--name nacos \
--restart=always \
-p 8848:8848 \
-p 9848:9848 \
-p 9849:9849 \
-e MODE=standalone \
-e JVM_XMS=256m \
-e JVM_XMX=256m \
nacos/nacos-server
http://虚拟机ip:8848/nacos
4、elasticsearch
mkdir -p /mydata/elasticsearch/config
mkdir -p /mydata/elasticsearch/data
echo "http.host: 0.0.0.0" >/mydata/elasticsearch/config/elasticsearch.yml
chmod -R 777 /mydata/elasticsearch/
docker pull elasticsearch:7.6.2
docker run \
--name elasticsearch \
--restart=always \
-p 9200:9200 \
-p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx512m" \
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.6.2
http://虚拟机ip:9200/
5、kibana
docker pull kibana:7.6.2
docker run \
--name kibana \
--restart=always \
-e ELASTICSEARCH_HOSTS=http://192.168.56.101:9200 \
-p 5601:5601 \
-d kibana:7.6.2
http://虚拟机ip:5601/
6、nginx
mkdir -p /mydata/nginx/conf
mkdir -p /mydata/nginx/log
mkdir -p /mydata/nginx/html
docker pull nginx
docker run --name nginx -p 80:80 -d nginx
docker cp nginx:/etc/nginx/nginx.conf /mydata/nginx/conf/
docker cp nginx:/etc/nginx/conf.d /mydata/nginx/conf/
docker cp nginx:/usr/share/nginx/html /mydata/nginx/
docker run \
-p 80:80 \
--name nginx \
--restart=always \
-v /mydata/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /mydata/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /mydata/nginx/log:/var/log/nginx \
-v /mydata/nginx/html:/usr/share/nginx/html \
-d nginx
http://虚拟机ip:80/
7、rabbitmq
docker pull rabbitmq:management
docker run \
--name rabbitmq \
--restart=always \
--publish 5671:5671 \
--publish 5672:5672 \
--publish 4369:4369 \
--publish 25672:25672 \
--publish 15671:15671 \
--publish 15672:15672 \
-d rabbitmq:management
http://虚拟机ip:15672/
8、logstash
docker pull logstash:7.6.2
mkdir -p /mydata/logstash/conf.d
mkdir /mydata/logstash/log
vim logstash.yml
logstash.yml
path.config: /mydata/logstash/conf.d/*.conf
path.logs: /mydata/logstash/log
9、mongodb
docker pull mongo:latest
# 创建mongodb目录用于存放mongodb数据
mkdir mongodb
cd mongodb
# 默认运行,无密码
docker run -p 27017:27017 -v $PWD/data/db:/data/db --name mongodb -d mongo
# 进入容器
docker exec -it mongodb mongo admin
# 创建账号
db.createUser({ user: 'root', pwd: '742740', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });
# 退出
exit
四、hadoop相关组件安装
0、参考文档
1、时间同步
查看时间,设置时区:
# 查看时间
date
# 选择时区
tzselect
# 设置时区并生效
echo "TZ='Asia/Shanghai'; export TZ" >> /etc/profile && source /etc/profile
三台机器安装时间同步协议,yum install -y ntp
,master作为ntp服务器,修改ntp配置文件,vim /etc/ntp.conf
如下:
#注释掉server 0 ~ n,新增
server 127.127.1.0
fudge 127.127.1.0 stratum 10
# 重启ntp服务(master上执行)
systemctl restart ntpd
# 从节点同步主节点时间
ntpdate master
设置定时任务去同步集群时间:
crontab -e # 添加定时任务
30 * * * * /usr/sbin/ntpdate master >> /root/log/ntpdate.log 2>&1 # 设置定时任务
crontab -l # 查看定时任务
2、配置ssh免密
# 1.生成公钥和私钥
ssh-keygen -t rsa
# 2.连续按3次Enter键,会在当前用户家目录下生成隐藏目录.ssh,里面包含私钥id_rsa和公钥id_rsa.pub
# 3.将公钥复制到要免密登录的服务器上:ssh-copy-id 服务器名
ssh-copy-id slave1
ssh-copy-id slave2
3、hive
拷贝 mysql 驱动到 lib 目录下。配置
hive-site.xml
内容如下:
<configuration>
<!-- jdbc 连接的 URL -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://master:3306/metastore?useSSL=false</value>
</property>
<!-- jdbc 连接的 Driver-->
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<!-- jdbc 连接的 username-->
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<!-- jdbc 连接的 password -->
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>root</value>
</property>
<!-- Hive 元数据存储版本的验证 -->
<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
</property>
<!--元数据存储授权-->
<property>
<name>hive.metastore.event.db.notification.api.auth</name>
<value>false</value>
</property>
<!-- Hive 默认在 HDFS 的工作目录 -->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
</configuration>
# mysql 新建数据库
create database metastore;
# 初始化 hive 元数据库
schematool -initSchema -dbType mysql -verbose
# 运行 hiveserver2 服务
nohup hiveserver2 > hiveserver2.out 2>&1 &
# beeline 交互式命令行连接
beeline -u jdbc:hive2://master:10000 -n root
五、组件安装
1、mysql
安装 mysql:
# 检查当前系统是否安装过mysql
rpm -qa | grep mariadb
# 有则卸载
rpm -e --nodeps mariadb-libs
# 上传并解压mysql安装包
tar -xf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
# 安装目录下执行rpm安装,顺序执行。
# 若linux是最小化安装则安装server时可能会出现问题,可通过`yum install -y libaio`安装缺少的依赖`yum install -y net-tools`
sudo rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
删除 /etc/my.cnf 文件中 datadir 指向的目录下的所有内容,如果有内容的情况下:
# 初始化数据库
mysqld --initialize --user=mysql
# 查看临时生成的 root 用户的密码
cat /var/log/mysqld.log
# 启动 mysql 服务
systemctl start mysqld
# 登录 mysql 数据库,用刚查到的临时密码
mysql -uroot -p
# 必须先修改 root 用户的密码,否则执行其他的操作会报错
set password = password("新密码");
# 修改 mysql 库下的 user 表中的 root 用户允许任意 ip 连接
update mysql.user set host='%' where user='root';
flush privileges;