Ubuntu下部署图片查重的项目

1、安装mysql

sudo apt install mysql-server

2、进行安全配置

sudo mysql_secure_installation

3、查看mysql状态

sudo systemctl status mysql

4、设置root密码(root密码要与01,02两个创建数据库表脚本中的一致)

sudo mysql

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_new_password';

FLUSH PRIVILEGES;

EXIT;

5、使用root新密码登陆

mysql -u root -p

6、安装uv虚拟环境

sudo apt install nodejs npm -y


uv --version

检查uv的版本信息


7、拉取项目文件

git clone https://github.com/zhangfanxp/cc.git && cd cc

8、创建并激活虚拟环境

uv venv && source .venv/bin/activate

9、安装依赖库

uv pip install -r requirements.txt

10、执行脚本创建数据库表

python 01_setup_database.py

python 02_populate_data.py

11、运行webui的启动服务程序

python image_deduplicator.py

12、上传zip压缩包,查重

-------------------------------------------------

设置Ubuntu系统开机后自动启动服务:


a、创建自启动文件(image-deduplicator.service)

vi ~/image-deduplicator.service

b、写入下面的代码(根据ubuntu实际用户名修改下面三处绿色代码)

[Unit]
Description=Image Deduplicator Service
After=network.target

[Service]
# 使用您的实际用户名
User=your_username
# 脚本的实际工作目录
WorkingDirectory=/home/your_username/env/cc
# 运行的命令
# 注意:这里直接使用虚拟环境的完整路径来运行 python,避免使用 source
ExecStart=/home/your_username/env/cc/.venv/bin/python image_deduplicator.py
# 重启策略,如果脚本退出,系统会尝试重启它
Restart=on-failure

[Install]
WantedBy=multi-user.target

c、保存并退出

:wq

d、把文件移入系统目录并重新加载systemd配置

sudo mv ~/image-deduplicator.service /etc/systemd/system/

sudo systemctl daemon-reload

e、设置为开机后自启动服务

sudo systemctl enable image-deduplicator.service

---------------------------------------------

固定IP地址,建议在路由器中设置,本地设置容易产生IP冲突!

---------------------------------------------

Ubuntu系统

禁用开机自启动:

sudo systemctl disable image-deduplicator.service

查看自启动服务状态:

systemctl is-enabled image-deduplicator.service

仅当前启动的停止,不影响未来开始自启动:

sudo systemctl stop image-deduplicator.service

*******************************

Mac系统

1、使用vi生成(start_image_deduplicator.sh)

#!/bin/bash
cd /Users/yourusername/env/cc
/Users/yourusername/env/cc/.venv/bin/python /Users/yourusername/env/cc/image_deduplicator.py

----------------

给脚本文件赋权限:

chmod +x /Users/yourusername/env/cc/start_image_deduplicator.sh


2、创建LaunchDaemon配置文件:

sudo vi /Library/LaunchDaemons/com.frank.imagededup.plist

写入下面的内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.frank.imagededup</string>

    <key>ProgramArguments</key>
    <array>
        <string>/Users/yourusername/env/cc/start_image_deduplicator.sh</string>
    </array>

    <key>RunAtLoad</key>
    <true/>

    <key>KeepAlive</key>
    <true/>

    <key>StandardOutPath</key>
    <string>/Users/yourusername/env/cc/log.txt</string>
    <key>StandardErrorPath</key>
    <string>/Users/yourusername/env/cc/error.txt</string>
</dict>
</plist>

3、设置加载LaunchDaemon:

sudo launchctl load /Library/LaunchDaemons/com.frank.imagededup.plist

sudo launchctl start com.frank.imagededup

4、设置mysql开机自动启动:

brew services start mysql

查看启动状态:

brew services list

=============================

取消开机自启动:

sudo launchctl stop com.frank.imagededup
sudo launchctl unload /Library/LaunchDaemons/com.frank.imagededup.plist

(可选)
sudo rm /Library/LaunchDaemons/com.frank.imagededup.plist









评论

此博客中的热门博文

通过命令行在Github上发布项目的新版本

利用GitHub免费的静态页面托管空间发布网页

本地部署OpenAvatarChat实时交互数字人系统