说明
Fiora
是一款偏二次元的Web多人在线聊天应用,使用Node.js
、Mongodb
、Socket.io
和React
编写的
截图
功能
1。好友, 群组, 私聊, 群聊
2。文本, 图片, 代码, url等多种类型消息
3。贴吧表情, 滑稽表情, 搜索表情包
4。桌面通知, 声音提醒, 消息语音朗读
5。自定义桌面背景, 主题颜色, 文本颜色
6。查看在线用户, @功能
7。管理员
手动安装
Github地址:https://github.com/yinxin630/fiora
所需环境:Nodejs >= 8.9.0
、Mongodb
1。安装Nodejs
#Debian/Ubuntu系统 curl -sL https://deb.nodesource.com/setup_10.x | bash - apt install -y git nodejs #CentOS系统 curl -sL https://rpm.nodesource.com/setup_10.x | bash - yum install nodejs git -y
2。安装Mongodb
#CentOS 6系统,将下面命令一起复制进SSH客户端运行 cat < /etc/yum.repos.d/mongodb.repo [mongodb-org-4.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/6/mongodb-org/4.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc EOF yum -y install mongodb-org #CentOS 7系统,将下面命令一起复制进SSH客户端运行 cat < /etc/yum.repos.d/mongodb.repo [mongodb-org-4.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc EOF yum -y install mongodb-org #Debian 8系统 apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/4.0 main" | tee /etc/apt/sources.list.d/mongodb-org-4.0.list apt update -y apt install -y mongodb-org #Debian 9系统 curl https://www.mongodb.org/static/pgp/server-4.0.asc | apt-key add - echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.0 main" | tee /etc/apt/sources.list.d/mongodb-org-4.0.list apt-get update -y apt-get install -y mongodb-org #Debian 10系统 curl https://www.mongodb.org/static/pgp/server-4.2.asc | apt-key add - echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list apt update -y apt install -y mongodb-org #Ubuntu 16.04系统 apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 echo "deb https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.0.list apt update -y apt install -y mongodb-org #Ubuntu 18.04、18.10、19.04系统 apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 echo "deb https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.0.list apt update -y apt install -y mongodb-org
如果导入公匙时出现gnupg, gnupg2 and gnupg1 do not seem to be installed
错误,使用apt install -y gnupg2
,然后重新导入即可。
启动Mongodb
并设置开机自启:
#CentOS 6系统 service mongod start chkconfig mongod on #CentOS 7、Debian、Ubuntu系统 systemctl start mongod systemctl enable mongod
3。安装fiora
#拉取源码并存放于/opt文件夹 git clone https://github.com/yinxin630/fiora.git -b master /opt/fiora cd /opt/fiora #安装依赖,这里不能用npm,需要用yarn来安装 npm i -g yarn yarn #构建 npm run build #转移产物 npm run move-dist #启动 npm start
运行后打开ip:9200
,注册一个账号,然后可以看SSH客户端运行日志,获取自己的userId
#这里注册或登录的时候返回的信息,后面的5d329dd354b9则为自己的userId <-- getLinkmansLastMessages mYNheu93jds7 5d329dd354b9
如果ip:9200
打不开的,可以检查下防火墙,CentOS
系统可以使用以下命令:
#CentOS 6 iptables -I INPUT -p tcp --dport 9200 -j ACCEPT service iptables save service iptables restart #CentOS 7 firewall-cmd --zone=public --add-port=9200/tcp --permanent firewall-cmd --reload
接下来再将自己的账号设置成管理员,先使用Ctrl+C
断开运行。
新建Systemd
配置文件,只适用于CentOS 7
、Debian 8+
、Ubuntu 16+
等。
#先修改你的userId和运行端口后复制到SSH运行 Administrator=5d329dd354b9 Port=9200 #新建fiora用户并授权 useradd -M fiora && usermod -L fiora chown -R fiora:fiora /opt/fiora #新建systemd配置文件,将以下代码一起复制到SSH运行 cat > /etc/systemd/system/fiora.service <<EOF [Unit] Description=fiora After=network.target Wants=network.target [Service] Type=simple PIDFile=/var/run/fiora.pid ExecStart=$(command -v npm) start WorkingDirectory=/opt/fiora Environment=Administrator=$Administrator Port=$Port User=fiora Restart=on-failure RestartSec=42s [Install] WantedBy=multi-user.target EOF
开始启动并设置开机自启:
systemctl start fiora systemctl enable fiora
其它系统,比如CentOS
、Debian 7
等系统,可以直接使用以下方法启动:
#管理员userId和运行端口自行修改 export Administrator=5d329dd354b9 Port=9200 nohup npm start &
此时就可以访问ip:9200
,运行端口以你设置的为准,这时候你登陆的时候,会发现左侧多了个管理员图标
本地运行(开发模式)
git clone https://github.com/yinxin630/fiora.git -b master
yarn
安装, 执行 yarn
. 也可以使用 npm
安装, 执行 npm i
, 但是不能保证所安装的依赖版本一致, 可能会导致运行不起来npm run server
npm run client
http://localhost:8080
修改代码会自动重启服务端和刷新客户端
服务器上运行
npm run build
npm run move-dist
npm start
http://[服务端ip]:[fiora端口号]
在服务器上部署时, 强烈推荐配置七牛CDN, 详情请参考 七牛CDN配置
docker运行
安装Docker
环境
#CentOS 6系统 rpm -iUvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm yum update -y yum -y install docker-io service docker start chkconfig docker on #CentOS 7、Debian、Ubuntu系统 curl -sSL https://get.docker.com/ | sh systemctl start docker systemctl enable docker
直接从 DockerHub 镜像运行
mongo
镜像 docker pull mongo
fiora
镜像 docker pull suisuijiang/fiora
docker network create fiora-network
docker run --name fioradb -p 27017:27017 --network fiora-network mongo
fiora
docker run --name fiora -p 9200:9200 --network fiora-network -e Database=mongodb://fioradb:27017/fiora suisuijiang/fiora
本地构建镜像运行
git clone https://github.com/yinxin630/fiora.git -b master
docker-compose build --no-cache --force-rm
docker-compose up
项目配置
配置列表
config/server.ts
config/client.ts
config/webpack.ts
通过配置文件修改配置
可以直接编辑配置文件, 修改相应配置值
因为修改了文件内容, 后续拉新代码可能会产生冲突
通过命令行参数修改配置
./node_modules/.bin/ts-node server/main.ts --xxx "yyy"
npm
运行时 npm start -- --xxx "yyy"
pm2
运行时 pm2 start npm -- start --xxx "yyy"
xxx
是配置名, yyy
是要配置的值, 配置名可以去配置文件中查看
推荐使用该方法修改配置
通过环境变量修改配置
Linux
和 MaxOS系统
export XXX="yyy" && ./node_modules/.bin/ts-node server/main.ts
Windows
系统 SET "xxx=yyy" && ./node_modules/.bin/ts-node server/main.ts
七牛CDN配置
在没有配置七牛CDN的情况下, 客户端资源和用户上传/下载图片都是消耗服务器带宽的, 并发流量较大, 服务器容易扛不住, 所以强烈推荐使用七牛CDN
其它的CDN运营商没做支持
url
AccessKey
和 SecretKey
构建客户端上传到七牛
qshell
并添加到环境变量qshell account AccessKey SecretKey name
fiora
目录下创建 .qiniurc
配置文件, 内容如下所示: { "src_dir" : "./dist", "bucket" : "七牛空间名称", "overwrite": true, "rescan_local": true }
url
作为 publicPath npm run build -- --publicPath "http://示例地址/fiora/"
CDN
qshell qupload .qiniurc
index.html
npm run move-dist
, 如果是本地构建上传CDN的, 请手动更新 index.html 到服务器上 fiora public
目录下每次更新客户端代码后, 重复4~6步
更新服务端七牛配置
config/server.ts
里的配置项: qiniuAccessKey
/ qiniuSecretKey
/ qiniuBucket
/ qiniuUrlPrefix
注意
qiniuUrlPrefix
配置值要以斜线/结尾, 例如: http://示例地址/
config/webpack.ts
里的配置项: build.assetsPublicPath
, 与构建客户端时的 publicPath
值相同pm2 远程部署/更新
pm2 yarn global add pm2
mkdir -p ~/fiora
source
文件夹 git clone -b master [email protected]:yinxin630/fiora.git ~/fiora/source
pm2 ecosystem
配置文件 cp ecosystem.config.js.example ecosystem.config.js
./deploy.sh
详情请参考 http://pm2.keymetrics.io/docs/usage/deployment/
修改默认群组名称
修改 config/server.ts
中的 defaultGroupName
字段
重启服务器
禁止注册, 手动分配账号
修改 config/server.ts
, 将 disableRegister
选项设置为 true
, 重启服务器生效
在服务端执行 npx ts-node bin/register.ts --username [新用户名] --password [用户密码] 注册新用户
域名反代
1。安装Caddy反代
wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubiBackup/doubi/master/caddy_install.sh && chmod +x caddy_install.sh && bash caddy_install.sh #备用地址 wget -N --no-check-certificate https://www.moerats.com/usr/shell/Caddy/caddy_install.sh && chmod +x caddy_install.sh && bash caddy_install.sh
配置
#以下全部内容是一个整体,请修改域名后一起复制到SSH运行! #http访问,该配置不会自动签发SSL echo "www.moerats.com { gzip proxy / 127.0.0.1:9200 { websocket header_upstream Host {host} header_upstream X-Real-IP {remote} header_upstream X-Forwarded-For {remote} header_upstream X-Forwarded-Port {server_port} header_upstream X-Forwarded-Proto {scheme} } }" > /usr/local/caddy/Caddyfile #https访问,该配置会自动签发SSL,请提前解析域名到VPS服务器 echo "www.moerats.com { gzip tls [email protected] proxy / 127.0.0.1:9200 { websocket header_upstream Host {host} header_upstream X-Real-IP {remote} header_upstream X-Forwarded-For {remote} header_upstream X-Forwarded-Port {server_port} header_upstream X-Forwarded-Proto {scheme} } }" > /usr/local/caddy/Caddyfile
tls
参数会自动帮你签发ssl
证书,如果你要使用自己的ssl
,改为tls /root/xx.crt /root/xx.key
即可。后面为ssl
证书路径。
启动Caddy
/etc/init.d/caddy start