1、克隆flink源码
git clone https://github.com/apache/flink
2、maven构建flink包,留意下方对jdk版本的要求:
In addition you need Maven 3 and a JDK (Java Development Kit). Flink requires at least Java 8 to build.
mvn clean install -DskipTests
cd flink-dist mvn clean install
若无maven需要安装maven:macOS:brew install maven;ubuntu:apt-get install maven;centos:yum -y install maven
3、构建完成后flink根目录下,构建PyFlink的源码发布包和wheel包:
cd flink-python; python3 setup.py sdist bdist_wheel
4、构建好的源码发布包和wheel包位于./flink-python/dist/目录下。它们均可使用pip安装,比如:
pip install dist/*.tar.gz
5、因为安装了anaconda,pip将pyflink安装到了anaonda默认的路径下:
cd /anaconda3/lib/python3.7/site-packages/pyflink/
6、启动flink集群模式:
sudo bin/start-cluster.sh
启动后可在http://127.0.0.1:8081 查看flink webui
7、也可启动flink的Python交互式界面:
sudo bin/pyflink-shell.sh local
8、若想更改默认的Python交互工具为ipython, 简单修改启动脚本该行即可:
vim bin/pyflink-shell.sh
PYFLINK_PYTHON="${PYFLINK_PYTHON:-"python"}"
——>
PYFLINK_PYTHON="${PYFLINK_PYTHON:-"ipython"}"
注意:需要预先安装ipython
sudo pip3 install ipython -i [https://pypi.tuna.tsinghua.edu.cn/simple](https://pypi.tuna.tsinghua.edu.cn/simple)
9、maven构建的flink根目录下有几个flink的练习demo:
cd ~/flink/flink-examples/
练习demo
10、练习1:启动wordcount.py :
sudo bin/flink run -py examples/python/table/batch/word_count.py
Flink wordcount
wordcount 结果
11、练习2:提交jar包任务:
sudo bin/flink run -j flink-examples-batch/target/flink-examples-batch_2.11-1.10-SNAPSHOT-KMeans.jar
Flink KMeans
网友评论