安装环境

基础环境

系统版本:centos7.9
docker版本:
Docker Compose

安装Docker

修改源

sudo cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
sudo yum clean all
vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

一键安装docker脚本

vim install_docker.sh
#!/bin/bash

read -p "安装(y/n):" judge_1

if [ $judge_1 = "y" ]; then
    yum -y install yum-utils
    if [ $? != 0 ]; then
        echo "安装命令失败"
    else
        sudo yum install -y yum-utils
        if [ $? != 0 ]; then
            echo "安装工具包失败1.1"
        else
            sudo yum-config-manager --add-repo https://download.docker.com+https://mirrors.tuna.tsinghua.edu.cn/docker-ce+
            if [ $? != 0 ]; then
                echo "设置远程仓库失败1.2"
            else
                sudo yum install docker-ce
                if [ $? != 0 ]; then
                    echo "安装失败1.3"
                else
                    echo "安装完成"
                fi
            fi
        fi
    fi
else
    echo "退出"
    exit
fi

修改docker镜像源

sudo tee /etc/yum.repos.d/docker-ce.repo <<-'EOF'
[docker-ce-stable]
name=Docker CE Stable - \$basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
EOF

安装并启动

sh install_docker.sh
systemctl start docker

安装docker-compose

如果大陆无法安装,在github上下载下来传上去

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

安装go

wget https://go.dev/dl/go1.23.1.linux-amd64.tar.gz
tar -C /usr/local/ -xzf go1.23.1.linux-amd64.tar.gz
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bash_profile
source ~/.bash_profile

克隆代码

git clone https://github.com/casbin/casdoor.git
git clone https://github.com/casbin/casnode.git

现在,您可以看到两个文件夹,casnodecasdoor

安装casdoor

运行casdoor

cd casdoor
vim conf/app.conf
# 修改dataSourceName = root:123@tcp(localhost:3306)/
# 为 dataSourceName = root:123@tcp(db:3306)/

启动容器

docker-compose up

如果启动失败,改一下Docker国内镜像源

vim /etc/docker/daemon.json
# 添加国内镜像源
{
  "registry-mirrors": [
    "https://hub.atomgit.com",
    "https://docker.m.daocloud.io",
    "https://huecker.io",
    "https://dockerhub.timeweb.cloud",
    "https://noohub.ru"
  ]
}

修改Dockerfile文件的镜像源


vim Dockerfile
# 把这句加在执行yarn命令之前
RUN yarn config set registry https://registry.npm.taobao.org

再次尝试启动

docker-compose build
docker-compose up

配置casdoor

现在Casdoor已经配置完毕,访问http://your-ip:8000来配置Casnode。
默认的管理员登录账户是admin/123。
点击用户管理--组织,然后点击添加,对添加的组织点击Edit,将名称修改为你想要的组织名,这里我设置为casnode,然后点击Save。
file
点击顶栏中的“身份认证”,然后点击添加,
记住应用程序名称,这里我使用 forum 作为我的应用程序名称:
file
选择刚刚创建的组织作为申请组织
file
将重定向 URL 修改为论坛 URL 为http://yourip:7000/callback
file
单击保存,并记住Client ID和Client Secret
file

点击Users,点击Add,然后点击Edit,修改添加的用户,点击Organization,选择casnode,点击is admin。最后点击Save,现在你的组织就有管理员账号了。

安装casnode

注意:CasdoorCasnode启动时都会创建一个 MySQL 容器。如果它们在同一台服务器上,后启动的容器会因为端口冲突而无法启动。

cd casnode
vim conf/app.conf
# 修改dataSourceName = root:123@tcp(localhost:3306)/ 为dataSourceName = root:123@tcp(db:3306)/
# 找到casdoorEndpoint,将其修改为http://your-ip:8000(Casdoor后端地址)
# 找到clientId和clientSecret,并将其修改为之前记住的Application client id和client secret
# 找到casdoorOrganization,将组织名称修改为你设置的。
vim web/src/Conf.js
# 修改serverUrl为http://your-ip:8000 (Casdoor前端访问地址)
# 修改clientId为刚刚添加的应用的clientId
# 修改appName为设置的应用名称
# 修改organizationName为设置的组织名称。

运行 casnode

docker-compose up

如果启动时报错node版本不对,可以修改Dockerfile,指定node版本

vim Dockerfile
# 修改Dockerfile,修改node的版本
FROM node:16.14.2 AS FRONT
# 修改mysql容器端口为3307
CMD ./wait-for-it db:3307 -- ./server

docker-compose build
docker-compose up
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。