部署Node.js等开发环境
1.实验目的
了解LAMP 平台,学会在Ubuntu平台上部署PHP开发环境;了解Python編程语言,学会在Ubuntu平台上部署python 开发环境;了解Node.js编程语言,学会在 Ubuntu平台上部署Node.js开发环境。解 Ubuntu 服务器版本,学会安装Ubuntu服务器;掌握Ubuntu服务器的网络配置和磁盘存储的动态调整;学会通过SSH远程登录和管理Ubuntu服务器;熟悉LAMP 服务器安装过程,掌握 Apache MySQL和PHP的配置方法。
2.实验设备
一台PC,VM虚拟机和已经安装的Ubuntu18.04系统。
3.实验内容
1)Linux平台上部署Node.js开发环境
a.在Ubuntu上通过apt安装Node.js16。
操作提示:
Ubuntu18.04支持Node.js版本如下:
安装curl:
sudo apt install curl
分别执行:
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
更新软件源:
NODE_MAJOR=16
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
安装Node.js16:
sudo apt-get update
sudo apt-get install nodejs -y
npm也一起被安装:
参考资料:
distributions/README.md at master · nodesource/distributions · GitHub
https://npm.nodejs.cn/about-npm
b.Ubuntu安装Node开发工具——Visual Studio Code。
c.开发Node.js应用程序。
操作提示:
可以先将文字修改成中文=>新建=>xxx.js=>运行
编写程序:
const http = require('http');
const httpServer = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World!s\n');
});
httpServer.listen(3000,function(){
console.log('服务器正在3000端口上监听!');
});
第一个Node.js程序
2) Linux平台上部署SSH远程连接
a.通过apt安装并启动SSH服务
操作提示:
安装SSH:
sudo apt install openssh-server
修改SSH配置:
sudo gedit /etc/ssh/ssh_config
启动SSH服务:
sudo /etc/init.d/ssh start
b.在Windows中使用MobaXterm连接Ubuntu
操作提示:
下载MobaXterm:
MobaXterm Xserver with SSH, telnet, RDP, VNC and X11 - Home Edition
连接:
输入密码后,连接成功: