[关闭]
@zhangyy 2021-01-06T22:13:26.000000Z 字数 8231 阅读 220

Clickhouse 单机安装配置

ClickHouse系列



一:Clickhouse 单机安装

1.1 系统环境初始化:

  1. 系统:CentOS7.9x64
  2. 主机名:
  3. cat /etc/hosts
  4. ----
  5. 192.168.100.11 node01.flyfish.cn
  6. 192.168.100.12 node02.flyfish.cn
  7. 192.168.100.13 node03.flyfish.cn
  8. 192.168.100.14 node04.flyfish.cn
  9. 192.168.100.15 node05.flyfish.cn
  10. 192.168.100.16 node06.flyfish.cn
  11. 192.168.100.17 node07.flyfish.cn
  12. 192.168.100.18 node08.flyfish.cn
  13. ----

  1. 系统语言:
  2. echo "export LANG=en_US.UTF8" >> ~/.bash_profile
  3. cat ~/.bash_profile

image_1er8dqe7v12u71dt4bapipi1vm9.png-120.5kB


  1. 非强制执行步骤:
  2. ---
  3. umount /mnt
  4. mount /dev/cdrom /mnt
  5. cd /etc/yum.repos.d
  6. mkdir bk
  7. mv *.repo bk/
  8. echo "[EL7-1]" > /etc/yum.repos.d/itpux.repo
  9. echo "name =Linux-7" >> /etc/yum.repos.d/itpux.repo
  10. echo "baseurl=file://mnt" >> /etc/yum.repos.d/itpux.repo
  11. echo "gpgcheck=0" >> /etc/yum.repos.d/itpux.repo
  12. echo "enabled=1" >> /etc/yum.repos.d/itpux.repo
  13. ---
  14. yum install lvm2 -y
  15. pvcreate /dev/sdb
  16. vgcreate datavg /dev/sdb
  17. lvcreate -n datalv -L 200000M datavg
  18. mkfs.ext4 /dev/datavg/datalv
  19. vi /etc/fstab
  20. /dev/sda1 / xfs defaults 0 0
  21. /dev/sda2 swap swap defaults 0 0
  22. /dev/datavg/datalv /clickhouse ext4 defaults,nobarrier,noatime 0 0
  23. nobarrier 强制底层设备不需要刷新缓存
  24. noatime 不记录资源硬盘的访问时间
  25. mkdir /clickhouse
  26. mount /dev/datavg/datalv /clickhouse

  1. 创建clickhouse 存放 soft 目录
  2. mkdir /clickhouse/soft -p

  1. 创建安装用户:
  2. groupadd -g 60001 clickhouse
  3. useradd -u 61001 -g clickhouse clickhouse
  4. chown -R clickhouse:clickhouse /clickhouse
  5. chmod -R 775 /clickhouse
  6. echo "clickhouse" | passwd --stdin clickhouse
  7. 默认启动字符界面:
  8. systemctl set-default multi-user.target

image_1er8dr8k21hpp188r1kj8irgh03m.png-97.5kB

  1. 设置clickhouse 的系统句柄数
  2. cat >> /etc/security/limits.conf << EOF
  3. root soft nofile 1048576
  4. root hard nofile 1048576
  5. clickhouse soft nproc 1048576
  6. clickhouse hard nproc 1048576
  7. clickhouse soft nofile 1048576
  8. clickhouse hard nofile 1048576
  9. clickhouse soft stack 10240
  10. clickhouse hard stack 32768
  11. clickhouse hard memlock unlimited
  12. clickhouse soft memlock unlimited
  13. EOF

