Loading

使用Ubuntu20.04部署ferry工单系统

下面使用阿里云服务器ubuntu20.04进行ferry工单系统的部署

注:本教程所有命令均是使用root用户进行操作的

环境要求

需注意因使用到了json类型的字段,因此MySQL需是5.7以上的版本。

MySQL > 5.7

Go >= 1.14

Redis 新版即可

node >= v12 (稳定版本)

npm >= v6.14.8

配置源(可选)

Ubuntu 的软件源配置文件是 /etc/apt/sources.list。将系统自带的该文件做个备份,将该文件替换为下面内容,即可使用 TUNA 的软件源镜像。

Ubuntu20.04换源内容:

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

其他问题请访问帮助链接:

Ubuntu 镜像使用帮助

更新系统

第一次安装软件一定要先更新系统,可以避免很多奇奇怪怪的错误。

sudo apt update
sudo apt upgrade

Redis

sudo apt install redis-server
sudo service redis-server start

MySQL

安装

apt 库有现成的包,直接执行命令安装

sudo apt install mysql-server

配置

用这个命令进入mysql

sudo mysql

在sql命令行输入以下命令回车,你就可以把密码改成mynewpassword

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'mynewpassword';

exit回到终端命令行,输入:

sudo mysql_secure_installation

输入刚才设置的root密码,根据提示输入Y or N:

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: N # 否

# 是否移除匿名用户
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N # 否

... skipping.

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

# 是否禁止 root 远程登录
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N # 否

... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

# 是否移除 test 数据库
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N # 否

... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

# 是否立即刷新表的权限
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y # 是
Success.

All done!

配置完成后,重启 MySQL 服务

sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

项目配置

部署ferry需要在mysql中提前创建数据库:

mysql -uroot -p
# 输入密码进入mysql
create database ferry;
# 如果需要删除数据库ferry
# drop database ferry
exit;

常见错误

可能会出现以下报错:

Securing the MySQL server deployment.

Enter password for user root:

Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

先重启一下 MySQL 服务

sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

执行 start 的时候可能又会报错:

  • Starting MySQL database server mysqld
    No directory, logging in with HOME=/
    mkdir: cannot create directory ‘//.cache’: Permission denied
    -su: 19: /etc/profile.d/wsl-integration.sh: cannot create //.cache/wslu/integration: Directory > nonexistent

解决办法:

sudo usermod -d /var/lib/mysql/ mysql
sudo ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
sudo chown -R mysql:mysql /var/lib/mysql

输入密码时,可能会出现Failed! Error: SET PASSWORD has no significance for user ‘root‘@‘localhost‘的错误

用这个命令进入mysql

sudo mysql

在sql命令行输入以下命令回车,你就可以把密码改成mynewpassword

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'mynewpassword';

exit回到终端命令行,输入:

sudo mysql_secure_installation

输入刚才设置的root密码,即可正常进入脚本。

尝试登录

sudo mysql -uroot -p
Enter password:

输入密码后可能又会报错

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

打开 MySQL 配置文件 /etc/mysql/my.cnf,在 [mysqld]下新增一行 skip-grant-tables

此操作可以不输入密码登录 MySQL

此处登录不上去并不是密码错误

再次重启 MySQL

免密登录

> sudo mysql -uroot -p
# 直接回车可以登录
> use mysql;
> select user,plugin from user;
# 可以看到 root 用户的 plugin 为 auth_socket,需要修改为 mysql_native_password
> update user set plugin="mysql_native_password" where user="root";
> quit # 退出

打开 MySQL 配置文件 /etc/mysql/my.cnf,将skip-grant-tables 注释或者删除。

再次重启 MySQL 就可以登录成功了。

Golang

为了安装最新版本Golang,请不要使用apt安装。

# 不推荐!
sudo apt install golang

请使用下面的安装方式:

访问Golang官网下载页面复制linux文件下载链接,在终端执行:

