跳到主内容

服务器安装

安装要求

操作系统

All major operating systems, including Windows, Linux, and macOS, are supported.

环境

信息

我们强烈建议使用 Yarn 1.x 来运行和构建Casdoor前端。 使用NPM可能会导致界面样式问题。 欲了解更多详情,请见: casdoor#294

注意事项

如果您的网络无法直接同步Go依赖包,您需要配置GOPROXY环境变量。 我们强烈建议使用: https://goproxy.cn/

数据库

Casdoor使用 XORM 与数据库进行交互。 基于 Xorm Drivers, 当前支持的数据库包括:

  • MySQL
  • MariaDB
  • PostgreSQL
  • CockroachDB
  • SQL Server
  • Oracle
  • SQLite 3
  • TiDB

下载

Casdoor 的源代码托管在 GitHub: https://github.com/casdoor/casdoor。 转到后端代码和 React 前端代码都包含在一个仓库中。

名称描述语言源代码
前端Casdoor的网页前端界面JavaScript + Reacthttps://github.com/casdoor/casdoor/tree/master/web
后端Casdoor的ResTful API 后端Golang + Beego + XORMhttps://github.com/casdoor/casdoor

Casdoor支持 Go Modules。 To download the code, simply clone the code using git:

cd /文件夹路径/
git clone https://github.com/casdoor/casdoor

配置

配置数据库

Casdoor 支持MySQL、MSSQL、SQLite3和PostgreSQL。 默认情况下,Casto使用MySQL。

MySQL

Casdoor将会把users,nodes和topics信息存储在一个名为casdoor的MySQL数据库中。 如果数据库不存在,则需手动创建。 可以在以下位置指定数据库连接字符串 https://github.com/casdoor/blob/master/conf/app.conf

driverName = mysql
dataSourceName = root:123456@tcp(localhost:3306)/
dbName = casdoor

PostgreSQL

在运行 Cassdoor 之前,您需要手动准备PostgreSQL 数据库,因为Castor 需要在使用 xorm 打开 Postgres 时指定一个数据库。

Assuming you have already prepared a database called casdoor, you should specify app.conf like this:

driverName = postgres
dataSourceName = "user=postgres password=postgres host=localhost port=5432 sslmode=disable dbname=casdoor"
dbName =
For PostgreSQL, ensure that dataSourceName has a non-empty dbName, and leave the standalone dbName field empty as shown in the example above. :::

CockroachDB

CockroachDB can also be used with the PostgreSQL driver and has the same configuration as PostgreSQL.

driverName = postgres
dataSourceName = "user=postgres password=postgres host=localhost port=5432 sslmode=disable dbname=casdoor serial_normalization=virtual_sequence"
dbName =

SQLite3

To configure SQLite3, you should specify app.conf like this:

driverName = sqlite
dataSourceName = "file:casdoor.db?cache=shared"
dbName = casdoor

通过 Ini 文件配置

Casdoor can be configured via a single file: conf/app.conf, which by default contains the following content:

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 is the application name, which currently has no practical use.
  • httpport is the port that your backend application is listening on.
  • runmode can be set to dev or prod.
  • SessionOn determines whether to enable session and is enabled by default.
  • driverName, dataSourceName, and dbName were introduced earlier. Please see Configure Database for details.
  • verificationCodeTimeout sets the expiration time of the verification code. After expiration, the user needs to obtain it again.

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, and applications.

  • tableNamePrefix is the prefix of the table when using an adapter.
  • showSql determines whether to show SQL statements on the logger if the log level is greater than INFO.
  • redisEndpoint 后填写Redis地址,被Beego用于session存储 If this parameter is empty, the session data will be stored locally as files in the ./tmp folder. To use Redis as Beego session storage, the value would be something like: redis.example.com:6379. If Redis is deployed locally, you can use localhost:6379. If Redis password is enabled, use redis.example.com:6379,db,password. See more details at: https://github.com/beego/beedoc/blob/master/en-US/module/session.md#saving-provider-config.
  • defaultStorageProvider 是默认的文件存储服务名称。 如果您需要使用文件存储服务,例如 头像上传, 您需要设置存储提供商,并在您的 应用 中应用它。 详情请参阅 存储
  • isCloudIntranet is used to identify whether your provider endpoint is an intranet endpoint.
  • authstate 是授权应用程序名称。 登录时将检查该参数。
  • socks5Proxy 是 SOCKS 代理服务器 IP 地址。 Set the proxy port because we have Google-related services or use Google, GitHub, Facebook, LinkedIn, or Steam as OAuth Providers, which may be restricted by the network in some areas.
  • initscore 是每个用户的最初分数。 每个用户都有一个得分属性。 The score is used by Casnode and does not control anything in Casdoor.
  • logPostOnly is used to determine whether only the post method is used to add a record.
  • origin 是origin形式的后端域名
  • staticBaseUrl is the address of the static image used when the system initializes the database.
  • enableGzip will accept and respond with gzip encoding if the request header includes Accept-Encoding=gzip.

通过环境变量配置

All configuration items defined by Casdoor in the ini file mentioned above can be configured via environment variables, as well as 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 environment variables:

appname=casbin go run main.go

In addition, export derivatives are also a possible method. The names of environmental variables should exactly match the names you want to use in the ini file.

Note: configurations in environmental variables can override the configurations in the ini file.

运行

There are currently two methods to start, and you can choose one according to your situation.

Development Mode

Backend

Casdoor's Go backend runs on port 8000 by default. You can start the Go backend with the following command:

go run main.go

After the server is successfully running, you can start the frontend part.

Frontend

Casdoor's frontend is a very classic Create-React-App (CRA) project. It runs on 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 the Casdoor dashboard with the default global admin account: built-in/admin.

admin
123

Production Mode

Backend

Build the Casdoor Go backend code into an executable and start it.

For Linux:

go build
./casdoor

For Windows:

go build
casdoor.exe

Frontend

Build the 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 the 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.

Casdoor Port Details

In the dev environment, the frontend is run by yarn run on port 7001, so if you want to go to the Casdoor login page, you need to set the Casdoor link as http://localhost:7001.

In the prod environment, the frontend files are first built by yarn build and served on port 8000, so if you want to go to the Casdoor login page, you need to set the Casdoor link as https://your-casdoor-url.com:8000 (If you are using a 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 the dev environment, we set the serverUrl as http://localhost:7001, so when we test the signin and signup functionality using Casdoor, it will go to localhost 7001, which is the Casdoor port.

And when we put Casnode into the prod environment, we set the serverUrl as https://door.casdoor.com, so users can sign in or sign up using Casdoor.

Casnode Example