sudo service clickhouse-server start clickhouse-client # or "clickhouse-client --password" if you've set up a password.
填写default user的初始密码,回车可以看到如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Enter password for default user: Password for default user is saved in file /etc/clickhouse-server/users.d/default-password.xml. Setting capabilities for clickhouse binary. This is optional. Cannot set 'net_admin' or 'ipc_lock' or 'sys_nice' or 'net_bind_service' capability for clickhouse binary. This is optional. Taskstats accounting will be disabled. To enable taskstats accounting you may add the required capability later manually. chown -R clickhouse:clickhouse '/etc/clickhouse-server'
lintong@master:~$ sudo clickhouse start chown -R clickhouse: '/var/run/clickhouse-server/' Will run sudo --preserve-env -u 'clickhouse' /usr/bin/clickhouse-server --config-file /etc/clickhouse-server/config.xml --pid-file /var/run/clickhouse-server/clickhouse-server.pid --daemon Waiting for server to start Waiting for server to start Server started
连接clickhouse
1 2 3 4 5 6 7
lintong@master:~$ clickhouse-client ClickHouse client version 23.10.3.5 (official build). Connecting to localhost:9000 as user default. Password for user (default): Connecting to localhost:9000 as user default. Connected to ClickHouse server version 23.10.3 revision 54466.
client使用的9000端口
访问的话可以看到如下说明,如果想要使用http连接的话,需要使用8123端口
1 2 3
Port 9000 is for clickhouse-client program You must use port 8123 for HTTP.
INSERT INTO helloworld.my_first_table (user_id, message, timestamp, metric) VALUES (101, 'Hello, ClickHouse!', now(), -1.0 ), (102, 'Insert a lot of rows per batch', yesterday(), 1.41421 ), (102, 'Sort your data based on your commonly-used queries', today(), 2.718 ), (101, 'Granules are the smallest chunks of data read', now() + 5, 3.14159 )
private static final Logger logger = Logger.getLogger(HelloWorldServer.class.getName());
private int port = 50051; private Server server;
public static void main(String[] args) throws IOException, InterruptedException { final HelloWorldServer server = new HelloWorldServer(); server.start(); server.blockUntilShutdown(); }
private void start() throws IOException { server = ServerBuilder.forPort(port) .addService(new GreeterImpl()) .build() .start(); logger.info("Server started, listening on " + port);
System.err.println("*** shutting down gRPC server since JVM is shutting down"); HelloWorldServer.this.stop(); System.err.println("*** server shut down"); } }); }
private final ManagedChannel channel; private final GreeterGrpc.GreeterBlockingStub blockingStub; private static final Logger logger = Logger.getLogger(HelloWorldClient.class.getName());
public static void main(String[] args) throws InterruptedException { HelloWorldClient client = new HelloWorldClient("127.0.0.1", 50051); try { String user = "world"; if (args.length > 0) { user = args[0]; } client.greet(user); } finally { client.shutdown(); } }
public HelloWorldClient(String host, int port) { channel = ManagedChannelBuilder.forAddress(host, port) .usePlaintext() .build();
➜ /Users/lintong/coding/java/grpc-java/compiler git:(ae49d275b) $ ../gradlew java_pluginExecutable -PskipAndroid=true * Skipping the build of Android projects because skipAndroid=true
> Configure project :grpc-compiler *** Building codegen requires Protobuf *** Please refer to https://github.com/grpc/grpc-java/blob/master/COMPILING.md#how-to-build-code-generation-plugin
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.3/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
var ( addr = flag.String("addr", "localhost:50051", "the address to connect to") name = flag.String("name", defaultName, "Name to greet") )
func main() { flag.Parse() // Set up a connection to the server. conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { log.Fatalf("did not connect: %v", err) } defer conn.Close() c := pb.NewGreeterClient(conn)
// Contact the server and print out its response. ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() r, err := c.SayHello(ctx, &pb.HelloRequest{Name: *name}) if err != nil { log.Fatalf("could not greet: %v", err) } log.Printf("Greeting: %s", r.GetMessage()) }
// 定义结构体 type Inventory struct { Material string Count uint } // 赋值 sweaters := Inventory{"wool", 17} // 定义模板 tmpl, err := template.New("test").Parse(` {{.Count}} items are made of {{.Material}} `) if err != nil { panic(err) } // 填充模板 err = tmpl.Execute(os.Stdout, sweaters) if err != nil { panic(err) }
输出
1 2
17 items are made of wool
2.if else
1.判断字符串是否相等
1 2 3 4 5 6 7 8 9 10 11
{{ if eq .Material "wool" }} Material is "wool" {{ else if eq .Material "not wool" }} Material is not "wool" {{ end }} {{ if eq .Count 17 }} Count is 17 {{ else if eq .Count 10 }} Count is not 10 {{ end }}
输出
1 2 3 4
Material is "wool"
Count is 17
2.多条件,与或非
1 2 3 4
{{ if or (eq .Material "not wool") (eq .Count 17) }} Count is 17 {{ end }}