第一步,更新yum:
yum update
第二步,安装nodejs
yum module list nodejs
安装碰到报错:仓库appstream下载源数据失败,运行下面两行命令:
sudo sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
sudo sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
安装默认的版本
sudo yum -y install nodejs
安装完成后可以查看版本:
node -v
npm -v
第三步,安装pm2
npm install pm2 -g
pm2常用命令:
#启动任务
pm2 start main.js --name maokai
#查看所有任务
pm2 list
#停止指定id的任务
pm2 delete id
#保存当前任务列表
pm2 save
#设置开机启动
pm2 startup
第四步,安装mysql8.0
- 安装yum repository: wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
- 使用rpm安装mysql: rpm -ivh mysql80-community-release-el8-1.noarch.rpm
- 使用yum安装mysql服务: yum install mysql-server
- 检测是否mysql服务是否设置为开机启动(主要查看mysqld.service这个服务):
- systemctl list-unit-files|grep mysqld
- ps -ef | grep mysql
- mysqladmin --version
- 启动服务:
- systemctl start mysqld.service
- systemctl enable mysqld
- systemctl status mysqld
- 查看初始密码: grep 'temporary password' /var/log/mysqld.log
- 使用初始密码登录,修改默认密码:
mysql -uroot -p use mysql; ALTER USER 'root'@'localhost' IDENTIFIED BY '你的新密码'; flush privileges;
配置用户允许外部访问,修改mysql库的user表,将host项,从localhost改为%。%这里表示的是允许任意host访问,如果只允许某一个ip访问,则可改为相应的ip。
CREATE USER 'root'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
FLUSH PRIVILEGES;
设置密码策略,让Navicat能够正常连接:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码';
FLUSH PRIVILEGES;
第五步,安装Nginx,
yum install nginx
默认安装位置:/etc/nginx,nginx常用命令:
从容停止服务: nginx -s quit
立即停止服务:nginx -s stop
重启服务: service nginx restart
配置nginx为开机自启动(没有验证):
第一步:进入到/lib/systemd/system/目录
# cd /lib/systemd/system/
第二步:创建nginx.service文件,并编辑
# vim nginx.service
文件内容:
[Unit]
Description=nginx service
After=network.target
[Service]
Type=forking
ExecStart=/opt/nginx/sbin/nginx
ExecReload=/opt/nginx/sbin/nginx -s reload
ExecStop=/opt/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
保存退出。
第三步:加入开机自启动
# systemctl enable nginx.service
如何取消开机自启动
# systemctl disable nginx.service
第四步:服务的启动/停止/刷新配置文件/查看状态
# systemctl start nginx.service 启动nginx服务
# systemctl stop nginx.service 停止服务
# systemctl restart nginx.service 重新启动服务
# systemctl list-units --type=service 查看所有已启动的服务
# systemctl status nginx.service 查看服务当前状态
# systemctl enable nginx.service 设置开机自启动
# systemctl disable nginx.service 停止开机自启动