wget https://golang.google.cn/dl/go1.18.3.linux-amd64.tar.gz # 请不要复制粘贴,根据最新版本号调整
sudo tar zxf go1.18.3.linux-amd64.tar.gz -C /opt # 解压到/opt中

# 配置环境
echo "export PATH=\$PATH:/opt/go/bin" >> ~/.bashrc
source ~/.bashrc
sudo ln -s /opt/go/bin/go /usr/bin/go

查看Go版本是否符合要求:

go version

换源(可选)

# Go语言换源
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct

# 或者
echo "export GO111MODULE=on" >> ~/.bashrc
echo "export GOPROXY=https://goproxy.cn,direct" >> ~/.bashrc

Node.js

安装

为了安装最新版Node.js,请不要使用apt进行安装:

# 不推荐!
sudo apt install nodejs npm

请到官网下载页面复制Linux最新版下载链接,在终端粘贴下载安装:

wget https://npmmirror.com/mirrors/node/v16.15.1/node-v16.15.1-linux-x64.tar.xz # 请不要复制粘贴,根据最新版本号调整
sudo tar xf node-v16.15.1-linux-x64.tar.xz -C /opt # 解压到/opt中
sudo mv /opt/node-v16.15.1-linux-x64 /opt/node

# 配置环境
echo "export PATH=\$PATH:/opt/node/bin" >> ~/.bashrc
source ~/.bashrc
sudo ln -s /opt/node/bin/node /usr/bin/node
sudo ln -s /opt/node/bin/npm /usr/bin/npm

查看node和npm版本是否符合要求:

node -v
npm -v

其他操作(可选)

# npm换源
npm config set registry https://registry.npm.taobao.org
# 更新npm
sudo npm install npm@latest -g

Docker

安装docker

wget -qO- https://get.docker.com/ | sh
sudo service docker start
# 当要以非root用户可以直接运行docker时,需要执行
# sudo usermod -aG docker $(whoami)
# 命令,然后重新登陆,否则会有报错
# 使用命令:su - ${USER} 重新登录账户
# 使用命令:id -nG 查看当前用户已经更加到docker用户组

# 测试docker安装成功,命令如下:
# docker run hello-world

ferry

拉取仓库代码

sudo apt install git
git clone https://github.com/lanyulei/ferry.git
# 如果出现网络问题,请多试几次,网络不稳定
# 或者使用国内的链接:
git clone https://gitee.com/yllan/ferry.git

配置MySQL

# 在部署之前需要先配置数据库
# 进入ferry文件夹
cd ferry
vim ./config/settings.yml
# 找到database

按照下面的注释更改其中的条目

  database:
    dbtype: mysql
    # 数据库地址,使用本地数据库设置为localhost即可
    host: localhost
    # 数据库名称,需要在mysql中提前创建,例如:create database ferry;
    name: ferry
    # mysql登录密码
    password: mynewpassword
    # mysql端口,不需要改,保持默认即可
    port: 3306
    # mysql登录账户
    username: root

配置Redis

找到redis,并更改如下:

  redis:
    url: redis://localhost:6379

配置邮箱

下面以QQ邮箱为示例:

  1. 首先登陆QQ邮箱,开启POP3/SMTP服务,获取授权码。

  2. 更改settings.yml文件内容:

  email:
    alias: ferry
    # 改为QQ邮箱
    host: smtp.qq.com
    # 输入你QQ邮箱的授权码,而不是密码
    pass: your password
    # 保持默认
    port: 4653
    # 输入你的邮箱
    user: your email

编译项目

cd ferry
# 安装
./build.sh install
# 安装脚本询问的问题可以全部忽略(按回车键),采用默认值安装
# 启动
./build.sh start

编译问题

遇到Error: Node Sass version 7.0.1 is incompatible with ^4.0.0.

重新安装sass即可。

npm uninstall node-sass
npm i -D sass

Golang安装模块超时

参见Golang换源,或者:

clash开启ALLOW LAN,开启TUN,设置GLOBAL模式。

posted @ 2022-06-24 16:00  橘崽崽啊  阅读(618)  评论(0编辑  收藏  举报