部署CentOS,集成Mysql、Nodejs、Nginx
1. Mysql安装
Step 1 安装源
https://dev.mysql.com/downloads/repo/yum/
选择:Red Hat Enterprise Linux 8 / Oracle Linux 8 (Architecture Independent), RPM Package 这个download
跳转的页面对着No thanks, just start my download.右键,复制链接地址,我的是这个:
https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
Step 2 安装
登录服务器,随便找个文件夹执行:
wget -i -c https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
然后:
rpm -ivh mysql80-community-release-el8-1.noarch.rpm
然后:
sudo yum install mysql-server
然后,启动服务:
service mysqld restart
然后,改密码:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
然后,退出:
mysql> exit
然后,设置开机启动:
systemctl enable mysqld
Step 3 远程登录
登录数据库:
mysql -uroot -p
输入密码,然后:
mysql> use mysql
将host设置为%表示任何ip都能连接mysql,当然您也可以将host指定为某个ip:
mysql> update user set host='%' where user='root' and host='localhost';
如果开了想关闭的话,把host设成本地:
mysql> update user set host='localhost' where user='root';
然后,刷新权限表,使配置生效:
mysql> flush privileges;
PS:一顿操作之后连上去还是报timeout,那么大概率是防火墙没开3306了。
Step 4 DataGrip备份和还原
DataGrip真的好用,嗯,具体可以参考这里:
可以参考这里:https://www.jianshu.com/p/0b15988e8685
dump的话看这里:https://blog.csdn.net/zjh19961213/article/details/107865162
node 安装配置
先yum装个nodejs
sudo yum -y install nodejs
再装个node的版本切换工具n:
npm i -g n
然后切去最新的稳定版:
n stable
再装个切源工具:
npm i -g nrm
最后装个pm2:
npm i -g pm2
Nginx 安装配置
Step 1 安装
官方文档可以参考:http://nginx.org/en/linux_packages.html#RHEL-CentOS
对不起,上面是我装逼了,中文文档:https://www.nginx.cn/doc/
先跑:
yum install yum-utils
然后:
cd /etc/yum.repos.d/
然后新建nginx.repo文件:
vim nginx.repo
输入:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
然后安装:
sudo yum install nginx
查看是否装好了:
rpm -qa | grep nginx
常用的启停重指令:
systemctl start nginx
systemctl stop nginx
systemctl restart nginx
设置开机启动:
systemctl enable nginx
调试1,找安装目录,比如 “/usr/local/opt/nginx/bin/nginx” :
ps aux|grep nginx
调试2,测试是否连通:
/usr/local/opt/nginx/bin/nginx -t