1、查看主机名
//查看一下当前主机名的情况,查看全部三种主机名
hostnamectl
//或者,查看全部三种主机名
hostnamectl status
//只查看静态、瞬态或灵活主机名,分别使用--static,--transient或--pretty选项
[root@wuhao ~]# hostnamectl --static
xh00
[root@wuhao ~]# hostnamectl --transient
xh01
[root@wuhao ~]# hostnamectl --pretty
//或者,查看到的是瞬态的(Tansient hostname)
hostname
//或者查看主机名配置文件,查看到的是静态的(Static hostname)
cat /etc/hostname
2、修改主机名(永久生效)
//永久性的修改主机名称,重启后能保持修改后的。
hostnamectl set-hostname xxx
hostnamectl set-hostname --static
hostnamectl set-hostname --pretty
hostnamectl set-hostname --transient
例如:
hostnamectl set-hostname hadoopStudy
hostnamectl set-hostname --static
hostnamectl set-hostname --pretty
hostnamectl set-hostname --transient
3、更新/etc/hosts
vim /etc/hosts
例:更新的内容如下
127.0.0.1 hadoopStudy
::1 hadoopStudy
可能造成的原因之一:Kafka与zookeeper无法连接上。
我的解决方法:
查看三个内容:1)查看主机名中是否有主机与ip地址的映射
vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.133.101 hadoopStudy hadoopStudy.hadoop.com
192.168.133.102 hadoopStudy2 hadoopStudy2.hadoop.com
192.168.133.103 hadoopStudy3 hadoopStudy3.hadoop.com
注:使用如下表示
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
2)查看zookeeper中文件zoo.cfg是否关联集群中的主机,
vim zoo.cfg
如下所示:
server.1=hadoopStudy:2888:3888
server.2=hadoopStudy2:2888:3888
server.3=hadoopStudy3:2888:3888
3)查看Kafka中文件server.properties是否设置zookeeper连接
vim server.properties
如下所示:
zookeeper.connect=hadoopStudy:2181,hadoopStudy2:2181,hadoopStudy3:2181
注:要查看相应的文件,首先要到指定的路径下,然后才能编写文件内容。
启动消费者时错误日志信息如下:
[2020-07-18 16:27:06,667] WARN Fetching topic metadata with correlation id 1 for topics [Set(four)] from broker [BrokerEndPoint(3,hadoopStudy3,9092)] failed (kafka.client.ClientUtils$)
java.nio.channels.ClosedChannelException
at kafka.network.BlockingChannel.send(BlockingChannel.scala:112)
at kafka.producer.SyncProducer.liftedTree1$1(SyncProducer.scala:80)
at kafka.producer.SyncProducer.kafka$producer$SyncProducer$$doSend(SyncProducer.scala:79)
at kafka.producer.SyncProducer.send(SyncProducer.scala:124)
at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:61)
at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:96)
at kafka.consumer.ConsumerFetcherManager$LeaderFinderThread.doWork(ConsumerFetcherManager.scala:68)
at kafka.utils.ShutdownableThread.run(ShutdownableThread.scala:64)
解决方法:配置主机名与ip地址的映射
vim /etc/hosts 进入配置,配置内容根据你当前主机的ip和主机名写入,例如下所示,
192.168.133.101 hadoopStudy hadoopStudy.hadoop.com
192.168.133.102 hadoopStudy2 hadoopStudy2.hadoop.com
192.168.133.103 hadoopStudy3 hadoopStudy3.hadoop.com