ClickHouse【环境搭建 02】设置用户密码的两种方式(明文+SHA256)及新用户添加及只读模式 Cannot execute query in readonly mode 问题解决

简介: ClickHouse【环境搭建 02】设置用户密码的两种方式(明文+SHA256)及新用户添加及只读模式 Cannot execute query in readonly mode 问题解决

1.查看user.xml文件可知设置密码的多种方式

<!-- Password could be specified in plaintext or in SHA256 (in hex format).
If you want to specify password in plaintext (not recommended), place it in 'password' element.
Example: <password>qwerty</password>.
Password could be empty.
If you want to specify SHA256, place it in 'password_sha256_hex' element.
Example: <password_sha256_hex>65e84be33532fb784c48129675f9eff3a682b27168c0ea744b2cf58ee02337c5</password_sha256_hex>
Restrictions of SHA256: impossibility to connect to ClickHouse using MySQL JS client (as of July 2019).
If you want to specify double SHA1, place it in 'password_double_sha1_hex' element.
Example: <password_double_sha1_hex>e395796d6546b1b65db9d665cd43f0e858dd4303</password_double_sha1_hex>
If you want to specify a previously defined LDAP server (see 'ldap_servers' in the main config) for authentication,
place its name in 'server' element inside 'ldap' element.
Example: <ldap><server>my_ldap_server</server></ldap>
If you want to authenticate the user via Kerberos (assuming Kerberos is enabled, see 'kerberos' in the main config),
place 'kerberos' element instead of 'password' (and similar) elements.
The name part of the canonical principal name of the initiator must match the user name for authentication to succeed.
You can also place 'realm' element inside 'kerberos' element to further restrict authentication to only those requests
whose initiator's realm matches it. 
Example: <kerberos />
Example: <kerberos><realm>EXAMPLE.COM</realm></kerberos>
How to generate decent password:
Execute: PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
In first line will be password and in second - corresponding SHA256.
How to generate double SHA1:
Execute: PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha1sum | tr -d '-' | xxd -r -p | sha1sum | tr -d '-'
In first line will be password and in second - corresponding double SHA1.
-->

2.测试一下明文和SHA256方式

2.1 明文

# 修改配置文件
vim /etc/clickhouse-server/users.xml
# 密码改为 <password>666666</password>
# 重启服务
systemctl restart clickhouse-server.service
# 使用密码登录
[root@tcloud ~]# clickhouse-client --password 666666
ClickHouse client version 21.6.6.51 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 21.6.6 revision 54448.

2.2 SHA256

# 这是配置文件里的说明
How to generate decent password:
Execute: PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
In first line will be password and in second - corresponding SHA256.
# 根据说明生成SHA256密码
[root@tcloud ~]# PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
zQEkhhcL
cfaaae90d863c47187d9a9a58e9e1ef919fcd0d765c67e961bd3e56e96bfea8a
# 上边是随机生成的 这个是土豪方式
[root@tcloud ~]# PASSWORD=88888888; echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
88888888
615ed7fb1504b0c724a296d7a69e6c7b2f9ea2c57c1d8206c5afdf392ebdfd25
# 修改配置文件
vim /etc/clickhouse-server/users.xml
# 密码改为 <password_sha256_hex>615ed7fb1504b0c724a296d7a69e6c7b2f9ea2c57c1d8206c5afdf392ebdfd25</password_sha256_hex>
# 再次重启服务
systemctl restart clickhouse-server.service
# 使用密码登录
[root@tcloud ~]# clickhouse-client --password 88888888
ClickHouse client version 21.6.6.51 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 21.6.6 revision 54448.

3.新用户添加

想象中加一个用户标签和密码就OK了,配置走起!

# 修改配置文件
vim /etc/clickhouse-server/users.xml
# 添加一下标签 <admin>就是用户名 内部的标签就是当前用户的设置项
<admin>
  <password>123456</password>
  <networks>
    <ip>::/0</ip>
  </networks>
  <profile>default</profile>
  <quota>default</quota>
</admin>
# 再再次重启服务
systemctl restart clickhouse-server.service
# 使用用户名和密码登录 如果只使用密码则是default用户
[root@tcloud ~]# clickhouse-client --user admin --password 123456
ClickHouse client version 21.6.6.51 (official build).
Connecting to localhost:9000 as user admin.
Connected to ClickHouse server version 21.6.6 revision 54448.

3.1 readonly mode设置

如果要设置一个只读用户,可以修改user.xml里用户的标签属性。我们先看一下官方配置文件的说明:

<profiles>
        <!-- Default settings. -->
        <default>
            <!-- Maximum memory usage for processing single query, in bytes. -->
            <max_memory_usage>10000000000</max_memory_usage>
            <!-- How to choose between replicas during distributed query processing.
                 random - choose random replica from set of replicas with minimum number of errors
                 nearest_hostname - from set of replicas with minimum number of errors, choose replica
                  with minimum number of different symbols between replica's hostname and local hostname
                  (Hamming distance).
                 in_order - first live replica is chosen in specified order.
                 first_or_random - if first replica one has higher number of errors, pick a random one from replicas with minimum number of errors.
            -->
            <load_balancing>random</load_balancing>
        </default>
        <!-- Profile that allows only read queries. -->
        <readonly>
            <readonly>1</readonly>
        </readonly>
    </profiles>

测试:

# 修改配置文件
vim /etc/clickhouse-server/users.xml
# 添加一下标签 <admin>就是用户名 内部的标签就是当前用户的设置项
<admin>
  <password>123456</password>
  <networks>
    <ip>::/0</ip>
  </networks>
  <profile>readonly</profile>
  <quota>default</quota>