image_1er8drr4lvkeg4d1cuk15a71j913.png-100.8kB


  1. 设置系统极限数
  2. cat >> /etc/sysctl.conf << EOF
  3. fs.aio-max-nr = 1048576
  4. fs.file-max = 6815744
  5. net.ipv4.ip_local_port_range = 10000 65535
  6. net.ipv4.tcp_mem = 786432 2097152 3145728
  7. net.ipv4.tcp_rmem = 4096 4096 16777216
  8. net.ipv4.tcp_wmem = 4096 4096 16777216
  9. vm.swappiness=1
  10. vm.min_free_kbytes=204800
  11. vm.overcommit_memory=0
  12. EOF
  13. sysctl -p

  1. 修改 系统时间:
  2. ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  3. 关闭selinux firewalld ,iptables 防火墙
  4. echo "SELINUX=disabled" > /etc/selinux/config
  5. echo "#SELINUXTYPE=targeted " >> /etc/selinux/config
  6. cat /etc/selinux/config
  7. setenforce 0
  8. systemctl stop firewalld.service
  9. systemctl disable firewalld.service

image_1er8dvrjg14cb1soh11e61ofi1b9m1g.png-178.1kB

image_1er8e0fp4118e6qu16numop9b21t.png-176.1kB


  1. 关闭透明大页:
  2. cat /sys/kernel/mm/transparent_hugepage/defrag
  3. [always] madvise never
  4. cat /sys/kernel/mm/transparent_hugepage/enabled
  5. [always] madvise never
  6. vi /etc/rc.d/rc.local
  7. if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
  8. echo never > /sys/kernel/mm/transparent_hugepage/enabled
  9. fi
  10. if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
  11. echo never > /sys/kernel/mm/transparent_hugepage/defrag
  12. fi
  13. chmod +x /etc/rc.d/rc.local

1.2 clickhouse 单机版的安装

  1. 参考官网:
  2. https://clickhouse.tech/#quick-start
  3. 源码包安装:
  4. 下载包: https://repo.clickhouse.tech/tgz/stable/
  5. ----
  6. export LATEST_VERSION=$(curl -s https://repo.clickhouse.tech/tgz/stable/ | \
  7. grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort -V -r | head -n 1)
  8. curl -O https://repo.clickhouse.tech/tgz/stable/clickhouse-common-static-$LATEST_VERSION.tgz
  9. curl -O https://repo.clickhouse.tech/tgz/stable/clickhouse-common-static-dbg-$LATEST_VERSION.tgz
  10. curl -O https://repo.clickhouse.tech/tgz/stable/clickhouse-server-$LATEST_VERSION.tgz
  11. curl -O https://repo.clickhouse.tech/tgz/stable/clickhouse-client-$LATEST_VERSION.tgz
  12. tar -xzvf clickhouse-common-static-$LATEST_VERSION.tgz
  13. sudo clickhouse-common-static-$LATEST_VERSION/install/doinst.sh
  14. tar -xzvf clickhouse-common-static-dbg-$LATEST_VERSION.tgz
  15. sudo clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh
  16. tar -xzvf clickhouse-server-$LATEST_VERSION.tgz
  17. sudo clickhouse-server-$LATEST_VERSION/install/doinst.sh
  18. sudo /etc/init.d/clickhouse-server start
  19. tar -xzvf clickhouse-client-$LATEST_VERSION.tgz
  20. sudo clickhouse-client-$LATEST_VERSION/install/doinst.sh
  21. ----

  1. 新建安装目录:
  2. mkdir /clickhouse/app
  3. mkdir /clickhouse/data
  4. mkdir /clickhouse/log
  5. mkdir /clickhouse/etc
  6. mkdir /clickhouse/soft

image_1er8e8une1n9o1mqc11fi1tig8d72a.png-87.7kB

  1. cd /clickhouse/app
  2. tar zxvf /clickhouse/soft/clickhouse-common-static-20.12.2.1.tgz
  3. mv clickhouse-common-static-20.12.2.1/ clickhouse-common-static
  4. tar -zxvf /clickhouse/soft/clickhouse-common-static-dbg-20.12.2.1.tgz
  5. tar -zxvf /clickhouse/soft/clickhouse-server-20.12.2.1.tgz
  6. mv clickhouse-common-static-dbg-20.12.2.1/ clickhouse-common-static-dbg
  7. mv clickhouse-server-20.12.2.1/ clickhouse-server

