我尝试使用以下步骤安装Couchbase社区版:
echo '
deb [ arch=amd64 ] http://packages.couchbase.com/releases/couchbase-server/enterprise/deb/ xenial xenial/main
deb [ arch=amd64 ] http://packages.couchbase.com/releases/couchbase-server/community/deb/ xenial xenial/main
deb http://packages.couchbase.com/ubuntu xenial xenial/main
' | sudo tee /etc/apt/sources.list.d/couchbase.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6EF1EAC479CF7903
sudo apt-get update
sudo apt-get install couchbase-server-community
apt list -a couchbase-server-community
# make command line available
echo '
export PATH=$PATH:/opt/couchbase/bin
' | tee -a .bashrc
export PATH=$PATH:/opt/couchbase/bin
# init cluster
couchbase-cli cluster-init -c 127.0.0.1 \
--cluster-username Administrator \
--cluster-password YourPassword \
--services data,index,query \
--cluster-ramsize 512 \
--cluster-index-ramsize 256
# create bucket
couchbase-cli bucket-create -c 127.0.0.1:8091 --username Administrator \
--password YourPassword --bucket test1 --bucket-type couchbase \
--bucket-ramsize 512
# start n1ql
cbq -u Administrator -p YourPassword -engine=http://127.0.0.1:8091/和源代码:
package main
import (
"fmt"
"github.com/kokizzu/gotro/L"
"gopkg.in/couchbase/gocb.v1"
"math/rand"
"time"
)
const Username = `Administrator`
const Password = `YourPassword`
const Bucket = `test1`
type Score struct {
User int64 `json:"user"`
RefId int64 `json:"ref_id"`
Epoch int64 `json:"epoch"`
Score int `json:"score"`
Type string `json:"type"`
}
func main() {
cluster, err := gocb.Connect("couchbase://127.0.0.1")
if L.IsError(err,`cannot connect to couchbase`) {
return
}
cluster.Authenticate(gocb.PasswordAuthenticator{Username: Username, Password: Password})
bucket, _ := cluster.OpenBucket(Bucket, "")
m := bucket.Manager("", "")
err = m.CreatePrimaryIndex("", true, false)
if L.IsError(err, `failed create primary index`) {
return
}
indexes := []string{`type`, `epoch`, `user`, `refid`}
for _, index := range indexes {
err = m.CreateIndex(index, []string{index}, true, false)
if L.IsError(err, `failed create index %s`, index) {
return
}
}
for x := 0; x < 10000; x++ {
userId := 1 + rand.Intn(1000)
refId := 1 + rand.Intn(100)
epoch := time.Now().AddDate(0, 0, rand.Intn(365)+1).Unix()
score := 10 + rand.Intn(100)
_, err := bucket.Upsert(
fmt.Sprintf("user%dref%d", userId, refId),
Score{
User: int64(userId),
RefId: int64(refId),
Epoch: epoch,
Score: score,
Type: `score`,
}, 0)
if L.IsError(err, `failed upsert`) {
return
}
}
// Use query
sql := `SELECT user,SUM(score) FROM ` + Bucket + ` WHERE epoch > $1 GROUP BY user ORDER BY 2 DESC`
query := gocb.NewN1qlQuery(sql)
window := []int{1, 7, 30, 365}
for _, delta := range window {
fmt.Println(delta)
epoch := time.Now().AddDate(0, 0, delta).Unix()
rows, err := bucket.ExecuteN1qlQuery(query, []interface{}{epoch})
if L.IsError(err, `failed query %s`, sql) {
return
}
var row interface{}
defer rows.Close()
for rows.Next(&row) {
fmt.Printf("Row: %v", row)
}
}
}它显示错误:
2020-02-15 23:58:33.271 IsError ▶ &gocb.n1qlMultiError{
{Code:0x1388, Message:"GSI CreateIndex() - cause: Fails to create index. There is no available index service that can process this request at this time. Index Service can be in bootstrap, recovery, or non-reachable. Please retry the operation at a later time."},
}我是不是错过了一些步骤?或者这是Couchbase Community Edition 6.0的限制吗?
在web用户界面上,集群已经有了"data,index,query“标签,所以不能在该集群上创建索引吗?
发布于 2020-02-21 04:44:07
虽然我不能确定,但问题的核心很可能是通过REST接口向Couchbase发出的命令异步发生。如错误所示,索引的某些组件可能尚未初始化,并且它无法接受下一条命令。在编写命令脚本时,您很可能会遇到这种情况。Couchbase的REST接口确实表明工作将与HTTP 201回复异步进行。也就是说,REST接口无法检查完成情况,couchbase-cli也无法检查,所以我相信它只能返回成功。
因为像创建索引这样的事情可能是幂等的,所以只需使用backoff-retry重试一段时间作为解决方法。
改进此界面的问题跟踪工具是MB-11484。
发布于 2020-05-30 07:02:39
发生这种情况的一个可能原因是,在Couchbase也在侦听的同一端口上正在运行另一个进程,以便创建索引。
您可以在此处查看Couchbase使用的端口:
https://docs.couchbase.com/server/current/install/install-ports.html
要解决此问题,您可以按照本文中的说明更改索引端口,或者结束当前正在使用该端口的进程/服务。
要查找使用该端口的进程的PID,您可以在以管理员身份运行时,在Windows命令提示符下运行netstat -aob。
对于我来说,我删除了一个运行在端口9100上的服务,然后就可以创建索引了。
https://stackoverflow.com/questions/60241347
复制相似问题