这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
# Copyright (c) 2017 Minoru Osuka
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

.DS_Store

# Eclipse
.classpath
.project

# Gogland
.idea/

# Blast
bin/
dist/

# TLS
*.pem
*.csr

Expand Down
16 changes: 1 addition & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright (c) 2020 Minoru Osuka
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.14.0-alpine3.11

ARG VERSION
Expand Down Expand Up @@ -46,4 +32,4 @@ COPY --from=0 /go/src/github.com/mosuka/cete/docker-entrypoint.sh /usr/bin/
EXPOSE 7000 8000 9000

ENTRYPOINT [ "/usr/bin/docker-entrypoint.sh" ]
CMD [ "cete", "--help" ]
CMD [ "cete", "start" ]
60 changes: 25 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright (c) 2020 Minoru Osuka
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

GOOS ?=
GOARCH ?=
GO111MODULE ?= on
Expand All @@ -27,7 +13,7 @@ PACKAGES = $(shell $(GO) list ./... | grep -v '/vendor/')

PROTOBUFS = $(shell find . -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq | grep -v /vendor/)

TARGET_PACKAGES = $(shell find . -name 'main.go' -print0 | xargs -0 -n1 dirname | sort | uniq | grep -v /vendor/)
TARGET_PACKAGES = $(shell find $(CURDIR) -name 'main.go' -print0 | xargs -0 -n1 dirname | sort | uniq | grep -v /vendor/)

GRPC_GATEWAY_PATH = $(shell $(GO) list -m -f "{{.Dir}}" github.com/grpc-ecosystem/grpc-gateway)

