Super detailed GitBook and GitLab integration steps [linux environment]

introduce

This article mainly integrates gitbook on gitlab to realize automatic refresh deployment of gitbook when submitting, and builds gitlab gitbook on linux environment, integrates GitLab CI to realize an enterprise-level or personal Wiki system

Environmental preparation

1. A linux server
2. Install node and npm environment (note here that the node environment should not be too high or there will be an error when installing gitbook Recommended: v12.16.3)

Linux installation Node tutorial

Create a node folder in the root directory

    mkdir  node
    cd node

download unzip

wget https://nodejs.org/dist/v12.16.3/node-v12.16.3-linux-x64.tar.xz
tar xf node-v12.16.3-linux-x64.tar.xz

You can view the files in the current directory by executing:ls (命令)

After successful decompression, you can choose to delete the compressed package:

rm -rf node-v14.17.4-linux-x64.tar.xz

Among them: -f will remind you whether to delete; -rf will force delete without reminding. (use rf because some people don't know how to manipulate dialogue lines waiting for carriage return)

Create a directory

mkdir /usr/local/lib/node

If the directory already exists, there is no need to create it, or you can set the directory name according to your preferences

Move directory and rename

mv node-v12.16.3-linux-x64 /usr/local/lib/node/nodejs

Set environment variables (Note: This step requires administrator privileges or write permissions to the file.)
Execute:

sudo vim /etc/profile

Enter i to edit the file.
Add environment variables at the bottom of the file:

export NODEJS_HOME=/usr/local/lib/node/nodejs
export PATH=$NODEJS_HOME/bin:$PATH

Execute the command (the command in the list below is save and exit):

Click esc
to enter a colon:
enter wq
and press Enter
to save and exit.

refresh modification

source /etc/profile

The installation is complete, check the version number
node version number:

node -v

npm version number:

npm -v

Install Git

Install git on your machine with the following command:

## 通过下列命令安装git
yum install git
## 查看当前git版本
git --version

If you don’t have the yum command in your linux environment, see the following steps to install. If you have the yum command, you can ignore it.
Download the yum installation package and unzip it

wget http://yum.baseurl.org/download/3.2/yum-3.2.28.tar.gz
tar xvf yum-3.2.28.tar.gz

Enter the yum-3.2.28 folder to install and execute the installation instructions

cd yum-3.2.28
sudo apt install yum

update to new version

yum check-update
yum update
yum clean all

Install GitLab

1. Download the rpm package of gitlab
Address: https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-9.5.9-ce.0.el7.x86_64.rpm
2. Put the downloaded package into the linux environment
3. Execute the installation

## 安装rpm包
rpm -ivh gitlab-ce-9.5.9-ce.0.el7.x86_64.rpm

4. Modify the access URL (this step is to modify the address of your access to gitlab example: http://192.168.0.1:20001)

vim /etc/gitlab/gitlab.rb
## 修改以下内容并保存
external_url "http://192.168.0.1:20001"

5. Reinstall configuration

## 依次执行下面命令 
gitlab-ctl reconfigure
gitlab-ctl restart

6. Solve some errors after installing gitlab
When we execute the above code and enter the website in the browser (for example: http://192.168.0.1:20001), we should be able to enter gitlab,
but there is another situation that the port is not Open it so it can’t be accessed (for example, my port is 20001 but my server doesn’t open this port so I can’t access it) The
solution is as follows:

开端口命令:firewall-cmd --zone=public --add-port=20001/tcp --permanent

Install GitBook

Install it with the following command:

npm install gitbook-cli -g

Install GitLab Runner

Download GitLab Runner

Use the uname --m command to view the number of bits in the Linux system, and then download the corresponding installation package

# x86-64
sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
# x86
sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-386
# arm
sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-arm

file placement

The file has been placed in /usr/local/bin/gitlab-runner, and the corresponding permissions need to be configured

chmod +x /usr/local/bin/gitlab-runner

Install GitLab Runner

## 安装
gitlab-runner install --user=root --working-directory=/software/gitlab-runner
## 启动
gitlab-runner start

Get through GitLab and GitBook

Create a project in gitlab

As shown below:

insert image description here

Register GitLab Runner

## 注册
gitlab-runner register
然后依次输入以下参数:
## 1. GitLab的url,参考下图 
## 2. Token,参考下图
## 3. 描述,随便写一个(例如:my-runner)
## 4. 填写Gitlab Runner的tag (注意这里的tag后面会用到 例如:my-tag,another-tag)
## 5. 选择Runner的执行器,意思是执行方式,这里用shell即可

insert image description here

After the configuration is complete, you can see that the Runner has been registered in GitLab, as shown below:

insert image description here

Local gitbook project configuration CI

Add a new .gitlab-ci.yml file to the project, the content is as follows:

stages:
  - build
xx-wiki:
    #下面这里是项目的tag   根据上面注册GitLab Runner第4步设置的tags填写
  tags:   
    - my-runner
  stage: build
  script:
    - p=`pwd`
    - echo $p
    - gitbook install
    - gitbook build
    - setsid nohup sh startup.sh > nohup.out 2>&1 &

Add a startup.sh file to the project with the following content:

#!/bin/bash
for i in `ps -ef | grep gitbook | grep serve`; do kill -9 $i ; done;
gitbook serve

After submitting the local gitbook project to GitLab, check the task execution status through the Pipelines menu:
insert image description here

check

Modify the gitbook content, and then push it to GitLab, you can see that the tasks on GitLab are executed, as shown in the figure above. Note that if it is displayed as padiing, there may be a problem with the project configuration or the tags are wrong

Finally visit http://IP:4000, you can see that the corresponding project has been updated, which proves that the WiKi has been built and can be updated in real time

insert image description here

Guess you like

Origin blog.csdn.net/weixin_49014702/article/details/128968537