基本环境的搭建

本文详述了Linux基本环境的搭建,包括ip配置、防火墙设置、SSH连接、NTP时钟同步等。接着,逐步介绍了Hadoop的单节点伪分布式系统配置,包括Hadoop版本选择、JDK安装、各配置文件修改及启动脚本化。进一步,文章探讨了HA-hadoop分布式集群构建,涉及Zookeeper的搭建以及YARN相关配置。同时,还涵盖了Hive环境的搭建、Spark访问Hive的方法,以及standalone和Yarn环境下Spark的配置与启动。最后,解析了Yarn架构的基本组件和交互原理。
摘要由CSDN通过智能技术生成

一、基本环境

1.1 ip

 reboot (重启)
 网络服务器 service network start|stop|restart
 OS7: systemctl restart network 
 
 ip:
	查看:
		ip addr
		ifconfig
		ifconfig eth0 具体查看某一块网卡的ip信息
	修改:
		临时修改 
		  ifconfig eth0 192.168.111.3 关机 重启 ip将消失。
		永久修改(静态网卡):
		  vi /etc/sysconfig/network-scripts/ifcfg-eth0 
			  	DEVICE=eth0
				TYPE=Ethernet
				ONBOOT=yes
				NM_CONTROLLED=yes
				BOOTPROTO=static
				IPADDR=192.168.134.21
				NETMASK=255.255.255.0
				GATWAY=192.168.134.0
			
		  动态网卡:	
          network-scripts]# cat ifcfg-eth1 
		    DEVICE=eth1
			TYPE=Ethernet
			ONBOOT=yes
			NM_CONTROLLED=yes
			BOOTPROTO=dhcp
	

1.2 防火墙

基本使用:
	service iptables status 
	service iptables start
	service iptables stop
	service iptables restart
	
 OS7:
   状态 firewall-cmd --state
   停止:systemctl stop firewalld.service
   禁止firewall开机启动:systemctl disable firewalld.service 

关闭防火墙_开机自启:
   chkconfig iptables off|on

关闭selinux : 
   红帽子、centos公司定制的一种安全服务
   vi /etc/selinux/config
   SELINUX=disabled

SELinux模式:
	只能有 root 用户进行设置和修改
	可设置为enforcing,permissive或disabled
	RedHat linux操作系统中默认开启了防火墙,SELinux也处于启动状态,
	一般状态为enforing。致使很多服务端口默认是关闭的。等验证时有时连ping也ping不通.

1.3 主机名及映射

主机名:
	修改:
		vi /etc/sysconfig/network
			NETWORKING=yes
		    HOSTNAME=hadoop21.**.com
 SO7:hostnamectl set-hostname	
		    
linux 映射:
	 vi /etc/hosts	
	    
windows 映射 :
	 C:\Windows\System32\drivers\etc\hosts
	   192.168.111.3  hadoop1.**.com

1.4 服务器clone

集群搭建
     1.1 通过虚拟机软件,进行clone
     1.2 删除老机器的mac地址
         rm -rf /etc/udev/rules.d/70-persistent-net.rules
         修改ip地址:vi /etc/sysconfig/network-scripts/ifcfg-eth0 
         修改主机名:vi /etc/sysconfig/network  
         修改主机映射:vi /etc/hosts	
远程复制 
         scp /etc/hosts root@192.168.111.4:/etc
         scp 远程复制 文件夹 -r 
         scp -r  

1.5、SSH

[root@CentOSX ~]# ssh-keygen -t rsa
[root@CentOSX ~]# ssh-copy-id CentOSA
[root@CentOSX ~]# ssh-copy-id CentOSB
[root@CentOSX ~]# ssh-copy-id CentOSC

1.6、NTP时钟同步