Expand Down Expand Up @@ -55,13 +41,13 @@ GO := GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) CGO_CFLAGS=$(CGO_
.PHONY: protoc
protoc:
@echo ">> generating proto3 code"
@for proto_dir in $(PROTOBUFS); do echo $$proto_dir; protoc --proto_path=. --proto_path=$$proto_dir --proto_path=${GRPC_GATEWAY_PATH} --proto_path=${GRPC_GATEWAY_PATH}/third_party/googleapis --go_out=plugins=grpc:$(GOPATH)/src $$proto_dir/*.proto || exit 1; done
@for proto_dir in $(PROTOBUFS); do echo $$proto_dir; protoc --proto_path=. --proto_path=$$proto_dir --proto_path=${GRPC_GATEWAY_PATH} --proto_path=${GRPC_GATEWAY_PATH}/third_party/googleapis --grpc-gateway_out=logtostderr=true,allow_delete_body=true:$(GOPATH)/src $$proto_dir/*.proto || exit 1; done
for proto_dir in $(PROTOBUFS); do echo $$proto_dir; protoc --proto_path=. --proto_path=$$proto_dir --proto_path=${GRPC_GATEWAY_PATH} --proto_path=${GRPC_GATEWAY_PATH}/third_party/googleapis --go_out=plugins=grpc:$(GOPATH)/src $$proto_dir/*.proto || exit 1; done
for proto_dir in $(PROTOBUFS); do echo $$proto_dir; protoc --proto_path=. --proto_path=$$proto_dir --proto_path=${GRPC_GATEWAY_PATH} --proto_path=${GRPC_GATEWAY_PATH}/third_party/googleapis --grpc-gateway_out=logtostderr=true,allow_delete_body=true:$(GOPATH)/src $$proto_dir/*.proto || exit 1; done

.PHONY: format
format:
@echo ">> formatting code"
@$(GO) fmt $(PACKAGES)
$(GO) fmt $(PACKAGES)

.PHONY: test
test:
Expand All @@ -72,14 +58,21 @@ test:
@echo " CGO_CFLAGS = $(CGO_CFLAGS)"
@echo " CGO_LDFLAGS = $(CGO_LDFLAGS)"
@echo " BUILD_TAGS = $(BUILD_TAGS)"
@$(GO) test -v -tags="$(BUILD_TAGS)" $(PACKAGES)
$(GO) test -v -tags="$(BUILD_TAGS)" $(PACKAGES)

.PHONY: coverage
coverage:
@echo ">> checking coverage of all packages"
$(GO) test -coverprofile=./cover.out -tags="$(BUILD_TAGS)" $(PACKAGES)
$(GO) tool cover -html=cover.out -o cover.html

.PHONY: clean
clean:
@echo ">> cleaning binaries"
rm -rf ./bin
rm -rf ./data
rm -rf ./dist

.PHONY: build
build:
@echo ">> building binaries"
Expand All @@ -90,7 +83,7 @@ build:
@echo " CGO_LDFLAGS = $(CGO_LDFLAGS)"
@echo " BUILD_TAGS = $(BUILD_TAGS)"
@echo " VERSION = $(VERSION)"
@for target_pkg in $(TARGET_PACKAGES); do echo $$target_pkg; $(GO) build -tags="$(BUILD_TAGS)" $(LDFLAGS) -o ./bin/`basename $$target_pkg`$(BIN_EXT) $$target_pkg || exit 1; done
for target_pkg in $(TARGET_PACKAGES); do echo $$target_pkg; $(GO) build -tags="$(BUILD_TAGS)" $(LDFLAGS) -o ./bin/`basename $$target_pkg`$(BIN_EXT) $$target_pkg || exit 1; done

.PHONY: install
install:
Expand All @@ -102,7 +95,7 @@ install:
@echo " CGO_LDFLAGS = $(CGO_LDFLAGS)"
@echo " BUILD_TAGS = $(BUILD_TAGS)"
@echo " VERSION = $(VERSION)"
@for target_pkg in $(TARGET_PACKAGES); do echo $$target_pkg; $(GO) install -tags="$(BUILD_TAGS)" $(LDFLAGS) $$target_pkg || exit 1; done
for target_pkg in $(TARGET_PACKAGES); do echo $$target_pkg; $(GO) install -tags="$(BUILD_TAGS)" $(LDFLAGS) $$target_pkg || exit 1; done

.PHONY: dist
dist:
Expand All @@ -115,11 +108,11 @@ dist:
@echo " BUILD_TAGS = $(BUILD_TAGS)"
@echo " VERSION = $(VERSION)"
mkdir -p ./dist/$(GOOS)-$(GOARCH)/bin
@for target_pkg in $(TARGET_PACKAGES); do echo $$target_pkg; $(GO) build -tags="$(BUILD_TAGS)" $(LDFLAGS) -o ./dist/$(GOOS)-$(GOARCH)/bin/`basename $$target_pkg`$(BIN_EXT) $$target_pkg || exit 1; done
for target_pkg in $(TARGET_PACKAGES); do echo $$target_pkg; $(GO) build -tags="$(BUILD_TAGS)" $(LDFLAGS) -o ./dist/$(GOOS)-$(GOARCH)/bin/`basename $$target_pkg`$(BIN_EXT) $$target_pkg || exit 1; done
(cd ./dist/$(GOOS)-$(GOARCH); tar zcfv ../cete-${VERSION}.$(GOOS)-$(GOARCH).tar.gz .)

.PHONY: git-tag
git-tag:
.PHONY: tag
tag:
@echo ">> tagging github"
@echo " VERSION = $(VERSION)"
ifeq ($(VERSION),$(filter $(VERSION),latest master ""))
Expand All @@ -129,30 +122,27 @@ else
git push origin $(VERSION)
endif

.PHONY: docker-build
docker-build:
.PHONY: build-docker
build-docker:
@echo ">> building docker container image"
@echo " DOCKER_REPOSITORY = $(DOCKER_REPOSITORY)"
@echo " VERSION = $(VERSION)"
docker build -t $(DOCKER_REPOSITORY)/cete:latest --build-arg VERSION=$(VERSION) .
docker tag $(DOCKER_REPOSITORY)/cete:latest $(DOCKER_REPOSITORY)/cete:$(VERSION)

.PHONY: docker-push
docker-push:
.PHONY: push-docker
push-docker:
@echo ">> pushing docker container image"
@echo " DOCKER_REPOSITORY = $(DOCKER_REPOSITORY)"
@echo " VERSION = $(VERSION)"
docker push $(DOCKER_REPOSITORY)/cete:latest
docker push $(DOCKER_REPOSITORY)/cete:$(VERSION)

.PHONY: clean
clean:
@echo ">> cleaning binaries"
rm -rf ./bin
rm -rf ./data
rm -rf ./dist
.PHONY: clean-docker
clean-docker:
docker rmi -f $(shell docker images --filter "dangling=true" -q --no-trunc)

.PHONY: cert
cert:
@echo ">> generating certification"
openssl req -x509 -nodes -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -subj '/CN=localhost'
openssl req -x509 -nodes -newkey rsa:4096 -keyout ./etc/cete-key.pem -out ./etc/cete-cert.pem -days 365 -subj '/CN=localhost'
54 changes: 28 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
<!--
Copyright (c) 2020 Minoru Osuka

Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

# Cete

Cete is a distributed key value store server written in [Go](https://golang.org) built on top of [BadgerDB](https://blog.dgraph.io/post/badger/).
Expand Down Expand Up @@ -86,6 +67,27 @@ $ make GOOS=linux dist
$ make GOOS=darwin dist
```

## Configure Cete

| CLI Flag | Environment variable | Configuration File | Description |
| --- | --- | --- | --- |
| --config-file | - | - | config file. if omitted, cete.yaml in /etc and home directory will be searched |
| --id | CETE_ID | id | node ID |
| --raft-address | CETE_RAFT_ADDRESS | raft_address | Raft server listen address |
| --grpc-address | CETE_GRPC_ADDRESS | grpc_address | gRPC server listen address |
| --http-address | CETE_HTTP_ADDRESS | http_address | HTTP server listen address |
| --data-directory | CETE_DATA_DIRECTORY | data_directory | data directory which store the key-value store data and Raft logs |
| --peer-grpc-address | CETE_PEER_GRPC_ADDRESS | peer_grpc_address | listen address of the existing gRPC server in the joining cluster |
| --certificate-file | CETE_CERTIFICATE_FILE | certificate_file | path to the client server TLS certificate file |
| --key-file | CETE_KEY_FILE | key_file | path to the client server TLS key file |
| --common-name | CETE_COMMON_NAME | common_name | certificate common name |
| --log-level | CETE_LOG_LEVEL | log_level | log level |
| --log-file | CETE_LOG_FILE | log_file | log file |
| --log-max-size | CETE_LOG_MAX_SIZE | log_max_size | max size of a log file in megabytes |
| --log-max-backups | CETE_LOG_MAX_BACKUPS | log_max_backups | max backup count of log files |
| --log-max-age | CETE_LOG_MAX_AGE | log_max_age | max age of a log file in days |
| --log-compress | CETE_LOG_COMPRESS | log_compress | compress a log file |


## Starting Cete node

Expand Down Expand Up @@ -122,7 +124,7 @@ The result of the above command is:
}
```

### Putting a key-value
## Putting a key-value

To put a key-value, execute the following command:

Expand All @@ -137,7 +139,7 @@ $ curl -X PUT 'http://127.0.0.1:8000/v1/data/1' --data-binary value1
$ curl -X PUT 'http://127.0.0.1:8000/v1/data/2' -H "Content-Type: image/jpeg" --data-binary @/path/to/photo.jpg
```

### Getting a key-value
## Getting a key-value

To get a key-value, execute the following command:

Expand All @@ -157,7 +159,7 @@ You can see the result. The result of the above command is:
value1
```

### Deleting a value by key via CLI
## Deleting a key-value

Deleting a value by key, execute the following command:

Expand Down Expand Up @@ -360,7 +362,7 @@ Cete supports HTTPS access, ensuring that all communication between clients and
One way to generate the necessary resources is via [openssl](https://www.openssl.org/). For example:

```bash
$ openssl req -x509 -nodes -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -subj '/CN=localhost'
$ openssl req -x509 -nodes -newkey rsa:4096 -keyout ./etc/cete-key.pem -out ./etc/cete-cert.pem -days 365 -subj '/CN=localhost'
Generating a 4096 bit RSA private key
............................++
........++
Expand All @@ -372,9 +374,9 @@ writing new private key to 'key.pem'
Starting a node with HTTPS enabled, node-to-node encryption, and with the above configuration file. It is assumed the HTTPS X.509 certificate and key are at the paths server.crt and key.pem respectively.

```bash
$ ./bin/cete start --id=node1 --bind-addr=:7000 --grpc-addr=:9000 --http-addr=:8000 --data-dir=/tmp/cete/node1 --peer-grpc-addr=:9000 --cert-file=./cert.pem --key-file=./key.pem --cert-hostname=localhost
$ ./bin/cete start --id=node2 --bind-addr=:7001 --grpc-addr=:9001 --http-addr=:8001 --data-dir=/tmp/cete/node2 --peer-grpc-addr=:9000 --cert-file=./cert.pem --key-file=./key.pem --cert-hostname=localhost
$ ./bin/cete start --id=node3 --bind-addr=:7002 --grpc-addr=:9002 --http-addr=:8002 --data-dir=/tmp/cete/node3 --peer-grpc-addr=:9000 --cert-file=./cert.pem --key-file=./key.pem --cert-hostname=localhost
$ ./bin/cete start --id=node1 --bind-addr=:7000 --grpc-addr=:9000 --http-addr=:8000 --data-dir=/tmp/cete/node1 --peer-grpc-addr=:9000 --cert-file=./etc/cert.pem --key-file=./etc/key.pem --cert-hostname=localhost
$ ./bin/cete start --id=node2 --bind-addr=:7001 --grpc-addr=:9001 --http-addr=:8001 --data-dir=/tmp/cete/node2 --peer-grpc-addr=:9000 --cert-file=./etc/cert.pem --key-file=./etc/key.pem --cert-hostname=localhost
$ ./bin/cete start --id=node3 --bind-addr=:7002 --grpc-addr=:9002 --http-addr=:8002 --data-dir=/tmp/cete/node3 --peer-grpc-addr=:9000 --cert-file=./etc/cert.pem --key-file=./etc/key.pem --cert-hostname=localhost
```

You can access the cluster by adding a flag, such as the following command:
Expand Down
53 changes: 0 additions & 53 deletions cmd/cete/cluster.go

This file was deleted.

Loading