@zhangyy
2021-01-06T22:13:26.000000Z
字数 8231
阅读 220
ClickHouse系列
系统:CentOS7.9x64
主机名:
cat /etc/hosts
----
192.168.100.11 node01.flyfish.cn
192.168.100.12 node02.flyfish.cn
192.168.100.13 node03.flyfish.cn
192.168.100.14 node04.flyfish.cn
192.168.100.15 node05.flyfish.cn
192.168.100.16 node06.flyfish.cn
192.168.100.17 node07.flyfish.cn
192.168.100.18 node08.flyfish.cn
----
系统语言:
echo "export LANG=en_US.UTF8" >> ~/.bash_profile
cat ~/.bash_profile
非强制执行步骤:
---
umount /mnt
mount /dev/cdrom /mnt
cd /etc/yum.repos.d
mkdir bk
mv *.repo bk/
echo "[EL7-1]" > /etc/yum.repos.d/itpux.repo
echo "name =Linux-7" >> /etc/yum.repos.d/itpux.repo
echo "baseurl=file://mnt" >> /etc/yum.repos.d/itpux.repo
echo "gpgcheck=0" >> /etc/yum.repos.d/itpux.repo
echo "enabled=1" >> /etc/yum.repos.d/itpux.repo
---
yum install lvm2 -y
pvcreate /dev/sdb
vgcreate datavg /dev/sdb
lvcreate -n datalv -L 200000M datavg
mkfs.ext4 /dev/datavg/datalv
vi /etc/fstab
/dev/sda1 / xfs defaults 0 0
/dev/sda2 swap swap defaults 0 0
/dev/datavg/datalv /clickhouse ext4 defaults,nobarrier,noatime 0 0
nobarrier: 强制底层设备不需要刷新缓存
noatime: 不记录资源硬盘的访问时间
mkdir /clickhouse
mount /dev/datavg/datalv /clickhouse
创建clickhouse 的 存放 soft 目录
mkdir /clickhouse/soft -p
创建安装用户:
groupadd -g 60001 clickhouse
useradd -u 61001 -g clickhouse clickhouse
chown -R clickhouse:clickhouse /clickhouse
chmod -R 775 /clickhouse
echo "clickhouse" | passwd --stdin clickhouse
默认启动字符界面:
systemctl set-default multi-user.target
设置clickhouse 的系统句柄数
cat >> /etc/security/limits.conf << EOF
root soft nofile 1048576
root hard nofile 1048576
clickhouse soft nproc 1048576
clickhouse hard nproc 1048576
clickhouse soft nofile 1048576
clickhouse hard nofile 1048576
clickhouse soft stack 10240
clickhouse hard stack 32768
clickhouse hard memlock unlimited
clickhouse soft memlock unlimited
EOF
设置系统极限数
cat >> /etc/sysctl.conf << EOF
fs.aio-max-nr = 1048576
fs.file-max = 6815744
net.ipv4.ip_local_port_range = 10000 65535
net.ipv4.tcp_mem = 786432 2097152 3145728
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
vm.swappiness=1
vm.min_free_kbytes=204800
vm.overcommit_memory=0
EOF
sysctl -p
修改 系统时间:
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
关闭selinux 与 firewalld ,iptables 防火墙
echo "SELINUX=disabled" > /etc/selinux/config
echo "#SELINUXTYPE=targeted " >> /etc/selinux/config
cat /etc/selinux/config
setenforce 0
systemctl stop firewalld.service
systemctl disable firewalld.service
关闭透明大页:
cat /sys/kernel/mm/transparent_hugepage/defrag
[always] madvise never
cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
vi /etc/rc.d/rc.local
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
chmod +x /etc/rc.d/rc.local
参考官网:
https://clickhouse.tech/#quick-start
源码包安装:
下载包: https://repo.clickhouse.tech/tgz/stable/
----
export LATEST_VERSION=$(curl -s https://repo.clickhouse.tech/tgz/stable/ | \
grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort -V -r | head -n 1)
curl -O https://repo.clickhouse.tech/tgz/stable/clickhouse-common-static-$LATEST_VERSION.tgz
curl -O https://repo.clickhouse.tech/tgz/stable/clickhouse-common-static-dbg-$LATEST_VERSION.tgz
curl -O https://repo.clickhouse.tech/tgz/stable/clickhouse-server-$LATEST_VERSION.tgz
curl -O https://repo.clickhouse.tech/tgz/stable/clickhouse-client-$LATEST_VERSION.tgz
tar -xzvf clickhouse-common-static-$LATEST_VERSION.tgz
sudo clickhouse-common-static-$LATEST_VERSION/install/doinst.sh
tar -xzvf clickhouse-common-static-dbg-$LATEST_VERSION.tgz
sudo clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh
tar -xzvf clickhouse-server-$LATEST_VERSION.tgz
sudo clickhouse-server-$LATEST_VERSION/install/doinst.sh
sudo /etc/init.d/clickhouse-server start
tar -xzvf clickhouse-client-$LATEST_VERSION.tgz
sudo clickhouse-client-$LATEST_VERSION/install/doinst.sh
----
新建安装目录:
mkdir /clickhouse/app
mkdir /clickhouse/data
mkdir /clickhouse/log
mkdir /clickhouse/etc
mkdir /clickhouse/soft
cd /clickhouse/app
tar zxvf /clickhouse/soft/clickhouse-common-static-20.12.2.1.tgz
mv clickhouse-common-static-20.12.2.1/ clickhouse-common-static
tar -zxvf /clickhouse/soft/clickhouse-common-static-dbg-20.12.2.1.tgz
tar -zxvf /clickhouse/soft/clickhouse-server-20.12.2.1.tgz
mv clickhouse-common-static-dbg-20.12.2.1/ clickhouse-common-static-dbg
mv clickhouse-server-20.12.2.1/ clickhouse-server
修改clickhouse-server 配置文件:
vim clickhouse-server/install/doinst.sh
-----
CLICKHOUSE_DATADIR=${CLICKHOUSE_DATADIR:=/clickhouse/data}
CLICKHOUSE_LOGDIR=${CLICKHOUSE_LOGDIR:=/clickhouse/log}
-----
vim /clickhouse/app/clickhouse-server/etc/clickhouse-server/config.xml
----
<log>/clickhouse/log/clickhouse-server.log</log>
<errorlog>/clickhouse/log/clickhouse-server.err.log</errorlog>
----
<!-- Path to data directory, with trailing slash. -->
<path>/clickhouse/data</path>
-----
<!-- Path to temporary data for processing hard queries. -->
<tmp_path>/clickhouse/data/tmp/</tmp_path>
----
<!-- Directory with user provided files that are accessible by 'file' table function.
-->
<user_files_path>/clickhouse/data/user_files/</user_files_path>
<format_schema_path>/clickhouse/data/format_schemas/</format_schema_path>
------
<local_directory>
<!-- Path to folder where users created by SQL commands are stored. -->
<path>/clickhouse/data/access/</path>
</local_directory>
------
修改 IP 地址监听:打开
<listen_host>::</listen_host>
----
<! 设置时区为东八区-->
<timezone>Asia/Shanghai</timezone>
-----
vim /clickhouse/app/clickhouse-server/etc/clickhouse-server/users.xml
----
<max_memory_usage>80000000000</max_memory_usage>
<access_management>1</access_management> 打开
----
cd /clickhouse/app
----
tar -zxvf /clickhouse/soft/clickhouse-client-20.12.2.1.tgz
mv clickhouse-client-20.12.2.1/ clickhouse-client
----
启动clickhouse:
./clickhouse-common-static/install/doinst.sh
./clickhouse-common-static-dbg/install/doinst.sh
./clickhouse-server/install/doinst.sh
./clickhouse-client/install/doinst.sh
cd /etc/
ls -ld /etc/clickhouse-*
生成clickhouse的 server 与 client 端
mv /etc/clickhouse-* /clickhouse/etc/
ln -sf /clickhouse/etc/* .
检查参数:
/clickhouse/etc/clickhouse-server/config.xml
/clickhouse/etc/clickhouse-server/users.xml
-----
chown -R clickhouse:clickhouse /clickhouse
chmod -R 755 /clickhouse
clickhouse 启动脚本:
vim /etc/systemd/system/clickhouse-server.service
---
[Unit]
Description=ClickHouse Server (analytic DBMS for big data)
Requires=network-online.target
After=network-online.target
[Service]
Type=simple
User=clickhouse
Group=clickhouse
Restart=always
RestartSec=30
RuntimeDirectory=clickhouse-server
ExecStart=/usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/clickhouse-server.pid
LimitCORE=infinity
LimitNOFILE=500000
CapabilityBoundingSet=CAP_NET_ADMIN CAP_IPC_LOCK CAP_SYS_NICE
[Install]
WantedBy=multi-user.target
---
systemctl daemon-reload
systemctl status clickhouse-server
systemctl start clickhouse-server
systemctl stop clickhouse-server
netstat -nultp |grep 9000
登录 clickhouse
clickhouse-client
脚本启动:
su - clickhouse
nohup clickhouse-server --config=/etc/clickhouse-server/config.xml &
cd /clickhouse/app
vim clickhouse.sh
----
#!/bin/bash
nohup clickhouse-server --config=/etc/clickhouse-server/config.xml &
-----
chmod 775 clickhouse.start
/clickhouse/app/clickhouse.start
clickhouse-client -h 192.168.100.11 --port 9000 --user default --password
----
192.168.100.11:9200 的端口实例
----
配置 config.xml 文件
cp -p /clickhouse/etc/clickhouse-server/config.xml /clickhouse/etc/clickhouse-server/config9200.xml
vim /clickhouse/etc/clickhouse-server/config9200.xml
---
<log>/clickhouse/log9200/clickhouse-server.log</log>
<errorlog>/clickhouse/log9200/clickhouse-server.err.log</errorlog>
<http_port>8224</http_port>
<tcp_port>9200</tcp_port>
<mysql_port>9204</mysql_port>
<interserver_http_port>9209</interserver_http_port>
<path>/clickhouse/data9200</path>
<tmp_path>/clickhouse/data9200/tmp/</tmp_path>
<user_files_path>/clickhouse/data9200/user_files/</user_files_path>
<access_control_path>/clickhouse/data9200/access/</access_control_path>
<format_schema_path>/clickhouse/data9200/format_schemas/</format_schema_path>
mkdir -p /clickhouse/data9200
mkdir -p /clickhouse/log9200
chown -R clickhouse:clickhouse /clickhouse/data9200
chown -R clickhouse:clickhouse /clickhouse/log9200
启动clickhouse9200 实例:
#!/bin/bash
nohup clickhouse-server --config=/etc/clickhouse-server/config.xml &
sleep 10
nohup clickhouse-server --config=/etc/clickhouse-server/config9200.xml &
su - clickhouse
clickhouse-server --config=/etc/clickhouse-server/config9200.xml
clickhouse-client -h 192.168.100.11 --port 9200