方案
该方案目的:同步node1的时间为外部授时时间,然后node、node3的时间为同步node1的时间
先安装 ntp 再使用命令同步外部授时中心:ntpdate -u cn.pool.ntp.org 或 ntpdate -u ntp6.aliyun.com
1.ntp 
安装 yum install ntp 
启动服务 systemctl start ntpd 
查看是否启动 ps -ef | grep ntpd
开机启动 systemctl enable ntpd.service    
查看当前时间 date
查看当前时间和NTP服务的同步状态 timedatectl 
2.node1作为NTP Server,node2和node3作为NTP Client,node2和node3要跟node1同步时间,node1要去外部授时中心同步时间
1.配置 node1:
	1.配置前先使用命令同步外部授时中心:ntpdate -u cn.pool.ntp.org 或 ntpdate -u ntp6.aliyun.com
	2.vim /etc/ntp.conf
	  注释以下配置
		#server 0.centos.pool.ntp.org iburst
		#server 1.centos.pool.ntp.org iburst
		#server 2.centos.pool.ntp.org iburst
		#server 3.centos.pool.ntp.org iburst

	  增加如下配置:
		# 允许内网其他机器同步时间,如果不添加该约束默认允许所有IP访问本机同步服务。192.168.88.0为本局域网内的子网IP
		restrict 192.168.88.0 mask 255.255.255.0 nomodify notrap

		# 配置和上游标准时间同步
		server 210.72.145.44  # 中国国家授时中心
		server 133.100.11.8  #日本[福冈大学]
		server 0.cn.pool.ntp.org
		server 1.cn.pool.ntp.org
		server 2.cn.pool.ntp.org
		server 3.cn.pool.ntp.org

		# 配置允许上游时间服务器主动修改本机(内网ntp Server)的时间
		restrict 210.72.145.44 nomodify notrap noquery
		restrict 133.100.11.8 nomodify notrap noquery
		restrict 0.cn.pool.ntp.org nomodify notrap noquery
		restrict 1.cn.pool.ntp.org nomodify notrap noquery
		restrict 2.cn.pool.ntp.org nomodify notrap noquery
		restrict 3.cn.pool.ntp.org nomodify notrap noquery

		# 确保localhost有足够权限,使用没有任何限制关键词的语法。
		# 外部时间服务器不可用时,以本地时间作为时间服务。
		# 注意:这里不能改,必须使用127.127.1.0,否则会导致无法
		#在ntp客户端运行ntpdate serverIP,出现no server suitable for synchronization found的错误。
		#在ntp客户端用ntpdate –d serverIP查看,发现有“Server dropped: strata too high”的错误,并且显示“stratum 16”。而正常情况下stratum这个值得范围是“0~15”。
		#这是因为NTP server还没有和其自身或者它的server同步上。
		#以下的定义是让NTP Server和其自身保持同步,如果在ntp.conf中定义的server都不可用时,将使用local时间作为ntp服务提供给ntp客户端。
		#下面这个配置,建议NTP Client关闭,建议NTP Server打开。因为Client如果打开,可能导致NTP自动选择合适的最近的NTP Server、也就有可能选择了LOCAL作为Server进行同步,而不与远程Server进行同步。
		server 127.127.1.0  # local clock
		fudge 127.127.1.0  stratum 10

2.配置 node2、node3:
	1.vim /etc/ntp.conf
	  注释以下配置
		#server 0.centos.pool.ntp.org iburst
		#server 1.centos.pool.ntp.org iburst
		#server 2.centos.pool.ntp.org iburst
		#server 3.centos.pool.ntp.org iburst

	  增加如下配置:
		#配置上游时间服务器为本地的ntpd Server服务器
		server 192.168.88.100

		# 配置允许上游时间服务器主动修改本机的时间
		restrict 192.168.88.100 nomodify notrap noquery

1.7、mysql

