前言:
今天小伙伴们对“java运行环境下载”大约比较珍视,咱们都需要剖析一些“java运行环境下载”的相关文章。那么小编在网上搜集了一些对于“java运行环境下载””的相关内容,希望咱们能喜欢,看官们一起来了解一下吧!1.安装JDK
若已安装jdk环境, 跳过此步骤。Kafka 使用Zookeeper 来保存相关配置信息, Kafka及Zookeeper 依赖Java 运行环境, 从oracle网站下载JDK 安装包, 解压安装:
在里面下载
> # mv jdk-8u201-linux-x64.tar.gz\?AuthParam\=1552888781_ef3c9e4f54bbd65f2097bd294d2cd884 jdk-8u201-linux-x64.tar.gz
> # tar -zxvf jdk-8u201-linux-x64.tar.gz
> # mv jdk1.8.0_201 /opt/java
设置Java 环境变量:
> # vim /etc/init.d/java
JAVA_HOME=/opt/java
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME PATH
> # source /etc/init.d/java
也可以选择yum install安装, 相应设置环境变量。
查看yum库中都有哪些jdk版本, 运行:
> # yum search java | grep jdk
选择版本进行安装:
> # yum install java-1.8.0-openjdk
> # java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
2. ZooKeeper框架安装
下载ZooKeeper
> # wget
> # tar -zxf apache-zookeeper-3.5.8-bin.tar.gz
> # cp -r apache-zookeeper-3.5.8-bin /usr/local/zookeeper
> # cd /usr/local/zookeeper/
> # mkdir data
> # cd conf
> # cp zoo_sample.cfg zoo.cfg
> # vim zoo.cfg
tickTime=2000
dataDir=/usr/local/zookeeper/data # 修改目录
clientPort=2181
initLimit=10
syncLimit=2
启动ZooKeeper服务器
> # cd ..
> # bin/zkServer.sh start conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
启动CLI
> # bin/zkCli.sh
......
f9c0000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]
停止Zookeeper服务器
连接服务器并执行所有操作后, 可以使用以下命令停止zookeeper服务器
> # bin/zkServer.sh stop
现在你已经在你的机器上成功安装了Java和ZooKeeper。
3 Apache Kafka安装
从官网()下载Kafka 安装包,解压安装:
> # wget
> # tar -zxvf kafka_2.13-2.5.1.tgz
> # mv kafka_2.13-2.5.1 /usr/local/kafka
> # cd /usr/local/kafka/
启动服务器
> # bin/kafka-server-start.sh config/server.properties
......
[2020-11-10 16:53:28,129] INFO [KafkaServer id=0] started (kafka.server.KafkaServer)
启动并转入后台
> # bin/kafka-server-start.sh config/server.properties &
> # bin/kafka-server-start.sh config/server.properties >>/dev/null 2>&1 &
停止服务器
> # bin/kafka-server-stop.sh config/server.properties
测试
> # jps
bash: jps: 未找到命令...
解决方法: 升级java版本
> # yum update -y java-1.8.0-openjdk-devel.x86_64
> # java -version
openjdk version "1.8.0_262"
OpenJDK Runtime Environment (build 1.8.0_262-b10)
OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)
> # jps
55859 Jps
25396 QuorumPeerMain
55412 -- main class information unavailable
> # netstat -lnp | grep 2181
tcp6 0 0 :::2181 :::* LISTEN 25396/java
zookeeper的进程ID为25396, 在2181端口监听
> # netstat -lnp | grep 9092
tcp6 0 0 :::9092 :::* LISTEN 55412/java
Kafka的进程ID为55412, 占用端口为9092
4、配置开机自启(systemctl)
在 /lib/systemd/system/ 目录下创建 zookeeper服务和 kafka 服务的配置文件。
> # cd /usr/lib/systemd/system/
> # vim zookeeper.service
[Unit]
Description=zookeeper.service
After=network.target
ConditionPathExists=/usr/local/zookeeper/conf/zoo.cfg
[Service]
Type=forking
User=root
Group=root
ExecStart=/usr/local/zookeeper/bin/zkServer.sh start
ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop
[Install]
WantedBy=multi-user.target
> # vim kafka.service
[Unit]
Description=Apache Kafka server (broker)
After=network.target zookeeper.service
ConditionPathExists=/usr/local/kafka/config/server.properties
[Service]
Type=simple
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
User=root
Group=root
ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh
[Install]
WantedBy=multi-user.target
刷新配置
> # systemctl daemon-reload
zookeeper、kafka服务加入开机自启
> # systemctl enable zookeeper
> # systemctl enable kafka
使用systemctl启动/关闭/重启 zookeeper、kafka服务systemctl start/stop/restart zookeeper/kafka
> # systemctl start zookeeper
> # systemctl start kafka
查看状态。
> # systemctl status zookeeper
> # systemctl status kafka
注:启动kafka前必须先启动zookeeper
开放端口号:
> # firewall-cmd --permanent --zone=public --add-port=9092/tcp
> # firewall-cmd --reload
kafka安装失败原因:
bin/kafka-server-start.sh config/server.properties
Classpath is empty. Please build the project first e.g. by running './gradlew jar -PscalaVersion=2.12.10'
原因
, 下载的是源码, 不是binary
安装librdkafka
下载地址:
> # wget -O librdkafka-1.5.2.tar.gz
> # tar -zxvf librdkafka-1.5.2.tar.gz
> # cd librdkafka-1.5.2/
> # ./configure
> # make
> # make install
安装php-rdkafka
下载地址:
> # wget
> # tar -zxvf rdkafka-4.0.4.tgz
> # cd rdkafka-4.0.4/
> # phpize
> # ./configure --with-php-config=php-config
> # make
> # make install
官方扩展下载地址:
在php.ini中添加
extension=rdkafka.so
注意:
window下 PHP 扩展安装的方法
librdkafka.dll 复制到 php-7.2.31-nts目录下
php_rdkafka.dll 复制到 php-7.2.31-nts/ext目录下
操作系统: CentOS7.6 + PHP+7.2.31 + zookeeper3.5.8 + kafka-2.5.1 + librdkafka1.5.2 + rdkafka-4.0.4
PHP环境: PHP7.2.31
注意:
Kafka3.0发布, 离彻底去掉ZooKeeper更进一步
标签: #java运行环境下载