普通安装
651字约2分钟
2024-10-02
环境准备
本次安装使用centos7操作系统安装
所需环境:
- python 3.8
- mysql 5.7
- node 16.20
#关闭防火墙
systemctl stop firewalld
#关闭selinux
setenforce 0
#永久关闭selinux,修改完保存退出
vim /etc/selinux/config
SELINUX=disabled
python安装
yum install zlib-devel libffi-devel mysql-devel bzip2-devel git -y
wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz
tar -zxf Python-3.8.6.tgz
cd Python-3.8.6
./configure
make && make install
mysql安装
#首先下载mysql的yum源配置
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
#安装mysql的yum源
yum -y install mysql57-community-release-el7-11.noarch.rpm
#yum方式安装mysql --nogpgcheck (不校验数字签名)
yum -y install mysql-server --nogpgcheck
#启动
systemctl start mysqld.service
systemctl status mysqld.service
#找到初始密码进入mysql
cat /var/log/mysqld.log| grep password
mysql -uroot -p'!F6o2k+Bc165'
>alter user 'root'@'localhost' identified by '123456QWEasd_';
>grant all privileges on *.* to 'root'@'%' identified by '123456QWEasd_' with grant option;
>flush privileges;
>CREATE DATABASE devops DEFAULT CHARACTER SET utf8;
>exit
node安装
wget https://nodejs.org/dist/v16.20.0/node-v16.20.0-linux-x64.tar.xz
tar -xf node-v16.20.0-linux-x64.tar.xz
ln -s /root/node-v16.20.0-linux-x64/bin/node /usr/local/bin/node
ln -s /root/node-v16.20.0-linux-x64/bin/npm /usr/local/bin/npm
vim /etc/profile
#末尾添加
export NODE_HOME=/root/node-v16.20.0-linux-x64/bin/
export PATH=$PATH:$NODE_HOME:/usr/local/bin/
#生效
source /etc/profile
#查看
node -v
npm -v
后台安装
#安装
yum install sshpass rsync git -y
cd /opt/
#拉取后端代码
git clone https://gitee.com/lucky_liuzhe/devops_api.git
cd devops_api/
python3.8 -m pip install --upgrade pip
#安装依赖
pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
vim devops_api/settings.py
#修改mysql用户名、密码、地址
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'devops',
'USER': 'root',
'PASSWORD': '123456QWEasd_',
'HOST': '192.168.0.11',
'PORT': '3306',
}
}
#添加配置-收集静态文件,配置完成后保存退出
STATIC_ROOT=os.path.join(BASE_DIR,'static')
#收集静态文件
python3 manage.py collectstatic
#同步数据库
python3 manage.py migrate
#创建管理员账号-user.py文件默认有配置的创建管理员用户名密码信息,之后用于登录,如果需要变动,请修改以下参数配置
username = 'admin'
email = 'admin@example.com'
password = '123456'
first_name = '管理员'
#执行创建账号命令
python3 user.py
#后台启动服务
nohup python3 manage.py runserver 0.0.0.0:8000 &
#查看日志
tail -f nohup.out
####同步数据库可能遇到的问题####
解决办法:
vim /usr/local/lib/python3.8/site-packages/rest_framework/authtoken/views.py
#修改导入模块
from rest_framework.compat import coreschema,coreapi
#修改完成后再次同步
python3 manage.py migrate
前台安装
cd /opt/
#拉取前端代码
git clone https://gitee.com/lucky_liuzhe/devops_web.git
cd devops_web/
#配置源
npm config set registry https://registry.npmmirror.com
#安装依赖
npm install
#修改VUE_APP_API_HOST值为自己服务器地址
vim .env.production
VUE_APP_API_HOST=192.168.0.11
#执行构建
npm run build
#安装nginx
yum -y install epel-release
yum -y install nginx
#修改配置
server {
listen 80;
listen [::]:80;
server_name _;
root /opt/devops_web/dist/;
location / {
try_files $uri $uri /index.html;
}
location /api {
proxy_pass http://192.168.0.11:8000;
}
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
#启动服务
systemctl start nginx
测试访问
http://ip/
默认管理员账号密码:admin/123456