llama.cpp + llama-server 安装部署验证
推荐使用 Ubuntu 22.04 LTS,自带较新的 GCC、CMake 和 Python,部署过程顺畅。
一、安装系统依赖
sudo apt update
sudo apt install -y git build-essential cmake libssl-dev
二、克隆并编译 llama.cpp
1. 克隆仓库
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
2. 使用 CMake 构建 server
mkdir build && cd build
sudo apt install -y ninja-build
cmake .. -DCMAKE_BUILD_TYPE=Release -DLLAMA_BUILD_SERVER=ON
make -j $(nproc) llama-server
三、准备 GGUF 模型
下载量化模型(以 Llama-3-8B-Instruct Q6_K 为例)。
pip install --upgrade pip
pip install modelscope
modelscope download --model QuantFactory/Llama-3-8B-Instruct-Coder-GGUF Llama-3-8B-Instruct-Coder.Q6_K.gguf --local_dir ./models
modelscope download --model ngxson/Qwen2.5-7B-Instruct-1M-Q4_K_M-GGUF qwen2.5-7b-instruct-1m-q4_k_m.gguf --local_dir ./models
四、启动服务
./build/bin/llama-server -m ./models/Llama-3-8B-Instruct-Coder.Q6_K.gguf --port 8080 --host 0.0.0.0 --ctx-size 8192 --threads 8
后台启动示例
nohup ./build/bin/llama-server -m ./models/Llama-3-8B-Instruct-Coder.Q6_K.gguf --port 8080 --host 0.0.0.0 --ctx-size 8192 --threads 8 > llama-server.log 2>&1 &
五、验证与服务测试
1. 健康检查
curl http://localhost:8080/health
2. 查看日志
tail -f llama-server.log
3. 停止服务
pkill -f llama-server
4. 接口调用示例
Completion API

