下载安装包:
java:
jdk-8u333-linux-aarch64.tar.gz
下载链接:
https://www.oracle.com/java/technologies/downloads/#java8
zookeeper:
zookeeper-3.4.13.tar.gz
下载链接:
https://zookeeper.apache.org/releases.html#download
http://archive.apache.org/dist/zookeeper/
clickhouse:
clickhouse-common-static-22.7.3.5-arm64.tgz
clickhouse-common-static-dbg-22.7.3.5-arm64.tgz
clickhouse-server-22.7.3.5-arm64.tgz
clickhouse-client-22.7.3.5-arm64.tgz
下载链接:
https://packages.clickhouse.com/tgz/stable/
ansible配置文件:
hosts_40_1:
- [hosts_40]
- ***.***.***.*** shard_id=1 myid=1
- ***.***.***.*** shard_id=2 myid=2
- ***.***.***.*** shard_id=3 myid=3
- ***.***.***.*** shard_id=4 myid=4
- ***.***.***.*** shard_id=5 myid=5
- ***.***.***.*** shard_id=6 myid=6
- ***.***.***.*** shard_id=7 myid=7
- ***.***.***.*** shard_id=8 myid=8
- ***.***.***.*** shard_id=9 myid=9
- ***.***.***.*** shard_id=10 myid=10
- [hosts_40:vars]
- ansible_ssh_user=xxx
- ansible_ssh_pass='***'
- ansible_sudo_pass='***'
1.创建/data目录
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "mkdir /data"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "mkdir /data"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "ls /data"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "ls /data"
2.格式化磁盘
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "mkfs.xfs -f /dev/sdb"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "mkfs.xfs -f /dev/sdb"
3.记录
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "cat << EOF >> /etc/fstab
- /dev/sdb /data xfs defaults 0 0
- EOF"
-
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "cat << EOF >> /etc/fstab
- /dev/sdb /data xfs defaults 0 0
- EOF"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "cat /etc/fstab"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "cat /etc/fstab"
4.挂载
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "mount -a"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "mount -a"
5.查看磁盘挂载是否成功
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "df -h"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "df -h"
1.查看防火墙
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "systemctl status firewalld.service"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "systemctl status firewalld.service"
2.如果没关防火墙需要关闭防火墙
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "systemctl stop firewalld.service"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "systemctl stop firewalld.service"
1.查看ip
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "hostname -i | cut -d ' ' -f3"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "hostname -i | cut -d ' ' -f3"
2.查询hosts
get_hosts.sh脚本:
- #!/bin/bash
-
- host=`hostname`
- ip=`hostname -i | cut -d ' ' -f3`
- echo $ip $host
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m script -a '/home/deployer/get_hosts.sh'
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m script -a '/home/deployer/get_hosts.sh'
3.整理好hosts后将hosts分发
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m copy -a "src=/home/deployer/hosts.txt dest=/home/deployer/ owner=deployer group=deployer mode=0777"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m copy -a "src=/home/deployer/hosts.txt dest=/home/deployer/ owner=deployer group=deployer mode=0777"
4.检查是否分发成功
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "ls -al /home/deployer"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "ls -al /home/deployer"
5.将分发后的hosts添加到每台机器
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "cat /home/deployer/hosts.txt >> /etc/hosts"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "cat /home/deployer/hosts.txt >> /etc/hosts"
6.检查是否添加成功
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "cat /etc/hosts"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "cat /etc/hosts"
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "mkdir /data/clickhouse"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "mkdir /data/clickhouse"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "mkdir /data/clickhouse/package"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "mkdir /data/clickhouse/package"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "mkdir /data/clickhouse/data"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "mkdir /data/clickhouse/data"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "mkdir /data/clickhouse/data/tmp"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "mkdir /data/clickhouse/data/tmp"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "chmod -R 777 /data/clickhouse"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "chmod -R 777 /data/clickhouse"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "chown -R deployer:deployer /data/clickhouse"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "chown -R deployer:deployer /data/clickhouse"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "mkdir /data/zookeeper"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "mkdir /data/zookeeper"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "mkdir /data/zookeeper/package"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "mkdir /data/zookeeper/package"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "mkdir /data/zookeeper/data"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "mkdir /data/zookeeper/data"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "mkdir /data/zookeeper/log"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "mkdir /data/zookeeper/log"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "chmod -R 777 /data/zookeeper"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "chmod -R 777 /data/zookeeper"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "chown -R deployer:deployer /data/zookeeper"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "chown -R deployer:deployer /data/zookeeper"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "mkdir /data/java"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "mkdir /data/java"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "mkdir /data/java/package"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "mkdir /data/java/package"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "ls -al /data/java/package"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "ls -al /data/java/package"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "chmod -R 777 /data/java"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "chmod -R 777 /data/java"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "chown -R deployer:deployer /data/java"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "chown -R deployer:deployer /data/java"
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m copy -a "src=/data/zookeeper/package/ dest=/data/zookeeper/package/ owner=deployer group=deployer mode=0777"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m copy -a "src=/data/zookeeper/package/ dest=/data/zookeeper/package/ owner=deployer group=deployer mode=0777"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "ls -al /data/zookeeper/package"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "ls -al /data/zookeeper/package"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m copy -a "src=/data/clickhouse/package/ dest=/data/clickhouse/package/ owner=deployer group=deployer mode=0777"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m copy -a "src=/data/clickhouse/package/ dest=/data/clickhouse/package/ owner=deployer group=deployer mode=0777"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "ls -al /data/clickhouse/package"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "ls -al /data/clickhouse/package"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m copy -a "src=/data/java/package/jdk-8u333-linux-aarch64.tar.gz dest=/data/java/package/jdk-8u333-linux-aarch64.tar.gz owner=deployer group=deployer mode=0777"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m copy -a "src=/data/java/package/jdk-8u333-linux-aarch64.tar.gz dest=/data/java/package/jdk-8u333-linux-aarch64.tar.gz owner=deployer group=deployer mode=0777"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "ls -al /data/java/package"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "ls -al /data/java/package"
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "tar -zxvf /data/java/package/jdk-8u333-linux-aarch64.tar.gz -C /data/java/package/"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "tar -zxvf /data/java/package/jdk-8u333-linux-aarch64.tar.gz -C /data/java/package/"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "mv /data/java/package/jdk1.8.0_333 /data/java/package/jdk1.8.0_141"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "mv /data/java/package/jdk1.8.0_333 /data/java/package/jdk1.8.0_141"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "ls -al /data/java/package"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "ls -al /data/java/package"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "echo 'export JAVA_HOME=/data/java/package/jdk1.8.0_141' >> /etc/profile"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "echo 'export JAVA_HOME=/data/java/package/jdk1.8.0_141' >> /etc/profile"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "echo 'export CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar' >> /etc/profile"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "echo 'export CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar' >> /etc/profile"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "echo -e 'export PATH=\$PATH:\$JAVA_HOME/bin' >> /etc/profile"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "echo -e 'export PATH=\$PATH:\$JAVA_HOME/bin' >> /etc/profile"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "more /etc/profile"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "more /etc/profile"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "source /etc/profile"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "source /etc/profile"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "java -version"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "java -version"
1.解压zookeeper
- ansible -i /etc/ansible/hosts_40_zk1 hosts_40 -m shell -a "tar -zxvf /data/zookeeper/package/zookeeper-3.4.13.tar.gz -C /data/zookeeper/package"
- ansible -i /etc/ansible/hosts_40_zk2 hosts_40 -m shell -a "tar -zxvf /data/zookeeper/package/zookeeper-3.4.13.tar.gz -C /data/zookeeper/package"
-
- ansible -i /etc/ansible/hosts_40_zk1 hosts_40 -m shell -a "ls -al /data/zookeeper/package/zookeeper-3.4.13"
- ansible -i /etc/ansible/hosts_40_zk2 hosts_40 -m shell -a "ls -al /data/zookeeper/package/zookeeper-3.4.13"
2.创建myid myid值在hosts文件中预先设置好
- ansible -i /etc/ansible/hosts_40_zk1 hosts_40 -m shell -a "touch /data/zookeeper/data/myid"
- ansible -i /etc/ansible/hosts_40_zk2 hosts_40 -m shell -a "touch /data/zookeeper/data/myid"
-
- ansible -i /etc/ansible/hosts_40_zk1 hosts_40 -m shell -a "echo -e '{{myid}}' >> /data/zookeeper/data/myid"
- ansible -i /etc/ansible/hosts_40_zk2 hosts_40 -m shell -a "echo -e '{{myid}}' >> /data/zookeeper/data/myid"
-
- ansible -i /etc/ansible/hosts_40_zk1 hosts_40 -m shell -a "cat /data/zookeeper/data/myid"
- ansible -i /etc/ansible/hosts_40_zk2 hosts_40 -m shell -a "cat /data/zookeeper/data/myid"
3.修改配置文件
3.1查看2181端口是否占用
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "netstat -tunlp|grep 2181"
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "netstat -tunlp|grep 2181"
将/data/zookeeper/package/zookeeper-3.4.13/conf/zoo.cfg配置文件进行两处修改
3.2将dataDir位置修改为
/data/zookeeper/data
3.3在配置文件zoo.cfg最后添加集群信息
- ###############cluster###############
- server.1=***.***.***.***:2888:3888
- server.2=***.***.***.***:2888:3888
- server.3=***.***.***.***:2888:3888
- server.4=***.***.***.***:2888:3888
- server.5=***.***.***.***:2888:3888
- server.6=***.***.***.***:2888:3888
- server.7=***.***.***.***:2888:3888
- server.8=***.***.***.***:2888:3888
- server.9=***.***.***.***:2888:3888
3.4将zoo.cfg配置文件分发到集群中其他机器
- ansible -i /etc/ansible/hosts_40_zk1 hosts_40 -m copy -a "src=/data/zookeeper/package/zookeeper-3.4.13/conf/zoo.cfg dest=/data/zookeeper/package/zookeeper-3.4.13/conf/zoo.cfg owner=deployer group=deployer mode=0777"
- ansible -i /etc/ansible/hosts_40_zk2 hosts_40 -m copy -a "src=/data/zookeeper/package/zookeeper-3.4.13/conf/zoo.cfg dest=/data/zookeeper/package/zookeeper-3.4.13/conf/zoo.cfg owner=deployer group=deployer mode=0777"
3.5查看通过是否成功
- ansible -i /etc/ansible/hosts_40_zk1 hosts_40 -m shell -a "tail -n 100 /data/zookeeper/package/zookeeper-3.4.13/conf/zoo.cfg"
- ansible -i /etc/ansible/hosts_40_zk2 hosts_40 -m shell -a "tail -n 100 /data/zookeeper/package/zookeeper-3.4.13/conf/zoo.cfg"
4.添加环境变量并刷新配置
- ansible -i /etc/ansible/hosts_40_zk1 hosts_40 -m shell -a "echo 'export ZOOKEEPER=/data/zookeeper/package/zookeeper-3.4.13' >> /etc/profile"
- ansible -i /etc/ansible/hosts_40_zk2 hosts_40 -m shell -a "echo 'export ZOOKEEPER=/data/zookeeper/package/zookeeper-3.4.13' >> /etc/profile"
-
- ansible -i /etc/ansible/hosts_40_zk1 hosts_40 -m shell -a "echo -e 'export PATH=\$PATH:\$ZOOKEEPER/bin' >> /etc/profile"
- ansible -i /etc/ansible/hosts_40_zk2 hosts_40 -m shell -a "echo -e 'export PATH=\$PATH:\$ZOOKEEPER/bin' >> /etc/profile"
- ansible -i /etc/ansible/hosts_40_zk1 hosts_40 -m shell -a "echo -e 'export PATH=\$PATH:\$ZOOKEEPER/bin' >> /home/deployer/.bash_profile"
- ansible -i /etc/ansible/hosts_40_zk2 hosts_40 -m shell -a "echo -e 'export PATH=\$PATH:\$ZOOKEEPER/bin' >> /home/deployer/.bash_profile"
-
- ansible -i /etc/ansible/hosts_40_zk1 hosts_40 -m shell -a "source /etc/profile"
- ansible -i /etc/ansible/hosts_40_zk2 hosts_40 -m shell -a "source /etc/profile"
5.启动zookeeper集群
启动
- ansible -i /etc/ansible/hosts_40_zk1 hosts_40 -m shell -a "source /etc/profile && zkServer.sh start"
- ansible -i /etc/ansible/hosts_40_zk2 hosts_40 -m shell -a "source /etc/profile && zkServer.sh start"
停止
- ansible -i /etc/ansible/hosts_40_zk1 hosts_40 -m shell -a "source /etc/profile && zkServer.sh stop"
- ansible -i /etc/ansible/hosts_40_zk2 hosts_40 -m shell -a "source /etc/profile && zkServer.sh stop"
查看节点状态
- ansible -i /etc/ansible/hosts_40_zk1 hosts_40 -m shell -a "source /etc/profile && zkServer.sh status"
- ansible -i /etc/ansible/hosts_40_zk2 hosts_40 -m shell -a "source /etc/profile && zkServer.sh status"
注意:
zookeeper相关的目录及目录下的文件都必须属于deployer,不然会出现运行失败的情况。
1.安装clickhouse-common-static
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "tar -zxvf /data/clickhouse/package/clickhouse-common-static-22.7.3.5-arm64.tgz -C /data/clickhouse/package"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "tar -zxvf /data/clickhouse/package/clickhouse-common-static-22.7.3.5-arm64.tgz -C /data/clickhouse/package"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "ls -al /data/clickhouse/package/clickhouse-common-static-22.7.3.5/install"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "ls -al /data/clickhouse/package/clickhouse-common-static-22.7.3.5/install"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "sh /data/clickhouse/package/clickhouse-common-static-22.7.3.5/install/doinst.sh"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "sh /data/clickhouse/package/clickhouse-common-static-22.7.3.5/install/doinst.sh"
2.安装clickhouse-common-static-dbg
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "tar -zxvf /data/clickhouse/package/clickhouse-common-static-dbg-22.7.3.5-arm64.tgz -C /data/clickhouse/package"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "tar -zxvf /data/clickhouse/package/clickhouse-common-static-dbg-22.7.3.5-arm64.tgz -C /data/clickhouse/package"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "ls -al /data/clickhouse/package/clickhouse-common-static-dbg-22.7.3.5/install"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "ls -al /data/clickhouse/package/clickhouse-common-static-dbg-22.7.3.5/install"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "sh /data/clickhouse/package/clickhouse-common-static-dbg-22.7.3.5/install/doinst.sh"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "sh /data/clickhouse/package/clickhouse-common-static-dbg-22.7.3.5/install/doinst.sh"
3.安装clickhouse-server
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "tar -zxvf /data/clickhouse/package/clickhouse-server-22.7.3.5-arm64.tgz -C /data/clickhouse/package"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "tar -zxvf /data/clickhouse/package/clickhouse-server-22.7.3.5-arm64.tgz -C /data/clickhouse/package"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "ls -al /data/clickhouse/package/clickhouse-server-22.7.3.5/install"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "ls -al /data/clickhouse/package/clickhouse-server-22.7.3.5/install"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "sh /data/clickhouse/package/clickhouse-server-22.7.3.5/install/doinst.sh"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "sh /data/clickhouse/package/clickhouse-server-22.7.3.5/install/doinst.sh"
4.安装clickhouse-client
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "tar -zxvf /data/clickhouse/package/clickhouse-client-22.7.3.5-arm64.tgz -C /data/clickhouse/package"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "tar -zxvf /data/clickhouse/package/clickhouse-client-22.7.3.5-arm64.tgz -C /data/clickhouse/package"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "ls -al /data/clickhouse/package/clickhouse-client-22.7.3.5/install"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "ls -al /data/clickhouse/package/clickhouse-client-22.7.3.5/install"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "sh /data/clickhouse/package/clickhouse-client-22.7.3.5/install/doinst.sh"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "sh /data/clickhouse/package/clickhouse-client-22.7.3.5/install/doinst.sh"
5.修改配置文件
5.1修改/etc/clickhouse-server/config.xml
0.0.0.0 /data/clickhouse/data/ /data/clickhouse/data/tmp/ -
- 添加
"clickhouse_remote_servers" /> "zookeeper-servers" optional="true" /> "macros" optional="true" /> "clickhouse_compression" optional="true" /> -
- 注释
5.2查看端口是否占用-8123、9000、9004、9005、9009
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "netstat -tunlp|grep 8123"
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "netstat -tunlp|grep 8123"
5.3修改/etc/clickhouse-server/config.d/data-paths.xml文件
/data/clickhouse/data /data/clickhouse/data/tmp
5.4添加/etc/metrika.xml
其中/etc/metrika.xml中的
-
-
shard_id -
macros_ip -
5.5修改/etc/clickhouse-server/users.xml中default用户的密码:
- echo -n password | openssl dgst -sha256
- 生成加密的password
- (stdin)= newpassword
- 修改/etc/clickhouse-server/users.xml
newpassword
5.6修改配置文件后统一分发:
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m copy -a "src=/etc/clickhouse-server/users.xml dest=/etc/clickhouse-server/users.xml owner=clickhouse group=clickhouse mode=0777"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m copy -a "src=/etc/clickhouse-server/users.xml dest=/etc/clickhouse-server/users.xml owner=clickhouse group=clickhouse mode=0777"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m copy -a "src=/etc/clickhouse-server/config.d/data-paths.xml dest=/etc/clickhouse-server/config.d/data-paths.xml owner=clickhouse group=clickhouse mode=0777"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m copy -a "src=/etc/clickhouse-server/config.d/data-paths.xml dest=/etc/clickhouse-server/config.d/data-paths.xml owner=clickhouse group=clickhouse mode=0777"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m copy -a "src=/etc/clickhouse-server/config.xml dest=/etc/clickhouse-server/config.xml owner=clickhouse group=clickhouse mode=0777"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m copy -a "src=/etc/clickhouse-server/config.xml dest=/etc/clickhouse-server/config.xml owner=clickhouse group=clickhouse mode=0777"
-
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m copy -a "src=/etc/metrika.xml dest=/etc/metrika.xml owner=clickhouse group=clickhouse mode=0777"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m copy -a "src=/etc/metrika.xml dest=/etc/metrika.xml owner=clickhouse group=clickhouse mode=0777"
5.7查看ip
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "hostname -i | cut -d ' ' -f3"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "hostname -i | cut -d ' ' -f3"
5.8替换/etc/metrika.xml中
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "sed -i 's/shard_id/{{shard_id}}/g' /etc/metrika.xml"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "sed -i 's/shard_id/{{shard_id}}/g' /etc/metrika.xml"
5.9替换/etc/metrika.xml中
update_file.sh脚本:
- #!/bin/bash
-
- ip=`hostname -i | cut -d ' ' -f3`
- sed -i 's/macros_ip/'$ip'/g' /etc/metrika.xml
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m script -a '/data/clickhouse/update_file.sh'
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m script -a '/data/clickhouse/update_file.sh'
6.启动服务
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "clickhouse start"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "clickhouse start"
7.查看进程
- ansible -i /etc/ansible/hosts_40_1 hosts_40 -m shell -a "ps -ef | grep clickhouse"
- ansible -i /etc/ansible/hosts_40_2 hosts_40 -m shell -a "ps -ef | grep clickhouse"
8.效果
页面查询
http://***.***.***.***:8123/play
通过系统表查询remote_servers的配置是否生效
SELECT * FROM system.clusters;
查看path是否配置正确
- SELECT
- name,
- path,
- formatReadableSize(free_space) AS free,
- formatReadableSize(total_space) AS total,
- formatReadableSize(keep_free_space) AS reserved
- FROM system.disks;
测试单表:
- CREATE TABLE default.test (
- id Int16,
- name String
- ) ENGINE = MergeTree()
- ORDER BY id;
测试分布式表:
- #先创建本地表
- CREATE TABLE default.test_local on cluster perftest_20shards_2replicas (
- id Int16,
- name String
- ) ENGINE = MergeTree()
- ORDER BY id;
- #创建分布式表
- CREATE TABLE IF NOT EXISTS default.test_distribute ON CLUSTER perftest_20shards_2replicas AS default.test_local
- ENGINE = Distributed(perftest_20shards_2replicas, default, test_local, rand());
欢迎关注“程序杂货铺”公众号,里面有精彩内容,欢迎大家收看^_^