image_1er8eeotuu3a1ffktvo146i1hps2n.png-320.5kB

image_1er8io55cfhi1r0j1udj1h291m3t34.png-74.5kB


  1. 修改clickhouse-server 配置文件:
  2. vim clickhouse-server/install/doinst.sh
  3. -----
  4. CLICKHOUSE_DATADIR=${CLICKHOUSE_DATADIR:=/clickhouse/data}
  5. CLICKHOUSE_LOGDIR=${CLICKHOUSE_LOGDIR:=/clickhouse/log}
  6. -----

image_1er8iveptluuujgl2c8in18ki3h.png-256.9kB


  1. vim /clickhouse/app/clickhouse-server/etc/clickhouse-server/config.xml
  2. ----
  3. <log>/clickhouse/log/clickhouse-server.log</log>
  4. <errorlog>/clickhouse/log/clickhouse-server.err.log</errorlog>
  5. ----
  6. <!-- Path to data directory, with trailing slash. -->
  7. <path>/clickhouse/data</path>
  8. -----
  9. <!-- Path to temporary data for processing hard queries. -->
  10. <tmp_path>/clickhouse/data/tmp/</tmp_path>
  11. ----
  12. <!-- Directory with user provided files that are accessible by 'file' table function.
  13. -->
  14. <user_files_path>/clickhouse/data/user_files/</user_files_path>
  15. <format_schema_path>/clickhouse/data/format_schemas/</format_schema_path>
  16. ------
  17. <local_directory>
  18. <!-- Path to folder where users created by SQL commands are stored. -->
  19. <path>/clickhouse/data/access/</path>
  20. </local_directory>
  21. ------
  22. 修改 IP 地址监听:打开
  23. <listen_host>::</listen_host>
  24. ----
  25. <! 设置时区为东八区-->
  26. <timezone>Asia/Shanghai</timezone>
  27. -----
  28. vim /clickhouse/app/clickhouse-server/etc/clickhouse-server/users.xml
  29. ----
  30. <max_memory_usage>80000000000</max_memory_usage>
  31. <access_management>1</access_management> 打开
  32. ----

  1. cd /clickhouse/app
  2. ----
  3. tar -zxvf /clickhouse/soft/clickhouse-client-20.12.2.1.tgz
  4. mv clickhouse-client-20.12.2.1/ clickhouse-client
  5. ----

image_1er8jlri51f1p1fvu9ncthq1ct03u.png-65.8kB


  1. 启动clickhouse:
  2. ./clickhouse-common-static/install/doinst.sh
  3. ./clickhouse-common-static-dbg/install/doinst.sh
  4. ./clickhouse-server/install/doinst.sh
  5. ./clickhouse-client/install/doinst.sh

image_1er8k849n14m2194t1kel1mps6vg4b.png-65.3kB

image_1er8k8rsot3hhkg1kf81us6du04o.png-265.6kB

image_1er8ka1gj1jukj0dt6214ll1rii55.png-207.3kB

  1. cd /etc/
  2. ls -ld /etc/clickhouse-*
  3. 生成clickhouse server client

