[root@13 ~]# yum -y install epel-release [root@13 ~]# ls /etc/yum.repos.d/ bak.tar.gz CentOS-Base.repo dvd.repo epel.repo epel-testing.repo [root@13 ~]# yum list | grep nodejs // 找到nodejs.x86_64的安装包 [root@13 ~]# yum -y install nodejs.x86_64 //直接安装 [root@13 ~]# node -v v16.20.2
简易服务器环境
安装包管理器 npm node package manager
[root@13 ~]# yum -y install npm [root@13 ~]# npm -v 8.19.4
npm 设置国内镜像
[root@13 ~]# npm config set registry https://registry.npmmirror.com [root@13 ~]#
安装vue的脚手架软件
[root@13 ~]# npm install @vue/cli -g //指定安装 npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated npm WARN deprecated @babel/plugin-proposal-optional-chaining@7.21.0: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead. npm WARN deprecated @babel/plugin-proposal-nullish-coalescing-operator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead. npm WARN deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead. npm WARN deprecated rimraf@2.6.3: Rimraf versions prior to v4 are no longer supported npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported npm WARN deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported npm WARN deprecated apollo-server-errors@3.3.1: The `apollo-server-errors` package is part of Apollo Server v2 and v3, which are now deprecated (end-of-life October 22nd 2023 and October 22nd 2024, respectively). This package's functionality is now found in the `@apollo/server` package. See https://www.apollographql.com/docs/apollo-server/previous-versions/ for more details. npm WARN deprecated apollo-datasource@3.3.2: The `apollo-datasource` package is part of Apollo Server v2 and v3, which are now deprecated (end-of-life October 22nd 2023 and October 22nd 2024, respectively). See https://www.apollographql.com/docs/apollo-server/previous-versions/ for more details. npm WARN deprecated apollo-server-plugin-base@3.7.2: The `apollo-server-plugin-base` package is part of Apollo Server v2 and v3, which are now deprecated (end-of-life October 22nd 2023 and October 22nd 2024, respectively). This package's functionality is now found in the `@apollo/server` package. See https://www.apollographql.com/docs/apollo-server/previous-versions/ for more details. npm WARN deprecated apollo-server-types@3.8.0: The `apollo-server-types` package is part of Apollo Server v2 and v3, which are now deprecated (end-of-life October 22nd 2023 and October 22nd 2024, respectively). This package's functionality is now found in the `@apollo/server` package. See https://www.apollographql.com/docs/apollo-server/previous-versions/ for more details. npm WARN deprecated apollo-server-env@4.2.1: The `apollo-server-env` package is part of Apollo Server v2 and v3, which are now deprecated (end-of-life October 22nd 2023 and October 22nd 2024, respectively). This package's functionality is now found in the `@apollo/utils.fetcher` package. See https://www.apollographql.com/docs/apollo-server/previous-versions/ for more details. npm WARN deprecated shortid@2.2.16: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. npm WARN deprecated apollo-reporting-protobuf@3.4.0: The `apollo-reporting-protobuf` package is part of Apollo Server v2 and v3, which are now deprecated (end-of-life October 22nd 2023 and October 22nd 2024, respectively). This package's functionality is now found in the `@apollo/usage-reporting-protobuf` package. See https://www.apollographql.com/docs/apollo-server/previous-versions/ for more details. npm WARN deprecated subscriptions-transport-ws@0.11.0: The `subscriptions-transport-ws` package is no longer maintained. We recommend you use `graphql-ws` instead. For help migrating Apollo software to `graphql-ws`, see https://www.apollographql.com/docs/apollo-server/data/subscriptions/#switching-from-subscriptions-transport-ws For general help using `graphql-ws`, see https://github.com/enisdenjo/graphql-ws/blob/master/README.md npm WARN deprecated vue@2.7.16: Vue 2 has reached EOL and is no longer actively maintained. See https://v2.vuejs.org/eol/ for more details. added 854 packages in 1m 74 packages are looking for funding run `npm fund` for details npm notice npm notice New major version of npm available! 8.19.4 -> 10.8.2 npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.2 npm notice Run npm install -g npm@10.8.2 to update! npm notice [root@13 ~]#
[root@13 ~]# find / -name "vue" /usr/local/bin/vue /usr/local/lib/node_modules/@vue/cli/node_modules/vue [root@13 ~]# /usr/local/bin/vue -V @vue/cli 5.0.8
以上是使用npm(nodejs 包管理器)安装软件
使用vue脚手架创建一个前段项目
[root@13 ~]# /usr/local/bin/vue create vuehtml000
在当前目录创建vuehtml000 目录,程序员就可以在这个文件中开发前端页面
[root@13 ~]# cd vuehtml000/ [root@13 vuehtml000]# npm run serve
[root@13 ~]# systemctl stop firewalld
真机访问 http://192.168.2.13:8080/
将vue项目做成一个前段项目
[root@13 vuehtml000]# npm run build # 在vue项目的目录中找到刚刚生成的dist目录 [root@13 vuehtml000]# ls babel.config.js jsconfig.json package.json public src dist node_modules package-lock.json README.md vue.config.js [root@13 vuehtml000]# ls ./dist/ css favicon.ico index.html js [root@13 vuehtml000]#
将这些静态文件部署到nginx的HTML
[root@13 ~]# mkdir /usr/share/nginx [root@13 ~]# mkdir /usr/share/nginx/html [root@13 vuehtml000]# find / -name "html" -type d /root/Python-3.12.4/Lib/html /var/www/html /usr/lib64/python2.7/site-packages/lxml/html /usr/share/doc/pam-1.1.8/html /usr/share/doc/pcre-devel-8.32/html /usr/share/doc/sgml-common-0.6.3/html /usr/share/doc/postgresql-9.2.23/html /usr/share/doc/python-kitchen-1.1.1/html /usr/share/doc/neon-0.30.0/html /usr/local/python3124/lib/python3.12/html [root@13 vuehtml000]# cp -R ./dist/* /usr/share/nginx/html [root@13 vuehtml000]#
启动nginx
[root@13 vuehtml000]# netstat -lntup | grep sshd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1096/sshd
tcp6 0 0 :::22 :::* LISTEN 1096/sshd
[root@13 vuehtml000]#
ssh 商用收费的对安全负责
当前系统默认安装的是
[root@13 vuehtml000]# systemctl stop sshd //停用ssh,Xshell断开
关闭防火墙和SElinux
[root@13 ~]# systemctl stop firewalld [root@13 ~]# systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. [root@13 ~]# setenforce 0 [root@13 ~]#
检查epel
[root@13 ~]# ls /etc/yum.repos.d/ bak.tar.gz CentOS-Base.repo dvd.repo epel.repo epel-testing.repo [root@13 ~]# yum -y install openssh 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: mirrors.huaweicloud.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 正在解决依赖关系 --> 正在检查事务 ---> 软件包 openssh.x86_64.0.7.4p1-16.el7 将被 升级 --> 正在处理依赖关系 openssh = 7.4p1-16.el7,它被软件包 openssh-server-7.4p1-16.el7.x86_64 需要 --> 正在处理依赖关系 openssh = 7.4p1-16.el7,它被软件包 openssh-clients-7.4p1-16.el7.x86_64 需要 ---> 软件包 openssh.x86_64.0.7.4p1-23.el7_9 将被 更新 --> 正在检查事务 ---> 软件包 openssh-clients.x86_64.0.7.4p1-16.el7 将被 升级 ---> 软件包 openssh-clients.x86_64.0.7.4p1-23.el7_9 将被 更新 ---> 软件包 openssh-server.x86_64.0.7.4p1-16.el7 将被 升级 ---> 软件包 openssh-server.x86_64.0.7.4p1-23.el7_9 将被 更新 --> 解决依赖关系完成 依赖关系解决 ============================================================================= Package 架构 版本 源 大小 ============================================================================= 正在更新: openssh x86_64 7.4p1-23.el7_9 updates 510 k 为依赖而更新: openssh-clients x86_64 7.4p1-23.el7_9 updates 655 k openssh-server x86_64 7.4p1-23.el7_9 updates 459 k 事务概要 ============================================================================= 升级 1 软件包 (+2 依赖软件包) 总下载量:1.6 M Downloading packages: No Presto metadata available for updates (1/3): openssh-7.4p1-23.el7_9.x86_64.rpm | 510 kB 00:01 (2/3): openssh-clients-7.4p1-23.el7_9.x86_64.rpm | 655 kB 00:01 (3/3): openssh-server-7.4p1-23.el7_9.x86_64.rpm | 459 kB 00:00 ----------------------------------------------------------------------------- 总计 808 kB/s | 1.6 MB 00:02 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在更新 : openssh-7.4p1-23.el7_9.x86_64 1/6 正在更新 : openssh-clients-7.4p1-23.el7_9.x86_64 2/6 正在更新 : openssh-server-7.4p1-23.el7_9.x86_64 3/6 清理 : openssh-server-7.4p1-16.el7.x86_64 4/6 清理 : openssh-clients-7.4p1-16.el7.x86_64 5/6 清理 : openssh-7.4p1-16.el7.x86_64 6/6 验证中 : openssh-7.4p1-23.el7_9.x86_64 1/6 验证中 : openssh-clients-7.4p1-23.el7_9.x86_64 2/6 验证中 : openssh-server-7.4p1-23.el7_9.x86_64 3/6 验证中 : openssh-7.4p1-16.el7.x86_64 4/6 验证中 : openssh-clients-7.4p1-16.el7.x86_64 5/6 验证中 : openssh-server-7.4p1-16.el7.x86_64 6/6 更新完毕: openssh.x86_64 0:7.4p1-23.el7_9 作为依赖被升级: openssh-clients.x86_64 0:7.4p1-23.el7_9 openssh-server.x86_64 0:7.4p1-23.el7_9 完毕! [root@13 ~]#
[root@13 ~]# yum -y install openssh-clients
查找主配置文件
[root@13 ~]# ls /etc/ssh moduli ssh_host_ecdsa_key ssh_host_ed25519_key.pub ssh_config ssh_host_ecdsa_key.pub ssh_host_rsa_key sshd_config ssh_host_ed25519_key ssh_host_rsa_key.pub [root@13 ~]# [root@13 ~]# rpm -ql openssh-clients /etc/ssh/ssh_config /usr/bin/scp /usr/bin/sftp /usr/bin/slogin /usr/bin/ssh /usr/bin/ssh-add /usr/bin/ssh-agent /usr/bin/ssh-copy-id /usr/bin/ssh-keyscan /usr/lib64/fipscheck/ssh.hmac /usr/libexec/openssh/ssh-pkcs11-helper /usr/share/man/man1/scp.1.gz /usr/share/man/man1/sftp.1.gz /usr/share/man/man1/slogin.1.gz /usr/share/man/man1/ssh-add.1.gz /usr/share/man/man1/ssh-agent.1.gz /usr/share/man/man1/ssh-copy-id.1.gz /usr/share/man/man1/ssh-keyscan.1.gz /usr/share/man/man1/ssh.1.gz /usr/share/man/man5/ssh_config.5.gz /usr/share/man/man8/ssh-pkcs11-helper.8.gz [root@13 ~]#
修改主配置文件/etc/ssh/sshd_config
(man 5 sshd_config 使用手册查看),不允许root远程登录
[root@13 ~]# vim /etc/ssh/sshd_config 38 PermitRootLogin no [root@13 ~]# systemctl restart sshd
添加用户和组
[root@13 ~]# useradd yulan [root@13 ~]# passwd yulan 更改用户 yulan 的密码 。 新的 密码: 无效的密码: 密码少于 8 个字符 重新输入新的 密码: passwd:所有的身份验证令牌已经成功更新。 [root@13 ~]# useradd lisi [root@13 ~]# passwd lisi 更改用户 lisi 的密码 。 新的 密码: 无效的密码: 密码少于 8 个字符 重新输入新的 密码: passwd:所有的身份验证令牌已经成功更新。 [root@13 ~]# su [root@13 ~]# ls -l /home/ 总用量 4 -rw-r--r--. 1 root root 233 7月 15 16:04 bak.tar.gz drwx------. 4 lisi lisi 106 7月 17 14:52 lisi drwx------. 2 mm mm 62 4月 11 2018 mm drwx------. 2 user1 user1 62 7月 11 10:20 user1 drwx------. 2 user2 user2 81 7月 11 10:29 user2 drwx------. 2 user3 user3 81 7月 11 10:41 user3 drwx------. 3 yulan yulan 115 7月 17 14:40 yulan [root@13 ~]# mkdir /code [root@13 ~]# groupadd code [root@13 ~]# usermod -g code yulan //添加到组 [root@13 ~]# usermod -g code lisi [root@13 ~]# [root@13 ~]# chgrp -R code /code/ [root@13 ~]# chmod -R g+w /code/ //给code组写的权限
[yulan@13 ~]$ touch /opt/woshiyulantouch: 无法创建"/opt/woshiyulan": 权限不够[yulan@13 ~]$ touch /code/woshiyulan //成功创建
[lisi@13 ~]$ touch /code/woshiyulan.txt //成功创建[lisi@13 ~]$
更改配置
[root@13 ~]# vim /etc/ssh/sshd_config 17 Port 9999 [root@13 ~]# systemctl restart sshd //重启ssh服务 [root@13 ~]# systemctl stop firewalld [root@13 ~]# setenforce 0 [root@13 ~]#
ssh连接服务器,如果服务器端口是22 ,可以不用添加 -p 端口;如果服务器端口是其他,一定要 -p 加端口
[root@14 ~]# ssh -lyulan 192.168.2.13 //不指定端口无法连接
ssh: connect to host 192.168.2.13 port 22: Connection refused
[root@14 ~]# ssh -lyulan 192.168.2.13 -p9999 //指定端口9999 成功
安装密码生成工具
[root@13 ~]# yum -y install pwgen.x86_64 已加载插件:fastestmirror Loading mirror speeds from cached hostfile epel/x86_64/metalink | 16 kB 00:00 * base: mirrors.aliyun.com * epel: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com base | 3.6 kB 00:00 extras | 2.9 kB 00:00 mnt | 3.6 kB 00:00 updates | 2.9 kB 00:00 正在解决依赖关系 --> 正在检查事务 ---> 软件包 pwgen.x86_64.0.2.08-1.el7 将被 安装 --> 解决依赖关系完成 依赖关系解决 ============================================================================= Package 架构 版本 源 大小 ============================================================================= 正在安装: pwgen x86_64 2.08-1.el7 epel 26 k 事务概要 ============================================================================= 安装 1 软件包 总下载量:26 k 安装大小:42 k Downloading packages: pwgen-2.08-1.el7.x86_64.rpm | 26 kB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : pwgen-2.08-1.el7.x86_64 1/1 验证中 : pwgen-2.08-1.el7.x86_64 1/1 已安装: pwgen.x86_64 0:2.08-1.el7 完毕! [root@13 ~]# pwgen -cnBs1 10 1 //生成密码 77ukWnbwm9 [root@13 ~]#
scp 指定端口 -P (大写)
ssh 指定端口 -p (小写)
默认端口22 ,不需要指定
查看用户:
[root@13 ~]# who root tty1 2024-07-17 09:30 root pts/0 2024-07-17 09:32 (192.168.2.2) root pts/1 2024-07-17 09:56 (192.168.2.2) yulan pts/3 2024-07-17 15:24 (192.168.2.2) [root@13 ~]# [root@13 ~]# pkill -kill -t pts/3 //杀死用户yulan [root@13 ~]# who root tty1 2024-07-17 09:30 root pts/0 2024-07-17 09:32 (192.168.2.2) root pts/1 2024-07-17 09:56 (192.168.2.2) [root@13 ~]#
生成密钥:
[root@13 ~]# su yulan [yulan@13 root]$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/yulan/.ssh/id_rsa): Created directory '/home/yulan/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/yulan/.ssh/id_rsa. Your public key has been saved in /home/yulan/.ssh/id_rsa.pub. The key fingerprint is: SHA256:1wWpTipdICDGFRdzQtNRn/5JUqlmRMZeDm4iLD7Umz4 yulan@13 The key's randomart image is: +---[RSA 2048]----+ | .o.++Booo..+. | | ... ..=o ++o.. | | + . ++++ | | o + =+++. | | o oSO.oB . | | + =..o + . | | + o | | E | | . | +----[SHA256]-----+ [yulan@13 root]$ cd [yulan@13 ~]$ ls ./.ssh/ id_rsa id_rsa.pub [yulan@13 ~]$ ls ./.ssh/ -l 总用量 8 -rw-------. 1 yulan code 1679 7月 17 16:17 id_rsa //私钥 -rw-r--r--. 1 yulan code 390 7月 17 16:17 id_rsa.pub //公钥 [yulan@13 ~]$
把公钥传输:
[yulan@13 ~]$ ssh-copy-id root@192.168.2.14 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/yulan/.ssh/id_rsa.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@192.168.2.14's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root@192.168.2.14'" and check to make sure that only the key(s) you wanted were added. [yulan@13 ~]$ [yulan@13 ~]$ ssh -lroot 192.168.2.14 //不用密码直接登录 Last login: Wed Jul 17 11:31:58 2024 from 192.168.2.2 [root@14 ~]# ls ./.ssh/ authorized_keys known_hosts [root@14 ~]# exit 登出 Connection to 192.168.2.14 closed. [yulan@13 ~]$ exit exit [root@13 ~]# ls /home/yulan/.ssh/ //只有yulan用户有免密登录文件 authorized_keys id_rsa id_rsa.pub known_hosts