#1 创建部署目录和docker-compose.yaml
mkdir -p /opt/clickhouse/etc/clickhouse-server/{config.d,users.d}
cd /opt/clickhouse
2准备:docker-compose.yaml
cat <<-EOF > docker-compose.yaml
services:
clickhouse:
image: registry.cn-shenzhen.aliyuncs.com/starsl/clickhouse-server:23.4
container_name: clickhouse
hostname: clickhouse
volumes:
- /opt/clickhouse/logs:/var/log/clickhouse-server
- /opt/clickhouse/data:/var/lib/clickhouse
- /opt/clickhouse/etc/clickhouse-server/config.d/config.xml:/etc/clickhouse-server/config.d/config.xml
- /opt/clickhouse/etc/clickhouse-server/users.d/users.xml:/etc/clickhouse-server/users.d/users.xml
- /usr/share/zoneinfo/PRC:/etc/localtime
ports:
- 8123:8123
- 9000:9000
EOF
3准备配置文件/config.xml
<clickhouse replace="true">
<logger>
<level>debug</level>
<log>/var/log/clickhouse-server/clickhouse-server.log</log>
<errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
<size>1000M</size>
<count>3</count>
</logger>
<display_name>ch_accesslog</display_name>
<listen_host>0.0.0.0</listen_host>
<http_port>8123</http_port>
<tcp_port>9000</tcp_port>
<user_directories>
<users_xml>
<path>users.xml</path>
</users_xml>
<local_directory>
<path>/var/lib/clickhouse/access/</path>
</local_directory>
</user_directories>
</clickhouse>
4- 准备 users.xml
# 生成密码(返回的第一行是明文,第二行是密文)
PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
kbcIc48j
1f8d0b27fa60a6aa73e05b8a0c8e348619f85ce765f7864e9853c1613377abce
然后:
vi /opt/clickhouse/etc/clickhouse-server/users.d/users.xml
如下:
<?xml version="1.0"?>
<clickhouse replace="true">
<profiles>
<default>
<max_memory_usage>10000000000</max_memory_usage>
<use_uncompressed_cache>0</use_uncompressed_cache>
<load_balancing>in_order</load_balancing>
<log_queries>1</log_queries>
</default>
</profiles>
<users>
<default>
<password remove='1' />
<password_sha256_hex>填写生成的密码密文</password_sha256_hex>
<access_management>1</access_management>
<profile>default</profile>
<networks>
<ip>::/0</ip>
</networks>
<quota>default</quota>
<access_management>1</access_management>
<named_collection_control>1</named_collection_control>
<show_named_collections>1</show_named_collections>
<show_named_collections_secrets>1</show_named_collections_secrets>
</default>
</users>
<quotas>
<default>
<interval>
<duration>3600</duration>
<queries>0</queries>
<errors>0</errors>
<result_rows>0</result_rows>
<read_rows>0</read_rows>
<execution_time>0</execution_time>
</interval>
</default>
</quotas>
</clickhouse>
5- 启动 +客户端连接
6-创建数据库与表
库:
CREATE DATABASE IF NOT EXISTS nginxlogs ENGINE=Atomic;
表:
CREATE TABLE nginxlogs.nginx_access
(
`timestamp` DateTime64(3, 'Asia/Shanghai'),
`server_ip` String,
`domain` String,
`request_method` String,
`status` Int32,
`top_path` String,
`path` String,
`query` String,
`protocol` String,
`referer` String,
`upstreamhost` String,
`responsetime` Float32,
`upstreamtime` Float32,
`duration` Float32,
`request_length` Int32,
`response_length` Int32,
`client_ip` String,
`client_latitude` Float32,
`client_longitude` Float32,
`remote_user` String,
`remote_ip` String,
`xff` String,
`client_city` String,
`client_region` String,
`client_country` String,
`http_user_agent` String,
`client_browser_family` String,
`client_browser_major` String,
`client_os_family` String,
`client_os_major` String,
`client_device_brand` String,
`client_device_model` String,
`createdtime` DateTime64(3, 'Asia/Shanghai')
)
ENGINE = MergeTree
PARTITION BY toYYYYMMDD(timestamp)
PRIMARY KEY (timestamp,
server_ip,
status,
top_path,
domain,
upstreamhost,
client_ip,
remote_user,
request_method,
protocol,
responsetime,
upstreamtime,
duration,
request_length,
response_length,
path,
referer,
client_city,
client_region,
client_country,
client_browser_family,
client_browser_major,
client_os_family,
client_os_major,
client_device_brand,
client_device_model
)
TTL toDateTime(timestamp) + toIntervalDay(30)
SETTINGS index_granularity = 8192;
到此为止,我们 click house 已经完成安装
http://10.0.0.215:8123/play
欢迎来撩 : 汇总all