image_1er8ovtks1shjuu01rp1bl71tsb19.png-60kB


  1. mv /etc/clickhouse-* /clickhouse/etc/
  2. ln -sf /clickhouse/etc/* .

image_1er8qbetm1i231n1kkuu1ufo15gf1m.png-85.8kB

  1. 检查参数:
  2. /clickhouse/etc/clickhouse-server/config.xml
  3. /clickhouse/etc/clickhouse-server/users.xml
  4. -----
  5. chown -R clickhouse:clickhouse /clickhouse
  6. chmod -R 755 /clickhouse

  1. clickhouse 启动脚本:
  2. vim /etc/systemd/system/clickhouse-server.service
  3. ---
  4. [Unit]
  5. Description=ClickHouse Server (analytic DBMS for big data)
  6. Requires=network-online.target
  7. After=network-online.target
  8. [Service]
  9. Type=simple
  10. User=clickhouse
  11. Group=clickhouse
  12. Restart=always
  13. RestartSec=30
  14. RuntimeDirectory=clickhouse-server
  15. ExecStart=/usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/clickhouse-server.pid
  16. LimitCORE=infinity
  17. LimitNOFILE=500000
  18. CapabilityBoundingSet=CAP_NET_ADMIN CAP_IPC_LOCK CAP_SYS_NICE
  19. [Install]
  20. WantedBy=multi-user.target
  21. ---
  22. systemctl daemon-reload
  23. systemctl status clickhouse-server
  24. systemctl start clickhouse-server
  25. systemctl stop clickhouse-server
  26. netstat -nultp |grep 9000

image_1er8qidfn1e0t834tcu39r1sdl23.png-321.2kB

image_1er8qjtm5c0e11sr1uhvb6e1mas2g.png-63.8kB


  1. 登录 clickhouse
  2. clickhouse-client

image_1er8qlkdq1tge1non1c008ue1pnf2t.png-120.4kB


  1. 脚本启动:
  2. su - clickhouse
  3. nohup clickhouse-server --config=/etc/clickhouse-server/config.xml &

  1. cd /clickhouse/app
  2. vim clickhouse.sh
  3. ----
  4. #!/bin/bash
  5. nohup clickhouse-server --config=/etc/clickhouse-server/config.xml &
  6. -----
  7. chmod 775 clickhouse.start
  8. /clickhouse/app/clickhouse.start
  9. clickhouse-client -h 192.168.100.11 --port 9000 --user default --password
  10. ----

image_1er8semp9jpdsuc17rggfr9tn3a.png-215.7kB

image_1er8sf77tups1iv8tg4j1v7ca3n.png-108.3kB

image_1er8sfoem1r4211kfsngrkj1l6844.png-145.7kB

image_1er9gv8bk65410f7g9ucr18p89.png-155.7kB

二:clickhouse的单机多实例配置

2.1 多实例配置

  1. 192.168.100.119200 的端口实例
  2. ----
  3. 配置 config.xml 文件
  4. cp -p /clickhouse/etc/clickhouse-server/config.xml /clickhouse/etc/clickhouse-server/config9200.xml
  5. vim /clickhouse/etc/clickhouse-server/config9200.xml
  6. ---
  7. <log>/clickhouse/log9200/clickhouse-server.log</log>
  8. <errorlog>/clickhouse/log9200/clickhouse-server.err.log</errorlog>
  9. <http_port>8224</http_port>
  10. <tcp_port>9200</tcp_port>
  11. <mysql_port>9204</mysql_port>
  12. <interserver_http_port>9209</interserver_http_port>
  13. <path>/clickhouse/data9200</path>
  14. <tmp_path>/clickhouse/data9200/tmp/</tmp_path>
  15. <user_files_path>/clickhouse/data9200/user_files/</user_files_path>
  16. <access_control_path>/clickhouse/data9200/access/</access_control_path>
  17. <format_schema_path>/clickhouse/data9200/format_schemas/</format_schema_path>

  1. mkdir -p /clickhouse/data9200
  2. mkdir -p /clickhouse/log9200
  3. chown -R clickhouse:clickhouse /clickhouse/data9200
  4. chown -R clickhouse:clickhouse /clickhouse/log9200

image_1erc00ri11d31iia17upo0r8029.png-112.4kB


  1. 启动clickhouse9200 实例:
  2. #!/bin/bash
  3. nohup clickhouse-server --config=/etc/clickhouse-server/config.xml &
  4. sleep 10
  5. nohup clickhouse-server --config=/etc/clickhouse-server/config9200.xml &
  6. su - clickhouse
  7. clickhouse-server --config=/etc/clickhouse-server/config9200.xml
  8. clickhouse-client -h 192.168.100.11 --port 9200

image_1erc0fnh7tn313gpiv0hu63vkm.png-145.9kB

image_1erc0iap0cs08n4p1218l213sm13.png-153.8kB

image_1erc0kvnt1c44aop12qdeqv18p51g.png-105.4kB

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注