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)
相关文章
|
3月前
|
IDE 开发工具 开发者
手把手教你安装PyCharm 2025:开发者的Python IDE配置全流程+避坑指南
本教程详细介绍了PyCharm 2025版本在Windows系统下的安装流程及配置方法,涵盖AI代码补全与智能调试工具链等新功能。内容包括系统要求、安装步骤、首次运行配置(如主题选择与插件安装)、创建首个Python项目,以及常见问题解决方法。此外,还提供了切换中文界面和延伸学习资源的指导,帮助用户快速上手并高效使用PyCharm进行开发。
1706 60
|
3月前
|
Linux Shell
在Linux、CentOS7中设置shell脚本开机自启动服务
以上就是在CentOS 7中设置shell脚本开机自启动服务的全部步骤。希望这个指南能帮助你更好地管理你的Linux系统。
173 25
|
1月前
|
Oracle 关系型数据库 Linux
MyEMS开源系统安装之CentOS/RHEL/Rocky/AlmaLinux/Oracle Linux
本指南介绍如何在CentOS/RHEL/Rocky/AlmaLinux/Oracle Linux服务器上部署MyEMS开源能源管理系统。内容涵盖系统准备、数据库配置、多个MyEMS服务(如myems-api、myems-admin、myems-modbus-tcp等)的安装与配置,以及Nginx服务器设置和防火墙规则调整。通过完成所有步骤,您将能够访问MyEMS Admin UI和Web UI,默认端口分别为8001和80,初始登录凭据已提供。
58 0
|
3月前
|
存储 缓存 文件存储
uv安装python及其依赖的加速方法
国内在使用uv的时候,可能会涉及到装python的速度太慢的问题,为了解决这个问题,可以使用`UV_PYTHON_INSTALL_MIRROR`这个环境变量。除此以外,对于多人协作场景,`UV_CACHE_DIR`也是一个有用的环境变量。本文会介绍这两个变量。
2015 10
|
3月前
|
安全 Linux 网络安全
在Linux(CentOS和AWS)上安装更新的git2的方法并配置github-ssh
经过以上这些步骤,你现在就能在GitHub上顺利往返,如同海洋中的航海者自由驰骋。欢迎你加入码农的世界,享受这编程的乐趣吧!
117 10
|
4月前
|
存储 IDE Linux
零基础保姆级教程!手把手教你免费玩转Linux CentOS安装+学习环境搭建(附避坑指南)
本文详细介绍了在VMware虚拟机中安装CentOS 6.8的全过程。首先,需确保已安装VMware并开启V-CPU虚拟化功能,可通过BIOS设置或使用LeoMoon CPU-V工具检测。接着,下载CentOS镜像文件,并在VMware中新建虚拟机,配置CPU、内存、硬盘等参数。最后,加载ISO镜像启动虚拟机,按照提示完成CentOS的安装,包括语言、键盘、存储方式、地区、密码设置及硬盘分区等步骤。安装完成后,以root用户登录即可进入系统桌面,开始学习Linux命令和操作。
379 12
零基础保姆级教程!手把手教你免费玩转Linux CentOS安装+学习环境搭建(附避坑指南)
|
4月前
|
安全 Linux 网络安全
CentOS 8下SSH连接超时与“无法加载主机密钥”错误的排查与修复
在CentOS 8系统中,宝塔面板提示“出错了,面板运行时发生错误”,导致插件无法正常显示。同时,SSH连接超时,修复面板功能失效。通过VNC连接排查,发现SSH服务安装和配置问题频发,最终通过重装SSH、调整权限并重新生成主机密钥文件解决问题,成功恢复SSH连接。
289 16
|
安全 Linux 网络安全
部署07--远程连接Linux系统,利用FinalShell可以远程连接到我们的操作系统上
部署07--远程连接Linux系统,利用FinalShell可以远程连接到我们的操作系统上
|
安全 数据可视化 关系型数据库
何远程连接阿里云主机服务器(Linux系统)
何远程连接阿里云主机服务器(Linux系统)
2165 57
何远程连接阿里云主机服务器(Linux系统)
|
关系型数据库 MySQL Linux
用sqlyog远程连接LINUX系统的MYSQL出现错解决方法
无法给远程连接的用户权限问题。结果这样子操作mysql库,即可解决。在本机登入mysql后,更改 “mysql” 数据库里的 “user” 表里的 “host” 项,从”localhost”改称'%'。
1827 0