I. Environmental installation
The book picks up where the previous one left off.Learning RedisAfter that, the server hasInstalling RedisNow, before linking redis with nodejs, install the nodejs environment.
1. Install fnm
(1) Compressed packagesGet it on the server, I put it in root.
(2) Unzip and set permissions
unzip
chmod 777 fnm
(3) Set the environment variable, add it to the end of the /etc/profile file, and the configuration will take effect.
export PATH=$PATH:/root
source /etc/profile
(4) Add to the end of the ~/.bashrc file
eval "$(fnm env --use-on-cd --shell bash)"
source ~/.bashrc
The check fnm version command verifies that the installation was successful
fnm --version
fnm 1.37.2
2、Download and install
fnm use --install-if-missing 20
3、Verify Version
node -v
node: /lib64/.6: version `GLIBC_2.27' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by node)
node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by node)
node: /lib64/.6: version `GLIBC_2.28' not found (required by node)
node: /lib64/.6: version `GLIBC_2.25' not found (required by node)
4, before installing the dependencies, first change the AliCloud yum source (please skip if you have changed)
(1) ReplacementAliCloud yum source
mv /etc// /etc//
wget -O /etc// /repo/
(2) Check your installed scl
yum list installed|grep "scl"
(3) Remove scl and reinstall
yum remove
yum remove
yum install -y centos-release-scl centos-release-scl-rh
(4) Configure scl domestic source aliyun
file
[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=/centos/7/sclo/x86_64/sclo/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
file
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=/centos/7/sclo/x86_64/rh/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
(5) Clearing the cache
yum clean all && yum makecache
I've stepped in the pits. 5, 6, 7, 8. Install them in that order.
5、Upgrade gcc (default is 4 upgrade to 8)
yum install -y centos-release-scl
yum install -y devtoolset-8-gcc*
mv /usr/bin/gcc /usr/bin/gcc-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/g++ /usr/bin/g++
6, upgrade make (default is 3 upgrade to 4)
wget /gnu/make/make-4.
tar -xzvf make-4. && cd make-4.3/
./configure --prefix=/usr/local/make --disable-dependency-tracking
make && make install
cd /usr/bin/ && mv make
ln -sv /usr/local/make/bin/make /usr/bin/make
7. Upgrade glibc
wget /gnu/glibc/glibc-2.
tar xf glibc-2.
cd glibc-2.28/ && mkdir build && cd build
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
make && make install
8. Upgrade libstdc++
wget /wp-content/uploads/2019/08/libstdc.so_.6.0.
unzip libstdc.so_.6.0.
cp libstdc++.so.6.0.26 /lib64/
cd /lib64
cp libstdc++.so.6 libstdc++.so.
rm -f libstdc++.so.6
ln -s libstdc++.so.6.0.26 libstdc++.so.6
"8 Palms of the Dragon" is over. Let's call it a day.
node -v
v20.17.0
II. Service side
1. Initialize the folder and load the package:
- express Simple and flexible framework
- cors cross-domain middleware
- redis client
- pm2 A daemon management tool
2、Modify the configuration
-> scripts -> add: "start": "node . /"
After pm2 is installed, create a startup configuration file in the project directory with the following code:
= {
apps: [
{
name: 'first-api',
script: './',
},
],
}
3. New construction
const express = require('express');
const app = express();
const cors = require('cors');
const redis = require("redis");
const redisClient = ({
url: 'redis://default:cryptographic@IP:Port'
});
('error', err => ('Redis Client Error', err));
();
// utilizationcorsmiddleware
(cors());
("/", (req, res) => {
("Hello World");
})
("/redis/keys", async (req, res) => {
var value = await ("test")
(value);
})
(3001, () => {
("Server is running on port 3001");
})
4, pm2 start --watch, waterling start
III. Front end
1. A matter of request
('http://localhost:3001/redis/keys').then(function (response) {
alert();
})