创建容器
docker run -d --name centos-glm -v /dp/docker/file/glm:/usr/local/glm -p 820:22 -p 8501:8501 --privileged=true centos:7 /usr/sbin/initdocker run -d --name glm -v /dp/docker/file/glm:/usr/local/glm -p 822:22 -p 8501:8501 -p 7861:7861 -p7860:7860 --privileged=true centos:7 /usr/sbin/init

#映射一个目录到宿主机,后期要下载的文件比较大有60G左右,都下载到这个目录,删除容器时保留这些文件

#进入容器
docker exec -it -u root glm /bin/bash
#安装几个必要的工具
yum install -y gcc patch libffi-devel python-devel  zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel 
yum install -y zlib* 
yum install -y net-tools.x86_64
yum install -y openssh-server 
yum install -y git
yum install -y wget
yum install -y python-setuptools
#git大文件管理要用到lfs
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sh
yum install git-lfs
git lfs install

systemctl restart sshd
#修改密码用的
yum install passwd -y 

#修改密码
passwd root
输入两次密码
如果有需要的话就可以ssh连接了 ,注意防火墙

下载Langchain-Chatchat根据read.me说明部署
https://github.com/chatchat-space/Langchain-Chatchat.git
当前版本0.2.10 要求python版本3.8-3.11这里用3.11.7

python环境
conda方式 [centos 安装 Conda]安装过程中最好也指定安装目录到/usr/local/glm子目录中(下一步安装依赖时也会下载几个G的文件)
conda create -p /opt/langchain-chatchat/pyenv python=3.11.7
激活Python虚拟环境
conda activate /opt/langchain-chatchat/pyenv
关闭环境
conda deactivate
# 删除环境
conda env remove -p /opt/langchain-chatchat/pyenv


# 拉取仓库 
cd /usr/local/glm
$ git clone https://github.com/chatchat-space/Langchain-Chatchat.git

# 进入目录
$ cd Langchain-Chatchat

# 安装全部依赖

#这里要下载的文件很大需要镜像根据自己网络环境试一下哪个快用哪个【镜像源】一定找个快的,要不然一天也下载不完。
pip install -r requirements.txt -i http://pypi.mirrors.ustc.edu.cn/simple/ --trusted-host pypi.mirrors.ustc.edu.cn
pip install -r requirements_api.txt -i http://pypi.mirrors.ustc.edu.cn/simple/ --trusted-host pypi.mirrors.ustc.edu.cn
pip install -r requirements_webui.txt  -i http://pypi.mirrors.ustc.edu.cn/simple/ --trusted-host pypi.mirrors.ustc.edu.cn
因为要离线运行所以需要下载两个模型,注意都下载到开始映射的宿主机目录中去
chatglm3-6b和bge-large-zh 
huggingface.co这个网址不科学的连不上,所以也找个镜像

先安装【git-lfs】不安装的后果是大文件下载不下来,只下载一个连接文件
cd /usr/local/glm
git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git #最大的就是这个了 差不多50G
git clone https://www.modelscope.cn/Xorbits/bge-large-zh-v1.5.git

cd Langchain-Chatchat
python copy_config_example.py

修改配置文件
Langchain-Chatchat/configs/model_config.py
主要修改这一部分,对应刚才下载的目录
LLM_MODELS = ["chatglm3-6b"]
MODEL_PATH = {
    "embed_model": {
        "bge-large-zh": "/usr/local/glm/bge-large-zh-v1.5"
    },

    "llm_model": {
        "chatglm3-6b": "/usr/local/glm/chatglm3-6b"

    },

如果没有显卡修改server_config.py

"chatglm3-6b": {
        "device": "cpu",
    },

# 初始化知识库向量
python init_database.py --recreate-vs

启动服务
python startup.py -a

如果成功启动就可以通过8501端口访问页面了

没有GPU的情况下运行应该很慢可以用OpenVINO 转换一下,优化模型,提高推理性能,减少模型的内存占用
git clone https://github.com/OpenVINO-dev-contest/chatglm3.openvino.git
cd chatglm3.openvino
python3 -m venv openvino_env
source openvino_env/bin/activate
python3 -m pip install --upgrade pip
pip install wheel setuptools
pip install -r requirements.txt -i http://pypi.mirrors.ustc.edu.cn/simple/ --trusted-host pypi.mirrors.ustc.edu.cn

转换模型
python3 convert.py --model_id  原目录/chatglm3-6b --output 输出目录/chatglm3-6b-vo
转换完了再修改

   "llm_model": {
        "chatglm3-6b": "/usr/local/glm/chatglm3-6b-vo"
    },
重新启动

参考文档:https://zhipu-ai.feishu.cn/wiki/YInmwPmyii67VRkzU3BchPNzncg