点击上方“IT那活儿”公众号--专注于企业全栈运维技术分享,不管IT什么活儿,干就完了!!!
主机设置
1.1 设置hosts文件
echo "xxx.xxx.3.181 CK1" >> /etc/hosts
1.2 必要软件准备
yum install lvm2 -y
1.3 创建数据盘
LVM
pvcreate dev/sdb
vgcreate datavg /dev/sdb
lvcreate -n datalv -L 200000M datavg
mkfs.ext4 /dev/mapper/rhel-clickhouse
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
mkdir /clickhouse
mount /clickhouse
mkdir /clickhouse/soft
1.4 权限及属组设置
groupadd -g 60001 clickhouse
useradd -u 61001 -g clickhouse clickhouse
chown -R clickhouse:clickhouse /clickhouse
chmod -R 775 /clickhouse
1.5 设置clickhouse用户密码
echo "clickhouse" | passwd --stdin clickhouse
1.6 设置系统限制参数
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
1.7 设置系统控制参数
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
1.8 时区设置
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
1.9 禁用透明大页
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
1.10 安装互信工具
cd /clickhouse/soft
tar -xvf sshpass-1.10.tar.gz
cd sshpass-1.10
./configure
make
make install
安装数据库软件
2.1 创建clickhouse目录
su - clickhouse
mkdir /clickhouse/app
mkdir /clickhouse/data
mkdir /clickhouse/log
mkdir /clickhouse/etc
mkdir /clickhouse/soft
2.2 安装包上传解压
clickhouse-client-20.11.4.13.tgz
clickhouse-common-static-20.11.4.13.tgz
clickhouse-common-static-dbg-20.11.4.13.tgz
clickhouse-server-20.11.4.13.tgz
cd /clickhouse/app
tar zxvf /clickhouse/soft/clickhouse-common-static-20.11.4.13.tgz
mv clickhouse-common-static-20.11.4.13 clickhouse-common-static
./clickhouse-common-static/install/doinst.sh
tar zxvf /clickhouse/soft/clickhouse-common-static-dbg-20.11.4.13.tgz
mv clickhouse-common-static-dbg-20.11.4.13 clickhouse-common-static-dbg
./clickhouse-common-static-dbg/install/doinst.sh
tar zxvf /clickhouse/soft/clickhouse-server-20.11.4.13.tgz
mv clickhouse-server-20.11.4.13 clickhouse-server
2.3 修改配置文件
vi clickhouse-server/install/doinst.sh
CLICKHOUSE_DATADIR=${CLICKHOUSE_DATADIR:=/clickhouse/data}
CLICKHOUSE_LOGDIR=${CLICKHOUSE_LOGDIR:=/clickhouse/log}
vi /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>
放开注释可创建其他用户
vi /clickhouse/app/clickhouse-server/etc/clickhouse-server/users.xml
<access_management>1</access_management>
根据实际情况设置内存:查询进程所能分配的最大内存
<max_memory_usage>80000000000</max_memory_usage>
2.4 执行安装
./clickhouse-common-static/install/doinst.sh
./clickhouse-common-static-dbg/install/doinst.sh
./clickhouse-server/install/doinst.sh
tar zxvf /clickhouse/soft/clickhouse-client-20.11.4.13.tgz
mv clickhouse-client-20.11.4.13 clickhouse-client
./clickhouse-client/install/doinst.sh
cd /etc/
mv /etc/clickhouse-* /clickhouse/etc/
ln -sf /clickhouse/etc/* .
ls -ls /etc/click*
0 lrwxrwxrwx 1 root root 33 Dec 2 17:02 clickhouse-client ->/clickhouse/etc/clickhouse-client
0 lrwxrwxrwx 1 root root 33 Dec 2 17:02 clickhouse-server ->/clickhouse/etc/clickhouse-server
chown -R clickhouse:clickhouse /clickhouse
chmod -R 755 /clickhouse
/clickhouse/etc/clickhouse-server/config.xml
/clickhouse/etc/clickhouse-server/users.xml
vi /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=/etc/clickhouse-server/clickhouse-server.pid
LimitCORE=infinity
LimitNOFILE=500000
CapabilityBoundingSet=CAP_NET_ADMIN CAP_IPC_LOCK CAP_SYS_NICE
-------------------------------------------------------------------------------
启动服务
3.1 启停服务语句
systemctl status clickhouse-server
systemctl start clickhouse-server
systemctl stop clickhouse-server
3.2 设置开机自启
systemctl enable clickhouse-server
systemctl disable clickhouse-server
systemctl daemon-reload
3.3 设置启动文件
vi clickhouse.start
nohup clickhouse-server --config=/etc/clickhouse-server/config.xml &
su - clickhouse
./clickhouse.start
cd /clickhouse/app

本文作者:陈 浩(上海新炬中北团队)
本文来源:“IT那活儿”公众号

文章转载自IT那活儿,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




