查看服务器信息
more /etc/redhat-release
# CentOS Linux release 7.6.1810 (Core)
一:安装clickhouse
官网地址:https://clickhouse.tech/#quick-start
sudo yum install yum-utils
sudo rpm --import https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG
sudo yum-config-manager --add-repo https://repo.clickhouse.tech/rpm/clickhouse.repo
sudo yum install clickhouse-server clickhouse-client
# 启动服务
sudo /etc/init.d/clickhouse-server start
# 查看状态
service clickhouse-server status
# 或者 systemctl status clickhouse-server
# 启动服务
service clickhouse-server start
# 或者 systemctl start clickhouse-server
# 停止服务
service clickhouse-server stop
# 或者 systemctl stop clickhouse-server
# 停止服务
service clickhouse-server restart
# 或者 systemctl restartclickhouse-server
# 客户端登录
clickhouse-client
二:目录配置
修改data目录,安装好后默认目录是/var/lib/clickhouse/目录下。要把这个目录放在空间容量大的目录下,比如我这里是:/data/clickhouse/ 。
1、创建目录
mkdir -p /data/clickhouse
chown -R clickhouse:clickhouse /data/clickhouse
2、修改配置文件
修改的配置文件目录在/etc/clickhouse-server/config.xml
把数据存放目录都配置到 /data/clickhouse/ 目录下面。
vim /etc/clickhouse-server/config.xml
<!-- Path to data directory, with trailing slash. -->
<path>/data/clickhouse/</path>
<!-- Path to temporary data for processing hard queries. -->
<tmp_path>/data/clickhouse/tmp/</tmp_path>
<!-- Directory with user provided files that are accessible by 'file' table function. -->
<user_files_path>/data/clickhouse/user_files/</user_files_path>
<!-- Directory in <clickhouse-path> containing schema files for various input formats.
The directory will be created if it doesn't exist.
-->
<format_schema_path>/data/clickhouse/format_schemas/</format_schema_path>
修改完之后重启服务:
service clickhouse-server restart
# 或者
systemctl restart clickhouse-server
# 查看目录结构
ll /data/clickhouse/
三:登录数据库
登录查看数据库(默认用户是default,密码为空)
clickhouse-client 或者 clickhouse-client -h127.0.0.1 都可以。
clickhouse-client -h ip地址 --port 端口号 -u 用户名 --password 密码
允许远程登录
把注释掉的<listen_host>::</listen_host>取消注释,然后重启服务
vim /etc/clickhouse-server/config.xml
确认user.xml配置
vim /etc/clickhouse-server/users.xml
主机:Clickhouse远程登录服务器的IP
用户名、密码:默认default,密码为空
还是无法连接,那么试试关闭防火墙
关闭防火墙步骤如下:
# 停止firewall
$ systemctl stop firewalld.service
添加新用户账号
# 生成加密密码
# PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
# p4BO5YNX #明文密码
# 539f0aa98b381a8c5e34149350c7c5de8b501c6def230fda86d26844d4f943aa #加密后的密码
cd /etc/clickhouse-server/
vim users.xml
#在 <user></user>里面添加下面内容
<yifeng>
<password>123456</password>
<networks incl="networks" replace="replace">
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
<allow_databases>
<database>default</database>
</allow_databases>
<access_management>1</access_management>
</yifeng>
dba用户采用明文密码,默认权限,<allow_databases>允许访问的数据库是default。
admin用户采用密文密码,只读权限,<allow_databases>允许访问的数据库是default