其实吧,花太多时间在环境的部署上不值得,环境部署是运维的事,所以在没环境 的时候自己测试用 伪分布就可以了。
小白开工
1.打开win10 (确保连接了互联网),
2.鼠标左键单机开始按钮, 找到Microsoft Store,点击它,
3.会自动弹出它的窗口,找到右上角的搜索,
4.敲键盘,切换到英文输入法,输入"ubuntu",然后点击回车,等待片刻,出现下面这个界面;
5.然后选择18.04那个版本吧,其实三个版本都可以,我选择的18.04版本
6.点“18.04LTS”的图标,进入这个应用的详细说明界面,然后点击右上角的获取,等待下载完成
7.下载完成后出现类似于这个界面
8.点击右上角的启动,或者在菜单栏找到它,单击启动它。
9.这时候会没有出现正常的linux用户操作界面的话需要,进行下面操作10,否则,跳过操作10
10.鼠标右击开始,然后选择有“管理员”三个汉字的那一项,然后,左键点击,出现全覆盖窗口,鼠标点击是,出现下面界面,输入wsl --install,像下面界面中光标处一样
然后点击回车,最后根据提示重启计算机。
练家子
1.打开安装好的ubuntu,看到熟悉的文字界面,按照提示,取一个用户名和设置一个密码。比如root和123456,这里取名为cqie,密码也是
2.更新apt源,国内屏蔽了国外很多网址,所以用国内的源快,/etc/apt/sources.list中是默认源,用国内的源更新它,先清空,再粘贴:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
不同版本的ubuntu源是不一样的哟
2.安装jdk,安装好的ubuntu是能直接连接互联网的,所以,
sudo apt install openjdk-8-jdk
3.启动ssh服务
sudo service ssh start
service ssh status #查看状态
#没安装需要安装Sudo apt install openssh-server
#免密设置
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
4.先关闭ubuntu窗口,先准备hadoop集群需要的包,在windows界面,进入d盘,在根目录下创建一个文件夹,随便命名但不要随便改,这里命名为wslware
5.下载hadoop的linux包,点击这里下载,选择2.7.6这个版本,
6.Hive在这里、Hbase在这里、Kafka在这里、Phoenix在这里、Spark在这里 下载注意版本一致性,乱用版本会报错,我用的是apache-hive-3.1.2-bin、hadoop-2.7.6、hbase-2.4.7、kafka_2.12-3.0.0、phoenix-hbase-2.4-5.1.2-bin、spark-2.4.6-bin-hadoop2.7
7.下载的文件都放在d:/wslware中
像这样:
8.在上面这个界面空白处,shift+右键,然选择"在此处打开Linux shell"
ls *gz | xargs -n1 tar xzvf
9.然后是配置文件,按顺序来
1./etc/hosts 添加ip地址
sudo echo "172.24.0.22 myhost <hostname>" >>/etc/hosts #myhost表示固定的ip名,hostname会跟机器变动所以还是多取了个名字,hostname是主机名,需要手动填写,这里的ip可以改,也可以不改
//ip的查看命令
hostname -I | cut -d" " -f 1
//主机名的查看命令
hostname
2./etc/profile添加环境变量
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export HIVE_HOME=/mnt/d/wslware/apache-hive-3.1.2-bin
export HADOOP_HOME=/mnt/d/wslware/hadoop-2.7.6
export HBASE_HOME=/mnt/d/wslware/hbase-2.4.7
export SPARK_HOME=/mnt/d/wslware/spark-2.4.6-bin-hadoop2.7
export KAFKA_HOME=/mnt/d/wslware/kafka_2.12-3.0.0
export PHOENIX_HOME=/mnt/d/wslware/phoenix-hbase-2.4-5.1.2-bin
export JAVA_LIBRARY_PATH=/mnt/d/wslware/hadoop-2.7.6/lib/native
export PYTHONPATH=$SPARK_HOME/python
export PYSPARK_PYTHON=python3
export PATH=$PATH:$HIVE_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HBASE_HOME/bin:$SPARK_HOME/sbin:$KAFKA_HOME/bin:$SPARK_HOME/bin
3.hadoop on yarn
五个文件配置,都在路径D:\wslware\hadoop-2.7.6\etc\hadoop中
core-site.xml文件
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://myhost:9000</value>
</property>
<property>
<name>hadoop.proxyuser.cqie.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.cqie.groups</name>
<value>*</value>
</property>
</configuration>
hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:///tmp/hadoop-tmp/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:///tmp/hadoop-tmp/data</value>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>myhost:50090</value>
</property>
<property>
<name>dfs.permissions.enabled</name>
<value>false</value>
<description>
If "true", enable permission checking in HDFS.
If "false", permission checking is turned off,
but all other behavior is unchanged.
Switching from one parameter value to the other does not change the mode,
owner or group of files or directories.
</description>
</property>
<property>
<name>dfs.safemode.threshold.pct</name>
<value>0</value>
<description>
Specifies the percentage of blocks that should satisfy
the minimal replication requirement defined by dfs.replication.min.
Values less than or equal to 0 mean not to wait for any particular
percentage of blocks before exiting safemode.
Values greater than 1 will make safe mode permanent.
</description>
</property>
</configuration>
mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.log-aggregation-enable</name>
<value>true</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value>
</property>
</configuration>
hadoop-env.sh
在JAVA_HOME后面具体jdk路径
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
4.spark on yarn
配置两个文件,路径在D:\wslware\spark-2.4.6-bin-hadoop2.7\conf,改sbin两个文件名字
D:\wslware\spark-2.4.6-bin-hadoop2.7\sbin下的start-all.sh改名为start-all-spark.sh;stop-all.sh改为stop-all-spark.sh
conf路径下的spark-defaults.conf.template复制一份改名复制文件为spark-defaults.conf,并后面添加配置
spark.eventLog.dir=file:///tmp/spark-tmp
spark.eventLog.enabled=true
spark.yarn.historyServer.address http://myhost:18018
spark.master spark://myhost:7077
conf路径下的spark-env.sh.template复制一份并改名复制文件为spark-env.sh,并后面添加配置
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export HADOOP_CONF_DIR=/mnt/d/wslware/hadoop-2.7.6/etc/hadoop
export YARN_CONF_DIR=/mnt/d/wslware/hadoop-2.7.6/etc/hadoop
export SPARK_LOCAL_IP=myhost
export SPARK_MASTER_HOST=myhost
5.hive on spark
文件路径在D:\wslware\apache-hive-3.1.2-bin\conf
hive-env.sh配置
HADOOP_HOME=/mnt/d/wslware/hadoop-2.7.6
hive-site.xml配置
<configuration>
<property>
<name>hive.execution.engine</name>
<value>spark</value>
</property>
<!-- Hive spark参数 官方Parameters -->
<property>
<name>spark.master</name>
<value>myhost</value>
</property>
<property>
<name>spark.serializer</name>
<value>org.apache.spark.serializer.KryoSerializer</value>
</property>
<property>
<name>spark.executor.memeory</name>
<value>512m</value>
</property>
<property>
<name>spark.eventLog.enabled</name>
<value>true</value>
</property>
<property>
<name>spark.eventLog.dir</name>
<value>/mnt/d/wslware/spark-2.4.6-bin-hadoop2.7/logs</value>
</property>
<property>
<name>hive.enable.spark.execution.engine</name>
<value>true</value>
</property>
<property>
<name>spark.home</name>
<value>/mnt/d/wslware/spark-2.4.6-bin-hadoop2.7</value>
</property>
<!-- Hive 元数据 -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:derby:/tmp/metastore_db;databaseName=metastore_db;create=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>org.apache.derby.jdbc.EmbeddedDriver</value>
</property>
<property>
<name>hive.server2.authentication</name>
<value>NONE</value>
</property>
</configuration>
6.hbae
配置两个文件,路径在D:\wslware\hbase-2.4.7\conf
hbase-site.xml
<configuration>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.rootdir</name>
<value>file:///tmp/hbase-tmp</value>
</property>
<property>
<name>hbase.unsafe.stream.capability.enforce</name>
<value>false</value>
</property>
</configuration>
hbase-env.sh
在后面添加
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
7.kafka
配置两文件,路径在D:\wslware\kafka_2.12-3.0.0\config
server.properties 配置
advertised.listeners=PLAINTEXT://myhost:9092
log.dirs=/tmp/kafka-tmp/kafka-logs
zookeeper.connect=myhost:2182 #这个端口和phoenix 2181冲突,改成了2182
zookeeper.properties配置
dataDir=/tmp/kafka-tmp/zookeeper
clientPort=2182
8.phoenix
这个比较复杂,hbase在环境变量有HBASE_HOM,这里也不用配置什么,路径在D:\wslware\phoenix-hbase-2.4-5.1.2-bin,但是由于高版本阉割的原因,没有提供queryserver,而低版本又都是python2版本,不太可能为了phoenix都改一遍,为了适应python3版本,需要进行对官网的提供的源码进行编译。
最后需要的文件是:
phoenix-queryserver-6.0.1-SNAPSHOT-bin.tar.gz
下载 https://github.com/apache/phoenix-queryserver 整个项目,并解压
下载maven工具,并配置windows环境变量,点击这里下载,版本没限制,确保windows环境变量有maven
在解压的phoenix-queryserver 中
删除所有项目的src下的test目录,编译的时候这个就是幺蛾子,然后mvn clean package,编译前的具体做法参考这个
编译成功后,phoenix-queryserver-6.0.1-SNAPSHOT-bin.tar.gz解压后,把bin目录下的phoenix_queryserver_utils.py、queryserver.py、sqlline-thin.py放在D:\wslware\phoenix-hbase-2.4-5.1.2-bin\bin下,mvnl、ib目录和同级目录的两个jar包一起放在D:\wslware\phoenix-hbase-2.4-5.1.2-bin路径下,phoenix_queryserver_utils.py有点不走心,文件的尾的print没有括号,要么注释掉要么把括号补上,还要把phoenix-server-hbase-2.4-5.1.2.jar拷贝到D:\wslware\hbase-2.4.7\lib下面不然会出错
这里配置就完成了
最后要根据上面的配置在/tmp/路径下创建hadoop-tmp、spark-tmp、kafka-tmp、hbase-tmp、hive-tmp四个目录,确保他们是是自己用户的权限
启动集群
windows主机端设置ip
#这个步骤是变相固定ip
wsl -d Ubuntu-18.04 -u root ip addr add 172.24.0.22/24 broadcast 172.24.0.255 dev eth0 label eth0:1
netsh interface ip add address "vEthernet (WSL)" 172.24.0.1 255.255.255.0
linux服务端
linux启动sshd
sudo service ssh start
#sudo apt-get install openssh-server
#测试-service ssh status
hdfs 初始化
hdfs namenode –format
hive初始化
Schematool –dbType derby –initSchema
linux启动hadoop和yarn
start-all.sh
#stop-all.sh
linux启动spark
start-all-spark.sh
#stop-all-spark.sh
linux启动hive
nohup hiveserver2 &
#kill <runjar的进程号>
#beeline
linux启动hbase
start-hbase.sh
#stop-hbase.sh
linux启动kafka
${KAFKA_HOME}/bin/zookeeper-server-start.sh -daemon ${KAFKA_HOME}/config/zookeeper.properties
${KAFKA_HOME}/bin/kafka-server-start.sh -daemon ${KAFKA_HOME}/config/server.properties
#zookeeper-server-stop.sh && kafka-server-stop.sh
#删除/tmp/zookeeper
linux启动phoenix
${PHOENIX_HOME}/bin/queryserver.py start
#[start|stop]
#sqlline
windows python客户端访问集群
winows客户端访问需要kerberos,这里下载
然后要把
172.24.0.22 myhost
加在C:\Windows\System32\drivers\etc\hosts文件的后面
hbase 连接端口16000 web端口16010
phoenix 连接端口 8765
hdfs web端口50070
hive 连接端口10000 web端口10002
spark 连接端口8081 web端口8080
kafka 连接端口9092
hadoop 安装-> pyhdfs
import pyhdfs
fs = pyhdfs.HdfsClient(hosts='172.24.0.22,9000',user_name='cqie')
g=fs.get_home_directory()#返回这个用户的根目录
print(g)
print(fs.listdir("/"))
fs.copy_from_local("d:/abc.txt","/abc.txt")
print(fs.listdir("/"))
spark 安装-> pyspark
出现没有hadoop的报错,可以不理会,可以自己在网上找winutils.exe,2.7.1那个版本,然后弄个HADOOP_HOME的路径就可以了
from pyspark import SparkConf, SparkContext
conf = SparkConf().setMaster("spark://172.24.0.22:7077").setAppName("ttest").set("spark.driver.host", "172.24.0.1")
sc = SparkContext(conf=conf)
print(sc.version)
list_test = [1, 2, 3]
x = sc.parallelize(list_test)
y = x.map(lambda x: x * 2)
print(x.collect())
print(y.collect())
sc.stop()
hive 安装-> impala
from impala.dbapi import connect
conn = connect(host='172.24.0.22', port=10000, database='default', auth_mechanism="PLAIN")
cur = conn.cursor()
cur.execute('show tables')
print(cur.fetchall())
#pip3 install bit-array
#pip3 install thrift
#pip3 install thriftpy
#pip3 install pure-sasl
#pip install thrift-sasl
#pip3 install impyla
phoenix 安装-> phoenixdb
import phoenixdb.cursor
url = 'http://172.24.0.22:8765/'
conn = phoenixdb.connect(url, autocommit=True)
cursor = conn.cursor()
# cursor.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, username VARCHAR)")
# cursor.execute("UPSERT INTO users VALUES (?,?)", (1, 'admin'))
cursor.execute("select * from users")
rows = cursor.fetchall()
print(rows[0])
cursor.close()
conn.close()
kafka 安装-> kafka
创建topic
client = pykafka.KafkaClient(hosts="ip:port")
for i in client.brokers.values():
i.create_topics(topic_reqs=(Topic("mytopic1"), ))
消费者
from kafka import KafkaConsumer
consumer = KafkaConsumer('test', bootstrap_servers=['172.24.0.22:9092'])
for msg in consumer:
recv = "%s:%d:%d: key=%s value=%s" % (msg.topic, msg.partition, msg.offset, msg.key, msg.value)
print(recv)
生产者
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers='172.24.0.22:9092') # 连接kafka
msg = "Hello World".encode('utf-8') # 发送内容,必须是bytes类型
producer.send('test', msg) # 发送的topic为test
producer.close()
linux端口映射到win10主机
#这是映射
netsh interface portproxy add v4tov4 listenaddress=10.8.16.152 listenport=7077 connectaddress=172.24.0.22 connectport=7077
#查看
netsh interface portproxy show all
#删除
netsh interface portproxy delete v4tov4 listenaddress=10.8.16.152 listenport=9870
总结
正确的分享是帮助他人也是帮助自己
注意:
hadoop如果没有退出安全模式,退出安全模式:hadoop dfsadmin -safemode leave,应该用不上。
win10的python版本和linux的python版本一致,主机用户名问题,你hadoop,core.xml有设置,更改时也要更改