服务器安装
安装要求
操作系统
支持所有主流的操作系统,包括Windows、Linux和macOS。
环境
我们强烈建议您使用 Yarn 1.x 运行 & Casdoor 前端,使用 NPM可能会导致UI 风格问题。 更多详细信息见: Casdoor#294
对于 中国大陆 用户,为了成功下载依赖关系包, 您需要通过配置 GOPROXY 环境变量来使用Go 代理。 我们强烈建议使用:https://goproxy.cn/
数据库
Casdoor使用 XORM 与数据库进行交互。 基于 Xorm Drivers Support, 当前支持的数据库包括:
MySQL
MariaDB
PostgreSQL
CockroachDB
SQL Server
Oracle
SQLite 3
TiDB
下载
Casdoor的源代码托管在 GitHub: https://github.com/casdoor/casdoor 。 Go 后端代码和 React 前端代码都在单个仓库中。
名称 | 描述 | 语言 | 源代码 |
---|---|---|---|
前端 | Casdoor的网页前端界面 | JavaScript + React | https://github.com/casdoor/casdoor/tree/master/web |
后端 | Casdoor的ResTful API 后端 | Golang + Beego + XORM | https://github.com/casdoor/casdoor |
Casdoor支持 Go Modules
。 要下载代码,您直接通过git克隆仓库就可以了:
cd /文件夹路径/
git clone https://github.com/casdoor/casdoor
配置
配置数据库
Casdoor支持MySQL, msSQL,Sqlite3,PostgreSQL等数据库。 默认使用MySQL。 如果您想使用支持以外的数据库,请自行修改object/adapter包
MySQL:
Casdoor将会把users,nodes和topics信息存储在一个命名为casdoor
的MySQL数据库中。 如果数据库不存在,则需手动创建。 数据库配置信息可以在 https://github.com/casdoor/casdoor/blob/master/conf/app.conf 中修改
driverName = mysql
dataSourceName = root:123456@tcp(localhost:3306)/
dbName = casdoor
PostgreSQL:
因为在使用xorm打开Postgres时我们必须选择一个数据库,所以您应该在运行Casdoor前手动准备一个数据库
假设您已经准备了一个名为 casdoor
的数据库,您应该这样编写 app.conf
:
driverName = postgres
dataSourceName = "user=postgres password=postgres host=localhost port=5432 sslmode=disable dbname=casdoor"
dbName =
对于PostgreSQL,请确保dataSourceName
中的dbName
不是空值,并且与上面例子一样将单独 dbName
配置留空
CockroachDB:
你也可以通过postgres驱动程序访问cockroachdb。 它的配置与 postgreSQL 相同。
driverName = postgres
dataSourceName = "user=postgres password=postgres host=localhost port=5432 sslmode=disable dbname=casdoor serial_normalization=virtual_sequence"
dbName =
For CockroachDB, don't forget to add serial_normalization=virtual_sequence
to the dataSourceName
like the above example. otherwise you will get error regarding existed database, whenever the service started or restarted. Notice, this must be added before the database created.
Sqlite3
您应该像这样配置app.conf
:
driverName = sqlite
dataSourceName = "file:casdoor.db?cache=shared"
dbName = casdoor
通过 Ini 文件配置
Casdoor can be configured via a single file: conf/app.conf, the content of which by default is:
appname = casdoor
httpport = 8000
runmode = dev
SessionOn = true
copyrequestbody = true
driverName = mysql
dataSourceName = root:123456@tcp(localhost:3306)/
dbName = casdoor
tableNamePrefix =
showSql = false
redisEndpoint =
defaultStorageProvider =
isCloudIntranet = false
authState = "casdoor"
socks5Proxy = "127.0.0.1:10808"
verificationCodeTimeout = 10
initScore = 2000
logPostOnly = true
origin = "https://door.casdoor.com"
staticBaseUrl = "https://cdn.casbin.org"
enableGzip = true
appname
是应用程序名称,目前没有实际使用httpport
是您后端应用程序正在监听的端口runmode
是dev
或prod
SessionOn
控制是否启用会话,默认为使用。driverName
,dataSourceName
和dbName
之前已经介绍,请参阅 Configure Database.verificationCodeTimeout
设置验证码到期时间。 超时之后用户需要再次获取验证码。
Despite all the configurable fields, as a beginner, you only need to modify two items: driverName
and dataSourceName
based on your database. This database will be used by Casdoor to store all data, including users, organizations, applications and so on.
tableNamePrefix
是使用适配器时表格的前缀。showSql
: 如果日志级别大于INFO 则显示 SQL 语句或不在 Logger 上。redisEndpoint
后填写Redis地址,被Beego用于session存储 如果此参数为空,session数据将被储存在./tmp
文件夹中 使用Redis作为Beego的session存储,此参数的示例为:redis.example.com:6379
。 If Redis is deployed in the local machine, you can uselocalhost:6379
. If Redis password is enabled, useredis.example.com:6379,db,password
. See more details at: https://beego.run/docs/module/session.md#saving-provider-configdefaultStorageProvider
是默认的文件存储服务名称。 如果您需要使用文件存储服务,例如头像上传
, 您需要设置存储提供商,并在您的应用
中应用它。 详情请参阅 存储isCloudIntranet
用于确定您的提供者端是否是内联网端点。authstate
是授权应用程序名称。 登录时将检查该参数。socks5Proxy
是 SOCKS 代理服务器 IP 地址。 设置代理端口, 因为我们有与谷歌相关的服务或使用Google
GitHub
Facebook
LinkedIn
Steam
作为OAuth Provider ,在某些领域将受到网络限制。initscore
是每个用户的最初分数。 每个用户都有一个得分属性。 得分被 Casnode 所使用。 分数无法控制 Casdoor 中的任何东西。logPostOnly
用于识别是否只使用帖子方法添加记录。origin
是origin形式的后端域名staticBaseUrl
是系统初始化数据库时静态图像的地址。enableGzip
当请求头带有Accept-Encoding=gzip
标志时,将会接受并返回通过gzip编码的响应.
通过环境变量配置
All configuration items defined by Casdoor in the ini file mentioned above can be chosen to configuration via environmental variables, so can some of the beego configurations items(httpport,appname).
For example, when you try to start casdoor, you can use something like this to pass the configuration via environmental variables.
appname=casbin go run main.go
Besides, export
derivatives are also a possible method. The names of environmental variables should be exactly the same with the names you want to use in the ini file.
注意: 环境变量中的配置会覆盖 ini 文件中的配置.
运行
当前有两种启动方法,您可以根据自己的情况选择一个。
开发模式
Backend
Casdoor's Go backend runs at port 8000 by default. You can start the Go backend with the following command:
go run main.go
After the server is successfully running, we can start the frontend part.
Frontend
Casdoor's frontend is a very classic Create-React-App (CRA) project. It runs at port 7001
by default. Use the following commands to run the frontend:
cd web
yarn install
yarn start
Visit: http://localhost:7001 in your browser. Log into Casdoor dashboard with the default global admin account: built-in/admin
admin
123
生产模式
Backend
Build Casdoor Go backend code into executable and start it.
For Linux:
go build
./casdoor
For Windows:
go build
casdoor.exe
Frontend
Build Casdoor frontend code into static resources (.html, .js, .css files):
cd web
yarn install
yarn build
Visit: http://localhost:8000 in your browser. Log into Casdoor dashboard with the default global admin account: built-in/admin
admin
123
To use another port, please edit conf/app.conf
and modify httpport
, then restart the Go backend.
In dev environment, the frontend is run by yarn run
in port 7001, so if you want to go to Casdoor login page, you need set Casdoor link as http://localhost:7001.
In prod environment, the frontend files is first built by yarn build
and served in port 8000, so if you want to go to Casdoor login page, you need to set Casdoor link as http://SERVER_IP:8000 (If you are using reverse proxy, you need to set the link as your domain).
Take our official forum Casnode as an example:
Casnode uses Casdoor to handle authentication.
When we are testing Casnode in dev environment, we set the serverUrl
as http://localhost:7001, so when we test signin and signup functionality using Casdoor, it will go to localhost 7001 which is the Casdoor port.
And when we put Casnode to prod environment, we set the serverUrl
as https://door.casdoor.com, so users can signin or signup using Casdoor.