跳到主内容

服务器安装

安装要求

操作系统

支持所有操作系统(Linux, Windows 和 macOS)

环境

info

我们强烈建议您使用 Yarn 1。 运行 & Casdoor 前端,使用 NPM可能会导致UI 风格问题。 更多详细信息见: Casdoor#294

对于中文用户,我们强烈建议您更新您的 [proxy server](https://goproxy. cn/)。 :::

数据库

Casdoor使用 XORM 与数据库进行对接。 基于 Xorm 驱动程序支持, 当前支持的数据库包括:

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

下载

Casdoor的源代码托管在 GitHub: https://github.com/casdoor/casdoor 。 Go 后端代码和 React 前端代码都在单个仓库中。

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

Casdoor支持 Go Modules。 要下载代码,您直接通过git克隆仓库就可以了:

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

配置

通过 Ini 文件

可以通过单个文件配置Casdoor: conf/app.conf,其内容默认是:

appname = casdoor
httpport = 8000
runmode = dev
SessionOn = true
copyrequestbody = true
driverName = mysql
dataSourceName = root:123456@tcp(localhost:3306)/
dbName = casdoor
redisEndpoint =
defaultStorageProvider =
isCloudIntranet = false
authState = "casdoor"
socks5Proxy = "127.0.0.1:10808"
verificationCodeTimeout = 10
initScore = 2000
logPostOnly = true
origin = "https://door.casdoor.com"
  • appname 是应用程序名称,目前没有实际使用
  • httpport 是您后端应用程序正在监听的端口
  • runmodedevprod
  • SessionOn 控制是否启用会话,默认为使用。
  • driverName, dataSourceNamedbname 此前已启用,请参阅 配置
  • useProxy 设置代理端口,因为我们有谷歌相关的服务,这些服务将在某些地区受到网络限制
  • verificationCodeTimeout 设置验证码到期时间。 到期后,用户需要再次获取

尽管有很多可配置的字段,作为初学者, 您只需要修改两个项目: driverNamedatasSourceName 基于您使用的数据库。 此数据库将被Casdoor用于存储所有数据,包括用户、组织、应用程序等等。

  • defaultStorageProvider is the default file storage service name. If you need to use file storage services such as avatar upload, you need to set up a storage provider and apply it in your application. See storage for details.

  • isCloudIntranet is used to identify whether your provider endpoint is intranet endpoint.

  • authState is the authorization application name. This parameter will be checked when logging in.

  • socks5Proxy is the SOCKS proxy server IP address.

  • initScore is the initial score of each user. Each user has a score attribute. Score is used by Casnode. Score does not control anything in casdoor.

  • logPostOnly is used to identify whether only use post method to add a record.

  • origin is the origin backend domain name.

  • Setup database (MySQL):

    Casdoor will store its users, nodes and topics information in a MySQL database named: casdoor, will create it if not existed. The DB connection string can be specified at: https://github.com/casdoor/casdoor/blob/master/conf/app.conf

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

    Since we must choose a database when opening Postgres with xorm, you should prepare a database manually before running Casdoor.

    Let's assume that you have already prepared a database called casdoor, then you should specify app.conf like this:

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

Please notice:

  • Other database...

环境变量

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 someting 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.

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

运行

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

开发模式

后端

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.

前端

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

生产模式

后端

Build Casdoor Go backend code into executable and start it.

For Linux:

go build
./casdoor

For Windows:

go build
casdoor.exe

前端

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).

以我们的官方论坛 Casnode 作为示例:

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.

Casnode Example :::