1. 脚本安装
curl -sSL https://resource.fit2cloud.com/1panel/package/quick_start.sh -o quick_start.sh && sh quick_start.sh
2. 配置镜像加速
在容器-> 配置中设置,否则安装软件会失败。
https://docker.211678.top
https://docker.1panel.live
https://hub.rat.dev
https://docker.m.daocloud.io
https://do.nark.eu.org
https://dockerpull.com
https://dockerproxy.cn
https://docker.awsl9527.cn
3. 容器安装组件
通过应用商店直接安装了kafka、mysql组件。
mysql组件安装完成,可以直接连接成功的。
验证本地程序发送kafka测试。
def main(args: Array[String]): Unit = {
val topic = "test"
val props = new Properties()
props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"192.168.80.100:9092")
props.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,classOf[StringSerializer].getName)
props.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,classOf[StringSerializer].getName)
val producer = new KafkaProducer[String,String](props)
var a = 0
for(a <- 1 to 10){
println(a)
val metadata = producer.send(new ProducerRecord(topic, "key" + a)).get()
println(s"topic:${metadata.topic()} partition: ${metadata.partition()} offset:${metadata.offset()}")
}
producer.close()
}
在验证kafka组件连接时,出现下面异常。
24/08/13 16:14:25 WARN NetworkClient: [Producer clientId=producer-1] Error connecting to node 1Panel-kafka-FHRb:9092 (id: 0 rack: null)
java.net.UnknownHostException: 1Panel-kafka-FHRb
at java.net.InetAddress.getAllByName0(InetAddress.java:1281)
at java.net.InetAddress.getAllByName(InetAddress.java:1193)
at java.net.InetAddress.getAllByName(InetAddress.java:1127)
at org.apache.kafka.clients.ClientUtils.resolve(ClientUtils.java:104)
at org.apache.kafka.clients.ClusterConnectionStates$NodeConnectionState.currentAddress(ClusterConnectionStates.java:394)
at org.apache.kafka.clients.ClusterConnectionStates$NodeConnectionState.access$200(ClusterConnectionStates.java:354)
at org.apache.kafka.clients.ClusterConnectionStates.currentAddress(ClusterConnectionStates.java:142)
at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:952)
at org.apache.kafka.clients.NetworkClient.access$700(NetworkClient.java:68)
at org.apache.kafka.clients.NetworkClient$DefaultMetadataUpdater.maybeUpdate(NetworkClient.java:1124)
at org.apache.kafka.clients.NetworkClient$DefaultMetadataUpdater.maybeUpdate(NetworkClient.java:1015)
at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:554)
at org.apache.kafka.clients.producer.internals.Sender.runOnce(Sender.java:312)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:235)
at java.lang.Thread.run(Thread.java:748)
这里连接无法识别是容器的名称 1Panel-kafka-FHRb 不能识别。
192.168.80.100是我本地的虚拟机IP地址。
刚才的错误是我本地电脑连接时出现的,所以最直接的办法,在本地host添加映射。
注意:这里是我本地机器添加的映射
192.168.80.100 1Panel-kafka-FHRb
再次通过程序发送kafka成功。