1.解压Kafka 把kafka的tgz文件解压放在/app下
- name: unarchive kafka
unarchive:
src: kafka_{{KafkaVersion}}.tgz
dest: /app
copy: yes
keep_newer: yes
owner: mcloud
group: mcloud
tags:
- unarchive_kafka
2.创建 zk/data 以及 /datalog 路径
- name: mkdir
file: path={{ item }} state=directory recurse=yes owner=mcloud group=mcloud mode=0755
with_items:
- "/app/kafka_{{KafkaVersion}}/zk/data"
- "/app/kafka_{{KafkaVersion}}/datalog"
tags:
- mkdir
3.把zookeeper.properties放在kafka的config目录
- name: template zookeeper.properties
template:
src: zookeeper.properties
dest: "{{ KafkaConfDir }}"
owner: mcloud
group: mcloud
mode: 0644
backup: yes
force: yes
tags:
- template_zookeeper
4.把kafka-server-start.sh放在kafka的bin目录
- name: template kafka ops
template:
src: kafka-server-start.sh
dest: "/app/kafka_{{KafkaVersion}}/bin/kafka-server-start.sh"
owner: mcloud
group: mcloud
mode: 0755
force: yes
tags:
- template_kafka
5.把变量的zoo_id写到kafka的zk/data/myid
- name: write myid file
shell: echo "{{zoo_id}}" > "{{ZkDataDir}}"/myid
tags:
- write_myid_file
- name: touch myid
file: path={{ ZkDataDir }}/myid state=file owner=mcloud group=mcloud mode=0644
tags:
- touch_myid
6.把server.properties放到kafka的config目录
- name: template server.properties
template:
src: server.properties
dest: "{{ KafkaConfDir }}"
owner: mcloud
group: mcloud
mode: 0644
backup: yes
force: yes
tags:
- template_server
7.把kafka-run-class.sh放到kafka的config目录
- name: template kafka-run-class.sh
template:
src: kafka-run-class.sh
dest: "{{ KafkaConfDir }}"
owner: mcloud
group: mcloud
mode: 0755
backup: yes
force: yes
tags:
- template_run-class
8.把kafka.service/zk.service放到systemd的启动目录
- name: copy kafka.service
become: yes
become_user: root
become_method: su
template:
src: kafka.service
dest: /usr/lib/systemd/system/kafka.service
owner: root
group: root
mode: 0644
backup: no
force: yes
tags:
- copy_kafka_service
9.systemctl enable zk.service/kafka.service
- name: enable kafka.service
become: yes
become_user: root
become_method: su
command: /usr/bin/systemctl enable kafka.service
ignore_errors: True
tags:
- enable_kafka_service
10.systemctl restart zk.service/kafka.service
- name: restart kafka.service
become: yes
become_user: root
become_method: su
command: /usr/bin/systemctl restart kafka.service
async: 45
tags:
- restart_kafka
分享下kafka.service文件
[Unit]
Description=kafka_2.12-2.8.0
After=syslog.target network.target remote-fs.target nss-lookup.target zk.service
[Service]
Environment="JAVA_HOME=/app/jdk1.8.0_92"
Environment="JMX_PORT=9999"
User=mcloud
Group=mcloud
Type=simple
ExecStart=/usr/bin/sh /app/kafka_2.12-2.8.0/bin/kafka-server-start.sh /app/kafka_2.12-2.8.0/config/server.properties
PrivateTmp=true
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=kafka_2.12-2.8.0
Restart=always
RestartSec=30
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
[Install]
WantedBy=multi-user.target
zk.service
[Unit]
Description=zk_{{KafkaVersion}}
After=syslog.target network.target remote-fs.target nss-lookup.target
Before=kafka.service
[Service]
Environment="JAVA_HOME=/app/jdk1.8.0_92"
User=mcloud
Group=mcloud
Type=simple
ExecStart=/usr/bin/sh /app/kafka_{{KafkaVersion}}/bin/zookeeper-server-start.sh /app/kafka_{{KafkaVersion}}/config/zookeeper.properties
PrivateTmp=true
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=zk_{{KafkaVersion}}
Restart=always
RestartSec=30
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
[Install]
WantedBy=multi-user.target
|