1. 环境准备
- Node.js 12 或更高版本
- 数据库 (MySQL 或者 Postgresql)
1.1 安装node
- 查看系统版本
cat /proc/version
Linux系统分为两种:
1.RedHat系列:Redhat、Centos、Fedora等
2.Debian系列:Debian、Ubuntu等
RedHat系列的包管理工具是yum
Debian系列的包管理工具是apt-get
- 安装
yum install nodejs
- 查看版本
node -v
1.2 安装mysql
- 通过wegt下载
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
- 安装 MySQL 源
yum localinstall mysql80-community-release-el7-3.noarch.rpm
- 如果之后不想通过 yum update 的时候更新 MySQL,安装完成后卸载即可
yum -y remove mysql80-community-release-el7-3.noarch.rpm
- 用下面的命令检查 MySQL 源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
5. 使用 yum install 命令安装
yum install -y mysql-community-server
如遇到错误信息
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-server-8.0.31-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
The GPG keys listed for the "MySQL 8.0 Community Server" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.
Failing package is: mysql-community-server-8.0.31-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
使用命令:
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
- 启动
systemctl start mysqld
- 查看已安装的 MySQL
rpm -qa | grep -i mysql
- 登录mysql,查看默认密码。
如果你安装的是 MySQL5.7 版本,安装完后会生成一个默认密码保存在 /var/log/mysqld.log 文件中,通过下面的命令找到密码:
grep 'password' /var/log/mysqld.log
- 登录并修改root密码
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
2、安装 Umami
- 获取安装
git clone https://github.com/mikecao/umami.git
cd umami
npm install
- 在umami目录下创建.env文件
DATABASE_URL=mysql://username:password@localhost:3306/database
HASH_SALT=[任意随机字符串]
- 导入预设好的数据表,提前在mysql中建立好umami数据库
mysql -u root -p umami < sql/schema.mysql.sql
- 构建启动程序
npm run build
npm start
如使用阿里云,腾讯云等服务器,请开发安全端口,否则无法访问,
这个命令退出以后就会自动停止,所以我们需要 PM2 工具来守护进程
3. PM2
- 安装
npm install pm2 -g
- 在 Umami 目录下运行
pm2 start npm --name umami -- start
- 设置重启服务器后自启动
pm2 startup
pm2 save
- 启动和停止
pm2 restart umami
pm2 stop umami
4. 使用
配置域名,把其插入到sscript中