【个人笔记】rancher远程调试搭建

rancher远程调试搭建

文章目录

  • rancher远程调试搭建
    • 配置主机(关防火墙,关SELinux)
    • 安装docker
    • 安装go环境
      • 下载go
      • 配置环境变量
      • 安装dlv
    • 拉代码
    • 配置goland
      • 远程代码
      • 远程调试
    • 运行
    • docker运行
    • rancher-ui
      • 安装nodejs
      • 安装 yarn
      • 拉代码
      • 启动
      • 访问
    • dockerfile

说句闲话:这本是一篇笔记,本来没想发出来,但是突然有道云这个坑货,将另一篇笔记的内容完全覆盖了这一篇。这种情况以前也出现过,一般重开一次就好了,然而这次却不好使,开chrome隐私模式登录看到也是被覆盖的,当时我就慌了……好在哥们急中生智,将手机断网打开有道云笔记,看到了熟悉的内容,于是全部复制出来才得以保全此文。后面计划陆续把笔记同步过来以防万一,就是给隐私打码也挺麻烦的……

配置主机(关防火墙,关SELinux)

systemctl stop iptables
systemctl stop firewalld
vi /etc/selinux/config

SELINUX=disabled

安装docker

sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce
echo '{"insecure-registries":["harbor.t2cp.com"]}' >> /etc/docker/daemon.json
service docker start

安装go环境

下载go

curl -o go1.13.linux-amd64.tar.gz https://dl.google.com/go/go1.13.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.13.linux-amd64.tar.gz

配置环境变量

创建工作目录

mkdir -p ~/go/src ~/go/pkg ~/go/bin

编辑/etc/profile添加如下

# golang
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:~/go/bin
echo "# golang" >> /etc/environment
echo "PATH=$PATH:/usr/local/go/bin" >> /etc/environment
echo "PATH=$PATH:~/go/bin" >> /etc/environment
source /etc/profile

安装dlv

go env -w GOPROXY="https://goproxy.cn,direct"
go get github.com/go-delve/delve
cd ~/go/src/github.com/go-delve/delve/cmd/dlv/
go install

拉代码

yum install -y git
mkdir -p ~/go/src/github.com/rancher
cd ~/go/src/github.com/rancher
git clone ...
git checkout ...

配置goland

远程代码

Tools->Deployment->Configuration
+SFTP后输入名称(随意),然后Host为IP,然后是登录信息(用户名密码)
然后RootPath是远程代码的绝对路径
Mappings中的DeploymentPath填/

远程调试

ctrl+shift+a->edit configurations
+go remote后填入名称(随意)和远程IP

运行

到主机上执行

cd ~/go/src/github.com/rancher/rancher/
dlv debug --build-flags "-tags "k8s"" --headless --listen=:2345 --api-version=2 --accept-multiclient
dlv debug --build-flags "-tags "k8s"" --headless --listen=:2345 --api-version=2 --accept-multiclient -- --http-listen-port=8080 --https-listen-port=8443 --audit-log-path=${AUDIT_LOG_PATH} --audit-level=${AUDIT_LEVEL} --audit-log-maxage=${AUDIT_LOG_MAXAGE} --audit-log-maxbackup=${AUDIT_LOG_MAXBACKUP} --audit-log-maxsize=${AUDIT_LOG_MAXSIZE} "${@}"

等输出API server listening at: [::]:2345后到goland上shift+F9
此时主机上会有log输出,一段时间后搜一下8443如果看到[INFO] Listening on :8443就可以postman访问了

docker运行

echo '*** ***' >> /etc/hosts
docker run -itd --privileged --entrypoint '/bin/bash' -p 8080:8080 -p 8443:8443 -p 30080:80 -p 30443:443 -p 2345:2345 -p 8022:22 ***/library/rancher/rancher:v2.2.2m114-dev

容器中

# 只启动rancher-server
/usr/bin/rancher

# 启动rancher前后端
/usr/bin/rancher --http-listen-port=8080 --https-listen-port=8443 --audit-log-path=${AUDIT_LOG_PATH} --audit-level=${AUDIT_LEVEL} --audit-log-maxage=${AUDIT_LOG_MAXAGE} --audit-log-maxbackup=${AUDIT_LOG_MAXBACKUP} --audit-log-maxsize=${AUDIT_LOG_MAXSIZE} "${@}"

# apt update
apt update

# ssh
apt install --fix-missing -y openssh-server
echo "PermitRootLogin yes" >>  /etc/ssh/sshd_config
/bin/echo 'root:***' |chpasswd
service ssh restart

# gcc
apt install --fix-missing -y gcc

rancher-ui

https://github.com/rancher/ui

安装nodejs

curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
sudo yum install -y nodejs

安装 yarn

curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
sudo yum -y install yarn

拉代码

mkdir ~/rancher-ui
git clone 'https://github.com/rancher/ui'
cd 'ui'
./scripts/update-dependencies

启动

RANCHER="https://localhost:8443" yarn start

访问

https://localhost:8000/

dockerfile

FROM ***/library/rancher/rancher:***

# install ssh & gcc
RUN apt update && \
    apt install --fix-missing -y openssh-server && \
    echo "PermitRootLogin yes" >> /etc/ssh/sshd_config && \
    /bin/echo 'root:***' |chpasswd && \
    service ssh restart && \
    apt install --fix-missing -y gcc

ENV PATH=/go/bin:/usr/local/go/bin:${PATH}

# install go & dlv
RUN curl -o go1.13.linux-amd64.tar.gz https://dl.google.com/go/go1.13.linux-amd64.tar.gz && \
    tar -C /usr/local -xzf go1.13.linux-amd64.tar.gz && \
    rm -f go1.13.linux-amd64.tar.gz && \
    mkdir -p /go/src /go/pkg /go/bin && \
    go env -w GOPROXY="https://goproxy.cn,direct" && \
    go env -w GOPATH="/go" && \
    go get -u github.com/go-delve/delve/cmd/dlv && \
    go install /go/src/github.com/go-delve/delve/cmd/dlv/ && \
    mkdir -p /go/src/github.com/rancher

WORKDIR /go/src/github.com/rancher

ENTRYPOINT ["/bin/bash"]

docker run --name tmp4 -itd --privileged --entrypoint '/bin/bash' -p 8080:8080 -p 8443:8443 -p 30080:80 -p 30443:443 -p 2345:2345 -p 8022:22 harbor.t2cp.com/library/rancher/rancher-env-for-develop:1.1

你可能感兴趣的:(容器云)