llama.cpp + llama-server 的安装部署验证
环境准备
使用 Ubuntu 22.04.5 LTS (Jammy Jellyfish) —— 这是一个长期支持(LTS)且完全受支持的现代 Linux 发行版,非常适合部署 llama.cpp + llama-server。Ubuntu 22.04 自带较新的 GCC、CMake 和 Python,无需手动升级工具链。
1. 检查系统版本
cat /etc/os-release
显示为 Ubuntu 22.04.5 LTS。
一、安装系统依赖
sudo apt update
sudo apt install -y git build-essential cmake libssl-dev ninja-build
二、克隆并编译 llama.cpp
1. 克隆仓库
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
2. 构建 server
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DLLAMA_BUILD_SERVER=ON
make -j $(nproc) llama-server
三、准备 GGUF 模型
1. 下载量化模型
从模型仓库下载所需的 GGUF 格式模型文件(例如 Llama-3-8B-Instruct 或 Qwen2.5-7B-Instruct),并保存至本地目录。
四、启动服务
1. 前台启动测试
./build/bin/llama-server -m ./models/Llama-3-8B-Instruct-Coder.Q6_K.gguf --port 8080 --host 0.0.0.0 --ctx-size 2048 --threads 8
2. 后台启动
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