11.MySQL 
 安装、配置 MySQL:(推荐该种安装方法)	
	1.查看是否安装了自带mysql:rpm -qa | grep mysql
	2.64位的MySQL(centOS 7 版本MySQL:mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz)解压到 /opt/model目录文件夹下
		cd /opt/model
		tar zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /opt/model
		mv mysql-5.7.24-linux-glibc2.12-x86_64 /opt/model/mysql
		rm -f mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
	       
	3.mkdir -p /opt/model/mysql/data
 	  mkdir -p /opt/model/mysql/database
 	  mkdir -p /opt/model/mysql/data/relay
 	  mkdir -p /opt/model/mysql/data/binlog
 	  mkdir -p /opt/model/mysql/data/tmp
 	  chmod -R 777 /opt/model/mysql/data
	  touch /opt/model/mysql/data/error.log
	  touch /opt/model/mysql/data/mysql.sock
	  touch /opt/model/mysql/data/mysql.pid
	4.(可以忽略)创建 mysql 用户组和 mysql 用户 , 把 mysql 目录所有者赋给 mysql 用户
		groupadd mysql
		useradd -r -g mysql mysql
		chown -R mysql:mysql mysql
		cd mysql
		主目录权限处理(查看是否有就得用户,有删除并新建用户)
			查看组和用户情况:cat /etc/group | grep mysql
			查看组和用户情况:cat /etc/passwd |grep mysql
		若存在,则删除原mysql用户:userdel -r mysql,会删除其对应的组和用户并在次查看。
			创建mysql组:groupadd mysql
			创建mysql用户:useradd -r -g mysql mysql
			修改目录拥有者:chown -R mysql:mysql /opt/model/mysql
	5.配置 vim /etc/my.cnf:my.cnf配置看另外一页,先删除原有的所有配置信息,然后添加新的进去
	6.初始化数据库 使用 mysqld 安装
		cd /opt/model/mysql/bin 
		root 用户(目前这个用户):./mysqld --initialize --user=root --basedir=/opt/model/mysql --datadir=/opt/model/mysql/database
		mysql 用户:./mysqld --initialize --user=mysql --basedir=/opt/model/mysql --datadir=/opt/model/mysql/database
	  	注意:
			1.执行上述语句进行初始化时,有可能打印出的显示信息中包括默认的登录密码:root@localhost:(该随机数字字母为自动生成的登录密码)
			  如果执行上述语句进行初始化时,没有任何打印信息的话,那么cat /opt/model/mysql/data/error.log文件中即能找到:root@localhost:(该随机数字字母为自动生成的登录密码)
			2.如果使用随机密码也无法登录mysql的话,那么需要重新执行如下步骤:
				1.删除 /opt/model/mysql 目录下的 database文件夹,然后执行 mkdir /opt/model/mysql/database
				2.cd /opt/model/mysql/bin
				  重新初始化 ./mysqld --initialize --user=root --basedir=/opt/model/mysql --datadir=/opt/model/mysql/database
				3.service mysql restart重启mysql后,再使用新的随机密码登录mysql
			3.如果执行上述语句时报错:./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory 
			  需要安装命令: yum install -y libaio
			  再执行 ./mysqld --initialize --user=root --basedir=/opt/model/mysql --datadir=/opt/model/mysql/database
	7./etc/profile环境变量配置
		vim /etc/profile
			export PATH="$PATH":/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
			export MYSQL_HOME=/opt/model/mysql
			export PATH="$PATH":"$MYSQL_HOME"/bin
			source /etc/profile
	8.开机服务启动设置:
		1.(第一种方法:目前使用这种即可)cp -a /opt/model/mysql/support-files/mysql.server /etc/init.d/mysql
		  (第二种方法)cp /opt/model/mysql/support-files/mysql.server /etc/init.d/mysqld   
			2.(第一种方法:目前使用这种即可)chmod 777 /etc/init.d/mysql
		  (第二种方法)chmod 777 /etc/init.d/mysqld
		  cd /etc/init.d
		  ll 查看到有mysql文件
		3.chkconfig --list mysql 查看mysql服务是否在服务配置中 
		  最后一行 显示 service mysql supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add mysql')
		  翻译为 服务mysql支持chkconfig,但没有在任何运行级别中引用(运行'chkconfig --add mysql')
		  因此需要把mysql注册为开机启动的服务 
			(第一种方法:目前使用这种即可)chkconfig --add mysql
			(第二种方法)chkconfig --add mysqld
		  然后再进行查看 chkconfig --list 
		  显示 mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
		       mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
		  如果看到mysql的服务,并且3,4,5都是on的话则成功,如果是off,则键入 
			chkconfig --level 2345 mysql on 
			chkconfig --level 2345 mysqld on
	9.mysql服务注册成功后,便可以使用以下命令进行启动 或 停止mysql   
		service mysql start 显示 Starting MySQL. SUCCESS!
		service mysql stop
		service mysql status
		service mysql restart
	  或者也可以使用 安全启动 方式 	
		cd /opt/model/mysql/bin 
		./mysqld_safe --user=root &
	  查看mysql进程是否启动成功:ps -ef | grep mysql

	10.创建快捷方式
		(已把mysql的bin目录路径配置到环境变量/etc/profile中后则不需要再创建快捷方式)ln -s /opt/model/mysql/bin/mysql /usr/bin
		服务启动后,直接运行 mysql -u root -padmin 即可登录,不需要进入到/opt/model/mysql/bin目录

	8.默认登录密码可以在两处地方找到
		1.可以在执行初始化数据库语句(./mysqld --initialize)显示的信息中查看到:root@localhost:(该随机数字字母为自动生成的登录密码)
		2.可以在 error.log日志(cat /opt/model/mysql/data/error.log)里查看
			cat /opt/model/mysql/data/error.log
			root@localhost: 后面的随机数字字母就是默认登录密码
			如果找不到可能默认是空,登录时无需密码直接回车 
		3.如果使用随机密码也无法登录mysql的话,那么需要重新执行如下步骤:
				1.删除 /opt/model/mysql 目录下的 database文件夹
				2.重新初始化 ./mysqld --initialize --user=root --basedir=/opt/model/mysql --datadir=/opt/model/mysql/database
				3.service mysql restart重启mysql后,再使用新的随机密码登录mysql
	9.登录mysql
		cd /opt/model/mysql/bin 
		./mysql -u root -p(该随机数字字母为自动生成的登录密码)
		set password = password('admin');
		grant all privileges on *.* to 'root' @'%' identified by 'admin';  
		flush privileges;
		exit

4.建立CM、Hive等需要的表(可以一次性粘贴执行完所有句子)
drop user 'hive'@'%';
FLUSH PRIVILEGES;  


create database hive default character set utf8;  
CREATE USER 'hive'@
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值