RocketChat安装部署

近期看到一款名为RocketChat的聊天工具,于是就自己安装看了下,感觉还不错,这里就记录下。

RocketChat官方网站:https://rocket.chat/。项目Github地址:https://github.com/RocketChat/Rocket.Chat

RocketChat是一款以nodejs开发的WebChat平台。

需求依赖

目前RocketChat最新的版本 3.4.1,所依赖服务如下:

  • NodeJS 12
  • MongoDB 4

安装NodeJS

wget https://nodejs.org/dist/v12.18.2/node-v12.18.2-linux-x64.tar.xz
tar Jxf node-v12.18.2-linux-x64.tar.xz -C /usr/local/
mv /usr/local/node-v12.18.2-linux-x64/ /usr/local/nodejs
echo 'PATH=$PATH:/usr/local/nodejs/bin' > /etc/profile.d/nodejs.sh
source /etc/profile.d/nodejs.sh
npm install -g npm
npm install pm2@latest -g

这里为方便,就直接使用官方已编译完成的二进制程序。

安装MongoDB

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-4.2.8.tgz
tar zxf mongodb-linux-x86_64-rhel80-4.2.8.tgz -C /usr/local/
mv /usr/local/mongodb-linux-x86_64-rhel80-4.2.8 /usr/local/mongodb-4.2.8
groupadd -g 400 mongod
useradd -g mongod -u 400 -s /sbin/nologin -d /data/mongodb/ -c "Mongod Server" -M mongod
mkdir -p /data/mongodb/data
chown -R mongod:mongod /data/mongodb/
vim /data/mongodb/mongod.conf
# MongoDB Configure File
dbpath      = /data/mongodb/data
logpath     = /data/mongodb/mongod.log
pidfilepath = /data/mongodb/mongod.pid
keyFile     = /data/mongodb/mongod-key
logappend   = true
fork        = true
auth        = true
#replSet     = reps

配置文件需开启replset,使其作为群集节点运行,虽然只有一台,但是RocketChat需要。但由于还未初初始化,未创建管理员账号,这里先将其注释,之后再开启。

同时副本集间认证用的keyFile也需要自己创建:

openssl rand -base64 752 > /data/mongodb/mongod-key
chown mongod:mongod /data/mongodb/mongod-key
chmod 600 /data/mongodb/mongod-key

修改host文件,指定副本集间IP与名称的对应,虽然只有一台:

vim /etc/hosts
# Hosts File for es
# System localhost
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

# ==== User Defiend Start ====
# == Members. ==
10.10.0.119     mongo-node1
# ==== User Defiend End ====

设置为服务并启动:

vim /usr/lib/systemd/system/mongod.service
# Simple MongoDB systemd service file.
[Unit]
Description=MongoDB Community Server
After=local-fs.target network.target syslog.target remote-fs.target

[Install]
WantedBy=multi-user.target

[Service]
User=mongod
Group=mongod
# (file size)
LimitFSIZE=infinity
# (cpu time)
LimitCPU=infinity
# (virtual memory size)
LimitAS=infinity
# (open files)
LimitNOFILE=65535
# (processes/threads)
LimitNPROC=65535
PermissionsStartOnly=true
ExecStart=/usr/local/mongodb-4.2.8/bin/mongod --config /data/mongodb/mongod.conf
PIDFile=/data/mongodb/mongod.pid
systemctl start mongod
systemctl status mongod

配置文件里开启了强制认证,这里先创建管理员用户:

mongo admin
db.createUser(
  {
    user: "root",
    pwd: "12345678",
    roles: [ { role: "root", db: "admin" } ]
  }
)

然后将配置文件中replSet的注释去掉,重启mongod服务:

systemctl restart mongod

使用刚创建的root用户登陆;初使用化副本集:

mongo admin -u root -p
rs.initiate({ "_id":"reps","members":[
  {"_id":1,"host":"mongo-node1:27017","priority":2}
]})

创建rocketchat用户:

db.createUser(
  {
    user: "rocketchat",
    pwd: "123456",
    roles: [ { role: "readWriteAnyDatabase", db: "admin" } ]
  }
)

赋权给local库:

db.grantRolesToUser( "rocketchat", [ "readWrite" , { role: "read", db: "local" } ]  )

RocketChat需要在副本集中的local库有写入权限

《RocketChat安装部署》有4条评论

发表评论

error: Content is protected !!