pychram 打开项目 本地尝试
添加python 解释器
先安装几个包
pip install Django pymysql markdown geoip2
|
新建数据库 students
settings.py中添加好连接信息
迁移一下数据
添加django服务器
尝试启动
成功访问
导出 requirements.txt
pip freeze > requirements.txt
|
docker
剩下的操作全部都是在龙芯操作平台下完成的
更改docker源
mkdir -p /etc/docker tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://cr.loongnix.cn"] } EOF cat /etc/docker/daemon.json systemctl daemon-reload systemctl restart docker
|
寻找镜像
docker pull cr.loongnix.cn/loongson/loongnix-server:8.4.0
|
docker run -d -p 80:80 -p 3306:3306 --privileged=true cr.loongnix.cn/loongson/loongnix-server:8.4.0 /usr/sbin/init docker ps
|
docker exec -it eb41e243e894 bash
|
容器的架构也是基于主机的架构的
mysql8.0.21
以下的操作都是在容器的内部进行的
其中所使用的yum源全部基于 Loongnix 的仓库
yum update -y && yum -y upgrade yum search mysql
|
yum install -y mysql-server.loongarch64 mysql.loongarch64 mysql-devel.loongarch64 vim
|
systemctl start mysqld systemctl status mysqld
|
创建students表
mysql -uroot -Be "CREATE DATABASE students;"
|
更改root密码
mysql -uroot -Be "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '1qaz@WSX';"
|
添加管理人员信息表
mysql -uroot -Be "INSERT INTO students.student (stu_id, username, password) VALUES (1, 'lwh', '123456');"
|
python3.8
yum install -y python38.loongarch64 python38-devel.loongarch64 gcc.loongarch64 make zlib.loongarch64 zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel libpcap-devel xz-devel zlib zlib-devel openssl openssl-devel libffi-devel vim
|
loogson部署
上传项目
docker cp ~/pythonProject2.tar.gz eb41e243e894:/tmp
|
cd /tmp tar -zxvf pythonProject2.tar.gz
|
mkdir /www mv pythonProject2 /www/ ls /www/pythonProject2/
|
cd /www/pythonProject2/ pip3 install -r requirements.txt -i https://pypi.loongnix.cn/loongson/pypi
|
修改setting中数据库连接密码
关闭debug
迁移一下数据库
python3 manage.py migrate
|
创建admin
python3 manage.py createsuperuser
|
尝试启动
python3 manage.py runserver
|
uwsgi
安装uwsgi驱动
pip3 install uwsgi -i https://pypi.loongnix.cn/loongson/pypi
|
添加 uwsgi.ini 配置文件
cd /www/pythonProject2/ vim uwsgi.ini
|
#添加配置选择 [uwsgi] #配置和nginx连接的socket连接 socket=127.0.0.1:8997 #配置项目路径,项目的所在目录 chdir=/www/pythonProject2/ #配置wsgi接口模块文件路径,也就是wsgi.py这个文件所在的目录 wsgi-file=text1/wsgi.py #配置启动的进程数 processes=4 #配置每个进程的线程数 threads=2 #配置启动管理主进程 master=True #配置存放主进程的进程号文件 pidfile=uwsgi.pid #配置dump日志记录 daemonize=uwsgi.log
|
uwsgi --ini /www/pythonProject2/uwsgi.ini
|
nginx
安装nginx
nginx netstat -antp curl http://127.0.0.1
|
查看nginx 的配置文件位置
修改配置文件
vim /etc/nginx/nginx.conf
|
原先
改后
server { listen 80; server_name localhost; charset utf-8; client_max_body_size 75M;
location /static { alias /www/pythonProject2/static; }
location / { include /etc/nginx/uwsgi_params; uwsgi_pass 127.0.0.1:8997; #端口要和uwsgi里配置的一样 uwsgi_param UWSGI_SCRIPT text1.wsgi; #wsgi.py所在的目录名+.wsgi uwsgi_param UWSGI_CHDIR /www/pythonProject2/; #项目路径 } }
|
制作成镜像
docker commit -a "loogson" eb41e243e894 loogson:v1 docker images
|
docker run -d -p 80:80 -p 3306:3306 --privileged=true loogson:v1 /usr/sbin/init docker exec -it 8a6ae8bd9ee9 bash
|
vim /usr/sbin/start_uwsgi.sh
|
#!/bin/sh /usr/local/bin/uwsgi --ini /www/pythonProject2/uwsgi.ini
|
chmod +x /usr/sbin/start_uwsgi.sh
|
vim /usr/lib/systemd/system/uwsgi.service
|
# chkconfig: 2345 10 90 # description: myservice .... [Unit] Description=uwsgi After=network.target Before=nginx.service
[Service] ExecStartPre=/bin/sleep 3 ExecStart=/usr/sbin/start_uwsgi.sh ExecReload=/bin/kill -HUP (netstat -antp | grep uwsgi) Type=forking
[Install] WantedBy=multi-user.target
|
docker stop b7a0638bb2db docker commit -a "loogson" b7a0638bb2db loogson:v2
|
FROM loogson:v2 COPY run.sh /tmp/run.sh RUN chmod +x /tmp/run.sh \ && sh /tmp/run.sh ENTRYPOINT ["/usr/sbin/init"]
|
#!/bin/bash sleep 1 systemctl enable mysqld systemctl enable nginx systemctl enable uwsgi
|
docker build --no-cache -t loogson .
|
docker run -d -p 80:80 -p 3306:3306 --privileged=true loogson /usr/sbin/init
|
推送到镜像仓库
创建仓库
登录账号
推送镜像
docker tag loogson:latest wanan21/loongnix-honeypot:latest docker push wanan21/loongnix-honeypot:latest
|
进行拉取尝试
docker pull wanan21/loongnix-honeypot:latest
|
运行
docker run -d -p 80:80 -p 3306:3306 --privileged=true wanan21/loongnix-honeypot:latest /usr/sbin/init
|