先建立容器
1.构建容器
查看镜像:
sudo docker images
查看端口是否占用
sudo lsof -i :16535
创建容器:
sudo docker run -itd --gpus all -p 16535:22 -p 11435:11434 --name ollamaplus -v /workplace/ollamaplus:/workspace -v /a_Pretrain_models:/models -e CUDA_DEVICE_ORDER=PCI_BUS_ID pytorch/pytorch:1.10.0-cuda11.3-cudnn8-devel
查看容器:
sudo docker ps
复制新创建的容器的id替换-it后边的编码,进入容器:
sudo docker exec -it ollamaplus /bin/bash
退出容器:
#-----直接退出
#---未添加 -d(持久化运行容器) 时 执行此参数 容器会被关闭
exit
#-----优雅退出
#--- 无论是否添加-d 参数 执行此命令容器都不会被关闭
Ctrl + p + q
2.容器内部安装ssh
更新apt-get
源
apt-get update
安装ssh,-y
参数表示如果碰到询问yes or no
则默认输入yes
而省略询问。
apt-get install -y openssh-server
安装vim:vim的安装与配置_安装vim-CSDN博客
apt-get install -y vim
使用vim打开ssh配置文件
vim /etc/ssh/sshd_config
在配置文件sshd_config
中加上两行
PermitRootLogin yes
PasswordAuthentication yes
重启ssh
service ssh restart
修改密码:
passwd
3.容器内部安装conda
在官网下载miniconda安装包:https://docs.conda.io/en/latest/miniconda.html
通过finalshell等工具传到服务器之后即可安装。
根据之前的操作,该文件已经存在于docker容器内部的文件夹/workspace
下。
运行:
chmod +x /workspace/Miniconda3-latest-Linux-x86_64.sh
/workspace/Miniconda3-latest-Linux-x86_64.sh
出现Welcome to Minxxxxx代表没问题,然后一直回车,可能会遇到More,依然一直回车,不用担心错过什么
直到遇到 Please answer 'yes' or 'no':'选择yes
接着回车,注意不要连点回车。到询问:
installation finished.
Do you wish to update your shell profile to automatically initialize conda?
This will activate conda on startup and change the command prompt when activated.
If you'd prefer that conda's base environment not be activated on startup,
run the following command when conda is activated:
conda config --set auto_activate_base false
You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] >>> yes
输入yes
.
安装完毕,执行命令,刷新环境变量:
source ~/.bashrc
刷新环境变量成功(此处如果失败,重启shell后成功)
使用命令退出base环境:conda deactivate
关闭自动进入base环境:conda config --set auto_activate_base false
4.安装ollama
安装crul
apt-get install curl -y
ollama/docs/linux.md at main · ollama/ollama
curl -fsSL https://ollama.com/install.sh | sh
更新命令:
curl -fsSL https://ollama.com/install.sh | sh
启动 Ollama
使用以下方式启动 Ollama systemd
:
systemctl start ollama
由于在容器中使用,会报错:
(base) root@:/workspace# systemctl start ollama
System has not been booted with systemd as init system (PID 1). Can't operate.
在Docker容器中,由于通常不会运行完整的 systemd
服务,因此无法使用 systemctl
命令来管理服务。
使用 supervisord启动ollama
如果你需要在Docker容器中管理多个服务或进程,可以使用 supervisord
。supervisord
是一个进程管理工具,可以用来启动和管理多个进程。
安装 supervisor:
apt-get update
apt-get install -y supervisor
配置 supervisord:
创建一个 supervisord
配置文件 /etc/supervisor/conf.d/ollama.conf
:
vim /etc/supervisor/conf.d/ollama.conf
[program:ollama]
command=ollama serve
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/ollama_stdout.log
stderr_logfile=/var/log/supervisor/ollama_stderr.log
这里,/path/to/ollama
需要替换为实际的 ollama
服务的启动命令。
启动 supervisord:
supervisord -c /etc/supervisor/supervisord.conf
supervisorctl shutdown
4.使用 supervisorctl****查看服务状态:
supervisorctl status
5.查看日志文件:
使用 cat
、less
、tail
等命令查看日志文件内容。例如:
tail -n 40 /var/log/supervisor/ollama_stdout.log
tail -n 40 -f /var/log/supervisor/ollama_stdout.log
或者查看标准错误日志:
tail -n 40 -f /var/log/supervisor/ollama_stderr.log
查看日志文件的最后40行,可以使用 tail
命令与 -n
选项指定行数。 如果想持续查看日志文件并同时看到新添加的日志行,可以使用 -f
选项
5.通过魔塔社区下载模型
pip install modelscope
安装需求的包
pip install packaging
pip install importlib-metadata
下载模型:
modelscope download --model llm-research/meta-llama-3.1-8b-instruct-gguf --local_dir /models/Meta-Llama-3.1-8B-Instruct-GGUF
单个.gguf
文件包含了独立的模型参数,只是它们的量化程度不同。量化程度决定了模型在计算效率和内存占用上的表现,低精度的量化模型(如Q3、Q4)通常更小更快,但可能会牺牲一些精度,而高精度的量化模型(如Q6、Q8)则更大更慢,但能保持更多的原始模型性能。因此,可以根据具体需求选择合适的量化版本。
modelscope download --model llm-research/meta-llama-3.1-8b-instruct-gguf --local_dir /models/Meta-Llama-3.1-8B-Instruct-GGUF
modelscope download --model 'rubraAI/Meta-Llama-3-70B-Instruct-GGUF' rubra-meta-llama-3-70b-instruct_Q8_0-00001-of-00003.gguf rubra-meta-llama-3-70b-instruct_Q8_0-00002-of-00003.gguf rubra-meta-llama-3-70b-instruct_Q8_0-00003-of-00003.gguf --local_dir /models/Meta-Llama-3-70B-Instruct-GGUF
6.加载模型
下完后创建model文件
/workspace/modelFile
vim Meta-Llama-3.1-8B-Instruct-GGUF-Q8.mf
FROM /models/Meta-Llama-3.1-8B-Instruct-GGUF/Meta-Llama-3.1-8B-Instruct-Q8_0.gguf
TEMPLATE """{{ if .System }}<|im_start|>system
{{ .System }}<|im_end|>{{ end }}<|im_start|>user
{{ .Prompt }}<|im_end|>
<|im_start|>assistant
"""
PARAMETER stop "<|im_start|>"
PARAMETER stop "<|im_end|>"
加载:
ollama create Meta-Llama-3.1-8B-Instruct-GGUF-Q8 -f Meta-Llama-3.1-8B-Instruct-GGUF-Q8.mf
7.运行模型
ollama run Meta-Llama-3.1-8B-Instruct-GGUF-Q8:latest --verbose
ollama pull nomic-embed-text