</admin>
# 再再再次重启服务
systemctl restart clickhouse-server.service
# 使用用户名和密码登录【此时用户是只读模式】
[root@tcloud clickhouse-server]# clickhouse-client --user admin --password 123456
ClickHouse client version 21.7.2.7 (official build).
Connecting to localhost:9000 as user admin.
Connected to ClickHouse server version 21.7.2 revision 54449.
# 测试 先进行查询操作
tcloud :) select * from tb_stat;
SELECT *
FROM tb_stat
Query id: 323ffecb-6e19-4c1a-998c-d415410c0de8
┌─id─┬─region──┬─group─┬─yesterday─┬─today─┬───────────stat_date─┐
│ 4  │ 1232364 │ 222   │        89 │   222 │ 2020-03-25 12:13:00 │
│ 7  │ 1232364 │ 333   │        76 │   128 │ 2020-03-25 12:11:00 │
└────┴─────────┴───────┴───────────┴───────┴─────────────────────┘
┌─id─┬─region──┬─group─┬─yesterday─┬─today─┬───────────stat_date─┐
│ 1  │ 1232364 │ 111   │        32 │     2 │ 2021-07-09 12:56:00 │
└────┴─────────┴───────┴───────────┴───────┴─────────────────────┘
┌─id─┬─region──┬─group─┬─yesterday─┬─today─┬───────────stat_date─┐
│ 2  │ 1232364 │ 111   │        34 │    44 │ 2021-07-09 12:21:00 │
└────┴─────────┴───────┴───────────┴───────┴─────────────────────┘
4 rows in set. Elapsed: 0.009 sec.
# 数据入库操作【报错Cannot execute query in readonly mode 可见当前用户是只读模式】
tcloud :) INSERT INTO tb_stat VALUES( '1','1232364', '111', 32, 2, '2021-07-09 12:56:00' );
INSERT INTO tb_stat VALUES
Query id: b9dc2175-554c-4b26-9127-bb0b88064d42
0 rows in set. Elapsed: 0.027 sec.
Received exception from server (version 21.7.2):
Code: 164. DB::Exception: Received from localhost:9000. DB::Exception: admin: Cannot execute query in readonly mode.
目录
相关文章
|
7月前
|
SQL 数据可视化 Linux
ClickHouse【环境搭建 03】Linux环境离线安装 clickhouse-22.3.3.44 配置参数说明+可视化界面使用(离线安装文件分享百度云盘)
ClickHouse【环境搭建 03】Linux环境离线安装 clickhouse-22.3.3.44 配置参数说明+可视化界面使用(离线安装文件分享百度云盘)
513 0
|
7月前
|
Unix Linux 程序员
ClickHouse【环境搭建 01】Linux环境单机版在线安装 Code:210.DB::NetException + Init script is already running 问题处理
ClickHouse【环境搭建 01】Linux环境单机版在线安装 Code:210.DB::NetException + Init script is already running 问题处理
242 0
|
存储 安全 中间件
ClickHouse环境搭建
ClickHouse环境搭建
114 0
|
SQL 存储 数据库
12.【clickhouse】ClickHouse从入门到放弃-环境搭建
【clickhouse】ClickHouse从入门到放弃-环境搭建
12.【clickhouse】ClickHouse从入门到放弃-环境搭建
|
2月前
|
存储 关系型数据库 MySQL
一个项目用5款数据库?MySQL、PostgreSQL、ClickHouse、MongoDB区别,适用场景
一个项目用5款数据库?MySQL、PostgreSQL、ClickHouse、MongoDB——特点、性能、扩展性、安全性、适用场景比较
|
6天前
|
SQL Unix OLAP
ClickHouse安装教程:开启你的列式数据库之旅
ClickHouse 是一个高性能的列式数据库管理系统,适用于在线分析处理(OLAP)。本文介绍了 ClickHouse 的基本使用步骤,包括下载二进制文件、安装应用、启动服务器和客户端、创建表、插入数据以及查询新表。还提到了图形客户端 DBeaver 的使用,使操作更加直观。通过这些步骤,用户可以快速上手并利用 ClickHouse 的强大性能进行数据分析。
36 4
|
2月前
|
存储 分布式计算 数据库
阿里云国际版设置数据库云分析工作负载的 ClickHouse 版
阿里云国际版设置数据库云分析工作负载的 ClickHouse 版
|
3月前
|
存储 SQL 缓存
数据库测试|Elasticsearch和ClickHouse的对决
由于目前市场上主流的数据库有许多,这次我们选择其中一个比较典型的Elasticsearch来和ClickHouse做一次实战测试,让大家更直观地看到真实的比对数据,从而对这两个数据库有更深入的了解,也就能理解为什么我们会选择ClickHouse。
数据库测试|Elasticsearch和ClickHouse的对决
|
2月前
|
存储 关系型数据库 MySQL
四种数据库对比MySQL、PostgreSQL、ClickHouse、MongoDB——特点、性能、扩展性、安全性、适用场景
四种数据库对比 MySQL、PostgreSQL、ClickHouse、MongoDB——特点、性能、扩展性、安全性、适用场景
|
6月前
|
DataWorks API 调度
DataWorks产品使用合集之在调度配置配置了节点的上游节点输出,没办法自动生成这个flow的依赖,该怎么操作
DataWorks作为一站式的数据开发与治理平台,提供了从数据采集、清洗、开发、调度、服务化、质量监控到安全管理的全套解决方案,帮助企业构建高效、规范、安全的大数据处理体系。以下是对DataWorks产品使用合集的概述,涵盖数据处理的各个环节。