青浦手机网站建设,建筑公司经营范围有哪些,成华区网站开发,wordpress查看原图前提条件#xff1a;先了解集群搭建流程是什么样#xff0c;需要改哪些配置#xff0c;有哪些环境#xff0c;这个文章目的是简化部署。 clickhouse运维篇#xff08;一#xff09;#xff1a;docker-compose 快速部署clickhouse集群 clickhouse运维篇#xff08;二先了解集群搭建流程是什么样需要改哪些配置有哪些环境这个文章目的是简化部署。 clickhouse运维篇一docker-compose 快速部署clickhouse集群 clickhouse运维篇二多机器手动部署ck集群
!https://i-blog.csdnimg.cn/direct/7677be0676904a7687c2f4cc8aef0a46.png
项目目录解析 $ tree .
.
├── cluster.conf #集群配置 集群包含哪些机器、端口分别为多少
├── config
│ ├── config_node1.xml # 生成的ck节点配置文件
│ ├── config_node2.xml
│ ├── config_template.xml # config模版
│ ├── users_node1.xml # 生成的ck节点用户配置文件
│ ├── users_node2.xml
│ └── users_template.xml # users模版
├── dep #下面包含需要的远程依赖 zookeeper、clickhouse、jdk根据自己的需求更改
├── gen_cluster_config.sh
├── gen_login_cmd.sh
├── install.conf # 远程登录的主机conf需要在跳板机或者中间机器上去ssh、scp使用
└── main.sh #启动入口1、main.sh
CUR_FOLDER$(cd /Users/admin/scripts/my_app/ckcluster;pwd). ${CUR_FOLDER}/cluster.conf
. ${CUR_FOLDER}/gen_cluster_config.sh
. ${CUR_FOLDER}/gen_login_cmd.shCONFIG_FOLDER${CUR_FOLDER}/config
DEP_FOLDER${CUR_FOLDER}/dep
TEMPLATE_FILE${CONFIG_FOLDER}/config_template.xmlif [ ! -d $CONFIG_FOLDER ]; thenmkdir -p $CONFIG_FOLDER
fiif [ ! -d $DEP_FOLDER ]; thenmkdir -p $DEP_FOLDER
fizk_index1
# 首先读取所有节点信息并根据 shard 进行分组
while true; dohost_varzk_node_${zk_index}_host# 检查所有变量是否为空若有一个为空则跳出循环if [ -z ${!host_var} ]; thenbreakfi# 远程安装jdk、zookeeperinstall_path$(get_install_path ${!host_var})echo $(get_scp_command ${!host_var} . ${DEP_FOLDER}/jdk-8u202-nonroot.tar.gz ${DEP_FOLDER}/apache-zookeeper-3.7.2-bin.tar.gz)get_scp_command ${!host_var} . ${DEP_FOLDER}/jdk-8u202-nonroot.tar.gz ${DEP_FOLDER}/apache-zookeeper-3.7.2-bin.tar.gzecho $(get_ssh_command ${!host_var} cd ${install_path};tar -xzvf ${install_path}/jdk-8u202-nonroot.tar.gz)echo $(get_ssh_command ${!host_var} cd ${install_path};tar -xzvf ${install_path}/apache-zookeeper-3.7.2-bin.tar.gz)get_ssh_command ${!host_var} cd ${install_path};tar -xzvf ${install_path}/jdk-8u202-nonroot.tar.gzget_ssh_command ${!host_var} cd ${install_path};tar -xzvf ${install_path}/apache-zookeeper-3.7.2-bin.tar.gzzk_index$((zk_index 1))
done# 生成ck集群配置文件
gen_config# 远程安装clickhouse
ck_index1
# 首先读取所有节点信息并根据 shard 进行分组
while true; dohost_varck_node_${ck_index}_host# 检查所有变量是否为空若有一个为空则跳出循环if [ -z ${!host_var} ]; thenbreakfi
# users_config/opt/appaduudit/my_app-2.4/clickhouse-23.4.2.9/ck_node_1/config/users_node.xml/users_config install_path$(get_install_path ${!host_var}) get_scp_command ${!host_var} . ${DEP_FOLDER}/clickhouse-23.4.2.9.tar.gzecho $(get_ssh_command ${!host_var} cd ${install_path};tar -xzvf ${install_path}/clickhouse-23.4.2.9.tar.gz)NODE_CK_PATH${BASE_CK_PATH}/ck_node_${ck_index}echo $(get_scp_command ${!host_var} ${NODE_CK_PATH}/config ${CONFIG_FOLDER}/user_node${ck_index}.xml)get_scp_command ${!host_var} ${NODE_CK_PATH}/config ${CONFIG_FOLDER}/config_node${ck_index}.xmlget_scp_command ${!host_var} ${NODE_CK_PATH}/config ${CONFIG_FOLDER}/users_node${ck_index}.xmlecho $(get_ssh_command ${!host_var} ${install_path}/clickhouse-23.4.2.9.tar.gz/bin/clickhouse server --config-file ${install_path}/config_node${ck_index}.xml)get_ssh_command ${!host_var} ${install_path}/clickhouse-23.4.2.9.tar.gz/bin/clickhouse server --config-file ${install_path}/config_node${ck_index}.xml ck_index$((ck_index 1))
done2、cluster.conf
# 定义变量
target_install_path/opt/app/ck_cluster
BASE_CK_PATH/opt/app/my_app-2.4/clickhouse-23.4.2.9
CK_CLUSTER_NAMEmy_ck_cluster_test#port为zk的clientPort
zk_node_1_host172.168.1.206
zk_node_1_port8551zk_node_2_host172.168.1.207
zk_node_2_port8551zk_node_3_host172.168.1.208
zk_node_3_port8551ck_node_1_host172.168.1.206
ck_node_1_tcp_port8601
ck_node_1_http_port8602
ck_node_1_interserver_http_port8603
ck_node_1_userdefault
ck_node_1_passwordpassword
ck_node_1_shard01
ck_node_1_replicareplica_63ck_node_2_host172.168.1.207
ck_node_2_tcp_port8611
ck_node_2_http_port8612
ck_node_2_interserver_http_port8613
ck_node_2_userdefault
ck_node_2_passwordpassword
ck_node_2_shard02
ck_node_2_replicareplica_63#ck_node_3_hostck_host_3
#ck_node_3_tcp_portck_tcp_port_3
#ck_node_3_http_portck_http_port_3
#ck_node_3_interserver_http_portck_interserver_http_port_3
#ck_node_3_useruser3
#ck_node_3_passwordpassword3
#ck_node_3_shard02
#ck_node_3_replicareplica_2093、install.conf
ssh.172.168.1.206root:app:/opt/app/ck_cluste
ssh.172.168.1.207admin:adminpass:/opt/app/ck_cluste
ssh.172.168.1.208admin:adminpass:/opt/app/ck_cluste4、gen_login_cmd.sh
#!/bin/bash
cd /Users/admin/scripts/my_app/ckcluster
# 读取配置文件并解析
CONFIG_FILEinstall.conf
declare -A HOSTSwhile IFS read -r key user_password || [[ -n $key ]]; dokey$(echo $key | xargs)user_password$(echo $user_password | xargs)if [[ $key ssh.* ]]; thenhost${key#ssh.}HOSTS[$host]$user_passwordfi
done $CONFIG_FILE# 获取 SSH 命令
get_ssh_command() {local host$1local cmd$2local user_password${HOSTS[$host]}IFS: read -r user password install_path $user_password# echo sshpass -p $password ssh $user$host $cmdecho sshpass -p $password ssh $user$host \$cmd\}# 获取 SCP 命令
get_scp_command() {local host$1local extra_dir$2local files$3 local user_password${HOSTS[$host]}# root:idss:/opt/idss/ck_clusteIFS: read -r user password install_path $user_passwordif [ $extra_dir ! . ]; theninstall_path$extra_dirfimkdir_cmd$(get_ssh_command $host mkdir -p $install_path)eval $mkdir_cmdecho sshpass -p $password scp -r $files $user$host:$install_path
}get_install_path() {local host$1local user_password${HOSTS[$host]}# root:idss:/opt/idss/ck_clusteIFS: read -r user password install_path $user_passwordecho $install_path
}
# ssh_command$(get_scp_command 10.87.102.206 /Users/admin/scripts/my_app/ckcluster/dep/jdk-8u202-nonroot.tar.gz /Users/admin/scripts/my_app/ckcluster/dep/apache-zookeeper-3.7.2-bin.tar.gz)
# echo $ssh_command
# scp_command$(get_ssh_command 10.87.102.206 ls /opt/idss/ck_cluste)
# echo $scp_command
# $scp_command5、gen_cluster_config.sh
#!/bin/bash
# 定义基础路径和模板文件名function gen_config() {# 生成 zookeeper 配置
ZOOKEEPER_CONFIGzookeeper\n
# 循环遍历 zk_node_*_host 和 zk_node_*_port 变量
zk_index1
while true; dohost_varzk_node_${zk_index}_hostport_varzk_node_${zk_index}_port# 检查变量是否已定义如果未定义则跳出循环if [ -z ${!host_var} ] || [ -z ${!port_var} ]; thenbreakfiZOOKEEPER_CONFIG node index\${zk_index}\\nZOOKEEPER_CONFIG host${!host_var}/host\nZOOKEEPER_CONFIG port${!port_var}/port\nZOOKEEPER_CONFIG /node\nzk_index$((zk_index 1))
done
ZOOKEEPER_CONFIG/zookeeper# 生成 remote_servers 配置
declare -A shard_nodes config_contentck_index1
# 首先读取所有节点信息并根据 shard 进行分组
while true; dohost_varck_node_${ck_index}_hosttcp_port_varck_node_${ck_index}_tcp_porthttp_port_varck_node_${ck_index}_http_portinterserver_port_varck_node_${ck_index}_interserver_http_portuser_varck_node_${ck_index}_userpassword_varck_node_${ck_index}_passwordshard_varck_node_${ck_index}_shardreplica_varck_node_${ck_index}_replica# 检查所有变量是否为空若有一个为空则跳出循环if [ -z ${!host_var} ] || \[ -z ${!tcp_port_var} ] || \[ -z ${!http_port_var} ] || \[ -z ${!interserver_port_var} ] || \[ -z ${!user_var} ] || \[ -z ${!password_var} ] || \[ -z ${!shard_var} ] || \[ -z ${!replica_var} ]; thenbreakfi# 将当前节点信息存入以 shard 为 key 的数组shard_nodes[${!shard_var}]$(cat -NODEreplicahost${!host_var}/hostport${!tcp_port_var}/portuser${!user_var}/userpassword${!password_var}/password/replica\n
NODE)NODE_CK_PATH${BASE_CK_PATH}/ck_node_${ck_index}config_template$(cat ${CONFIG_FOLDER}/config_template.xml)config_template$(echo $config_template | sed s|\${BASE_CK_PATH}|${NODE_CK_PATH}|g)config_template$(echo $config_template | sed s|\${HTTP_PORT}|${!http_port_var}|g)config_template$(echo $config_template | sed s|\${TCP_PORT}|${!tcp_port_var}|g)config_template$(echo $config_template | sed s|\${INTERSERVER_HTTP_PORT}|${!interserver_port_var}|g)config_template$(echo $config_template | sed s|\${MACROS_SHARD}|${!shard_var}|g)config_template$(echo $config_template | sed s|\${MACROS_REPLICA}|${!replica_var}|g)config_template$(echo $config_template | sed s|\${CK_PASSWORD}|${!password_var}|g) config_template$(echo $config_template | sed s|\${ck_index}|${!ck_index}|g) # 将生成的配置内容存入字典config_content[config_node${ck_index}]$config_template# users文件生成users_template$(cat ${CONFIG_FOLDER}/users_template.xml)users_template$(echo $users_template | sed s|\${CK_PASSWORD}|${!password_var}|g) echo -e $users_template ${CONFIG_FOLDER}/users_node${ck_index}.xmlck_index$((ck_index 1))
done# 构建最终的 XML 配置
REMOTE_SERVERS_CONFIGremote_servers\n
REMOTE_SERVERS_CONFIG ${CK_CLUSTER_NAME}\n
for shard in ${!shard_nodes[]}; doREMOTE_SERVERS_CONFIG shard\nREMOTE_SERVERS_CONFIG internal_replicationtrue/internal_replication \nREMOTE_SERVERS_CONFIG${shard_nodes[$shard]}REMOTE_SERVERS_CONFIG /shard\n
done
REMOTE_SERVERS_CONFIG /${CK_CLUSTER_NAME}\n
REMOTE_SERVERS_CONFIG/remote_servers# 动态修改配置文件插入 Zookeeper\CK集群 配置
for node_config in ${!config_content[]}; doecho 处理 $node_config ...# 创建临时文件temp_file${node_config}_tmp.xmlecho -e ${config_content[$node_config]} $temp_filesed -i /\/yandex/d $temp_file# linux下为# sed -i /\/yandex/d $temp_file # 拼接 Zookeeper 和 Remote Servers 配置combined_insert${ZOOKEEPER_CONFIG}
${REMOTE_SERVERS_CONFIG}echo -e $combined_insert $temp_fileecho /yandex $temp_filemv $temp_file $CONFIG_FOLDER/${node_config}.xmlecho 生成 $node_config 完成: ${node_config}.xml
done}6、config_template.xml
?xml version1.0?
yandexloggerlevelnotice/levellog${BASE_CK_PATH}/log/clickhouse-server.log/logerrorlog${BASE_CK_PATH}/log/clickhouse-server.err.log/errorlogsize1000M/sizecount10/count/loggerpath${BASE_CK_PATH}/data//pathtmp_path${BASE_CK_PATH}/tmp//tmp_pathuser_files_path${BASE_CK_PATH}/data/user_files//user_files_pathusers_config${BASE_CK_PATH}/config/users_node${ck_index}.xml/users_config usersdefaultpassword${CK_PASSWORD}/password !-- 空密码 --networksip::/0/ip !-- 允许所有IP访问 --/networksprofiledefault/profilequotadefault/quotaaccess_management1/access_management/default/users default_profiledefault/default_profiledefault_databasedefault/default_databasehttpport${HTTP_PORT}/portmax_connections1024/max_connectionsasync_insert1/async_insert/httplisten_host0.0.0.0/listen_hostlisten_host::/listen_hosthttp_port${HTTP_PORT}/http_porttcp_port${TCP_PORT}/tcp_portinterserver_http_port${INTERSERVER_HTTP_PORT}/interserver_http_portdistributed_ddl!-- Path in ZooKeeper to queue with DDL queries --path/clickhouse/task_queue/ddl/path/distributed_ddlmacrosshard${MACROS_SHARD}/shardreplica${MACROS_REPLICA}/replica/macros
/yandex7、users_template.xml
?xml version1.0?
yandex!-- Profiles of settings. --profiles!-- Default settings. --default!-- Maximum memory usage for processing single query, in bytes. --max_memory_usage10000000000/max_memory_usageload_balancingrandom/load_balancing/default!-- Profile that allows only read queries. --readonlyreadonly1/readonly/readonly/profilesusersdefaultpassword${CK_PASSWORD}/password networksip::/0/ip !-- 允许所有IP访问 --/networksprofiledefault/profilequotadefault/quotaaccess_management1/access_management/default/users !-- Quotas. --quotas!-- Name of quota. --default!-- Limits for time interval. You could specify many intervals with different limits. --interval!-- Length of interval. --duration3600/durationdistributed_product_modeallow/distributed_product_mode!-- No limits. Just calculate resource usage for time interval. --queries0/querieserrors0/errorsresult_rows0/result_rowsread_rows0/read_rowsexecution_time0/execution_time/interval/default/quotas
/yandex