Linux之centos安装clinkhouse以及python如何连接

简介: Linux之centos安装clinkhouse以及python如何连接

1.安装

clinkhouse之安装以及python操作

1.Clickhouse 仅支持Linux 且必须支持SSE4.2 指令集
grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"
显示
SSE 4.2 supported


2.首先去根目录创建文件
mkdir /myclinkhouse
cd /myclinkhouse
3.直接复制下载
wget --content-disposition https://packagecloud.io/Altinity/clickhouse/packages/el/7/clickhouse-server-common-20.3.12.112-1.el7.x86_64.rpm/download.rpm

wget --content-disposition https://packagecloud.io/Altinity/clickhouse/packages/el/7/clickhouse-server-20.3.12.112-1.el7.x86_64.rpm/download.rpm

wget --content-disposition https://packagecloud.io/Altinity/clickhouse/packages/el/7/clickhouse-common-static-20.3.12.112-1.el7.x86_64.rpm/download.rpm

wget --content-disposition https://packagecloud.io/Altinity/clickhouse/packages/el/7/clickhouse-client-20.3.12.112-1.el7.x86_64.rpm/download.rpm

4.解压安装
rpm -ivh ./*.rpm

5.卸载(当你装错了)
# 卸载及删除安装文件(需root权限)
yum list installed | grep clickhouse
yum remove -y clickhouse-common-static
yum remove -y clickhouse-server-common
rm -rf /var/lib/clickhouse
rm -rf /etc/clickhouse-*
rm -rf /var/log/clickhouse-server

6.创建用户名密码
password=$(base64 < /dev/urandom | head -c8); echo "$password"; 
echo -n "$password" | sha256sum | tr -d '-'
输出:明文  密文
RaSQ8uTe
1bf9e7c1e8692697f360a40aabfeaa8ae386b304482cdd81e597a36f426d432c


7.修改配置文件
vim /etc/clickhouse-server/config.xml
修改下面这个
<listen_host>0.0.0.0</listen_host>

vim /etc/clickhouse-server/users.xml
#找到 users --> default --> 标签下的password修改成password_sha256_hex,并把密文填进去
<password_sha256_hex>1bf9e7c1e8692697f360a40aabfeaa8ae386b304482cdd81e597a36f426d432c</password_sha256_hex>

8.启动以及重启
service clickhouse-server start
service clickhouse-server restart


9.连接
9.1直接连接
clickhouse-client
9.2用命令连接
clickhouse-client -h wusen0601.xyz -d default -m -u default --password 明文

View Code

2.python使用

# pip install clickhouse-driver
from clickhouse_driver import Client
import random

host = "wusen0601.xyz"
port = "9000"
user = "default"
password = "RaSQ8uTe1"
database = "default"
client = Client(host=host, port=port, user=user, password=password, database=database)
# client = Client(host=host, port=port, database=database)
sql = f"""
select enterprise_name,bike_type,count(*) as nums
from t_bike_location_real
GROUP BY (enterprise_name,bike_type)
"""

enterprise_name_list = [
    {"enterprise_name": "哈罗", "enterprise_id": "10001", "bike_type": random.randrange(0, 2),"bike_id":random.randrange(100000,1000000)},
    {"enterprise_name": "美团", "enterprise_id": "10002", "bike_type": random.randrange(0, 2),"bike_id":random.randrange(100000,1000000)},
    {"enterprise_name": "骑电", "enterprise_id": "10003", "bike_type": random.randrange(0, 2),"bike_id":random.randrange(100000,1000000)}
]
index_random = random.randrange(0,len(enterprise_name_list))
insert_data = enterprise_name_list[index_random]
insert_sql = f"""
insert into t_bike_location_real
(enterprise_name,enterprise_id,bike_type,bike_id)

values('{insert_data['enterprise_name']}','{insert_data['enterprise_id']}','{insert_data['bike_type']}','{insert_data['bike_id']}')
"""
print(insert_sql)
for i in range(100):
    ans = client.execute(insert_sql)

    print(ans)
相关文章
|
Linux 计算机视觉 C++
【解决方案】Building wheel for opencv-python:安装卡顿的原因与解决方案
当你安装OpenCV时,命令行停在Building wheel for opencv-python (PEP 517) ... -似乎卡住了。这并非程序假死,而是其编译耗时巨大。本文将揭示原因,并提供优化安装体验的实用方法。
1421 88
|
11月前
|
人工智能 数据安全/隐私保护 异构计算
桌面版exe安装和Python命令行安装2种方法详细讲解图片去水印AI源码私有化部署Lama-Cleaner安装使用方法-优雅草卓伊凡
桌面版exe安装和Python命令行安装2种方法详细讲解图片去水印AI源码私有化部署Lama-Cleaner安装使用方法-优雅草卓伊凡
1578 8
桌面版exe安装和Python命令行安装2种方法详细讲解图片去水印AI源码私有化部署Lama-Cleaner安装使用方法-优雅草卓伊凡
|
IDE 开发工具 开发者
手把手教你安装PyCharm 2025:开发者的Python IDE配置全流程+避坑指南
本教程详细介绍了PyCharm 2025版本在Windows系统下的安装流程及配置方法,涵盖AI代码补全与智能调试工具链等新功能。内容包括系统要求、安装步骤、首次运行配置(如主题选择与插件安装)、创建首个Python项目,以及常见问题解决方法。此外,还提供了切换中文界面和延伸学习资源的指导,帮助用户快速上手并高效使用PyCharm进行开发。
6470 61
|
人工智能 数据挖掘 Linux
Centos安装Python3.7(亲测可用)
本指南详细介绍了在基于Linux(以CentOS系统为例,使用yum包管理器)的系统上安装Python 3.7版本的完整流程。Python是一种广泛使用的高级编程语言,在各种领域如软件开发、数据分析、人工智能和区块链开发等都有着重要的应用。
943 2
|
存储 缓存 文件存储
uv安装python及其依赖的加速方法
国内在使用uv的时候,可能会涉及到装python的速度太慢的问题,为了解决这个问题,可以使用`UV_PYTHON_INSTALL_MIRROR`这个环境变量。除此以外,对于多人协作场景,`UV_CACHE_DIR`也是一个有用的环境变量。本文会介绍这两个变量。
8780 10
|
Linux 开发工具 Python
CentOS7安装python3超详细教程
CentOS7安装python3超详细教程
2853 0
|
Linux 网络安全 Python
linux centos上安装python3.11.x详细完整教程
这篇文章提供了在CentOS系统上安装Python 3.11.x版本的详细步骤,包括下载、解压、安装依赖、编译配置、解决常见错误以及版本验证。
12469 3
linux centos上安装python3.11.x详细完整教程
|
Linux 编译器 C语言
CentOS 快速安装Python3和pip3
CentOS是经常使用的Linux系统之一,特别是作为服务器使用,其只自带了Python2,但是现在使用更广泛的是Python3,因此需要自行安装,同时为了更方便地安装第三方库,还需要安装pip3。
|
Shell Linux Python
centos7系统 shell脚本安装python3 各版本
centos7系统 shell脚本安装python3 各版本
518 0