llama.cpp + llama-server 的安装部署验证
用的是 魔塔的免费资源 不太稳定
cat /etc/os-release

Ubuntu 22.04.5 LTS (Jammy Jellyfish) —— 这是一个长期支持(LTS)且完全受支持的现代 Linux 发行版,非常适合部署 llama.cpp + llama-server。Ubuntu 22.04 自带较新的 GCC(11+)、CMake(3.22+)和 Python 3.10+,无需手动升级工具链,部署过程非常顺畅。
一、安装系统依赖
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

步骤 3:使用 CMake 构建 server
mkdir build
sudo apt install -y ninja-build

cd build
cmake .. -G Ninja

ninja server 报错了

rm -rf build
重新来
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DLLAMA_BUILD_SERVER=ON

make -j $(nproc) llama-server



三、准备 GGUF 模型
下载量化模型(以 Llama-3-8B-Instruct Q4_K_M 为例)
cd /mnt/data/
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 /mnt/data
modelscope download --model ngxson/Qwen2.5-7B-Instruct-1M-Q4_K_M-GGUF qwen2.5-7b-instruct-1m-q4_k_m.gguf --local_dir /mnt/data

Qwen2.5-7B-Instruct-1M-Q4_K_M-GGUF · 模型库
Llama-3-8B-Instruct-Coder-GGUF · 模型库


# 启动
/mnt/workspace/llama.cpp/build/bin/llama-server -m /mnt/data/Llama-3-8B-Instruct-Coder.Q6_K.gguf --port 8080 --host 0.0.0.0 --ctx-size 2048 --threads 8


# 1. 后台启动
nohup /mnt/workspace/llama.cpp/build/bin/llama-server -m /mnt/data/Llama-3-8B-Instruct-Coder.Q6_K.gguf --port 8080 --host 0.0.0.0 --ctx-size 8192 --threads 8 > /mnt/workspace/llama-server.log 2>&1 &
nohup /mnt/workspace/llama.cpp/build/bin/llama-server -m /mnt/data/qwen2.5-7b-instruct-1m-q4_k_m.gguf --port 8080 --host 0.0.0.0 --ctx-size 8192 --threads 8 > /mnt/workspace/llama-server.log 2>&1 &

# 2. 验证
curl http://localhost:8080/health

# 3. 查日志
tail -f /mnt/workspace/llama-server.log
# 4. 停止
pkill -f llama-server
curl http://localhost:8080/completion \ -H "Content-Type: application/json" \ -d '{ "prompt": "<|start_header_id|>user<|end_header_id|>\n\n你好,请写一首关于春天的诗。<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n", "n_predict": 150, "stop": ["<|eot_id|>"] }'
curl http://localhost:8080/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "messages": [{"role": "user", "content": "你好!"}], "temperature": 0.7, "max_tokens": 50 }'