概述
后续的项目因需要用到Ubuntu系统,在此记录。
系统版本:Ubuntu22.04.2
基础设置
Ubuntu22.04.2系统安装后,ssh、gcc、make等基础软件包并未安装,需联网下载安装。
注:初次登录,无法以root用户登录。
设置root密码
sudo passwd
设置可root用户登录
- vim /etc/pam.d/gdm-autologin
- 将auth required pam_succeed_if.so user != root quiet_success行注释掉
- vim /etc/pam.d/gdm-password
- 将auth required pam_succeed_if.so user != root quiet_success行注释掉
- 注销,即可以root用户登录
安装基础软件
以root用户登录。
# 更新软件源
apt update
# 安装网络工具包
apt install net-tools
# 查看IP
ifconfig
# 安装ssh
apt install openssh-server
# 查看是否启动
ps ax | grep sshd
# 设置允许ssh远程登录、scp拷贝等
vim /etc/ssh/sshd_config
# 将PermitRootLogin prohibit-password
# 改为PermitRootLogin yes
# 然后重启ssh
service ssh restart
# 安装gcc
apt install gcc
# 查看gcc版本
gcc --version
# 安装g++
apt install g++
# 查看g++版本
g++ --version
# 安装make
apt install make
# 查看make版本
make --version
# 安装vim
apt install vim
# 查看vim版本
vim --version
# 安装curl
apt install curl
# 查看curl版本
curl --version
安装开发/测试环境
安装JDK1.8
- 将JDK1.8压缩包放到系统/home/soft目录下。
- 解压到opt目录下:
tar -zxvf jdk-8u261-linux-x64.tar.gz -C /opt
- 配置环境变量:
vim ~/.bashrc
在文件最后添加:
export JAVA_HOME=/opt/jdk1.8.0_261
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
- 使环境变量生效:
1. source ~/.bashrc
- 查看JDK版本:
java -version
- 若出现的java版本和安装的JDK版本一致,则说明安装成功。
安装MySQL8.0.30
- 放到/home/soft下
- 解压:
tar -xvf mysql-server_8.0.30-1ubuntu22.04_amd64.deb-bundle.tar
- 安装依赖:
apt install -y libaio1 libmecab2 man-db libc-bin
- 安装msyql:
安装过程中会设置MySQL的root用户密码,请牢记。
设置MySQL的root用户密码时,选低要求的那个密码验证方式。
dpkg -i mysql-community-client-plugins_8.0.30-1ubuntu22.04_amd64.deb
dpkg -i mysql-community-client-core_8.0.30-1ubuntu22.04_amd64.deb
dpkg -i mysql-community-client_8.0.30-1ubuntu22.04_amd64.deb
dpkg -i mysql-common_8.0.30-1ubuntu22.04_amd64.deb
dpkg -i mysql-community-client_8.0.30-1ubuntu22.04_amd64.deb
dpkg -i mysql-client_8.0.30-1ubuntu22.04_amd64.deb
dpkg -i libmysqlclient21_8.0.30-1ubuntu22.04_amd64.deb
dpkg -i libmysqlclient-dev_8.0.30-1ubuntu22.04_amd64.deb
dpkg -i mysql-client_8.0.30-1ubuntu22.04_amd64.deb
dpkg -i mysql-community-server-core_8.0.30-1ubuntu22.04_amd64.deb
dpkg -i mysql-community-server_8.0.30-1ubuntu22.04_amd64.deb
dpkg -i mysql-server_8.0.30-1ubuntu22.04_amd64.deb
- 查看MySQL是否启动:
ps ax | grep mysqld
- 登录MySQL,创建用户,创建数据库:
# 登录MySQL
mysql -u root -p
# 创建用户
create user test_user identified by '123456';
# 创建数据库
create database test_db;
# 切换到新创建的数据库
use test_db;
# 将新创建的数据库权限设置给新创建的用户
grant all privileges on *.* to test_user;
grant process on *.* to test_user;
flush privileges;
# 退出登录
quit
# 以新用户登录
mysql -u test_user -p
# 显示数据库
show databases;
# 切换到新创建的数据库
use test_db;
# 显示所有表格(因是新创建的数据库,故为空库)
show tables;
安装redis6.2.5
- 将redis安装包放到/home/soft下
- 解压
tar -zxvf redis-6.2.5_linux.tar.gz
- 进入到解压目录下,安装redis:
cd redis-6.2.5
make
make install
- 修改配置:
# 将/home/soft/redis-6.2.5/redis.conf复制到redis可执行程序处
cp /home/soft/redis-6.2.5/redis.conf /usr/local/bin
# 修改/usr/local/bin/redis.conf文件
vim /usr/local/bin/redis.conf
# (1)将bind 127.0.0.1 -::1 改为 bind 0.0.0.0 -::1
# (2)将port 6379改为6380
# (3)将protected-mode no改为protected-mode yes
# (4)将# requirepass foobared改为 requirepass 123456
# 保存退出
- 启动redis并查看:
# 启动
redis-server /usr/local/bin/redis.conf
# 查看
ps ax | grep redis
- 连接redis:
# 连接
redis-cli -p 6380
# 授权
auth 123456
# 测试响应(应回应PONG)
ping
安装nginx1.20.1
- 安装nginx依赖包:
apt install libpcre3 libpcre3-dev
apt install zlib1g-dev
- 将nginx安装包放到/home/soft下
- 解压:
tar -zxvf nginx-1.20.1.tar.gz
- 进入到解压目录,安装nginx:
# 进入到目录
cd nginx-1.20.1
# 生成makefile文件
./configure --prefix=/opt/nginx-1.20.1
# 编译,安装
make
make install
# 建立nginx全局启动软连接
ln -s /opt/nginx-1.20.1/sbin/nginx /usr/local/bin/nginx
# 启动nginx
nginx
# 查看nginx是否启动
ps ax | grep nginx
- 修改nginx配置文件/opt/nginx-1.20.1/conf/nginx.conf:
user root;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid /opt/nginx1.20/logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
map $http_upgrade $connection_upgrade {
default keep-alive; #默认为keep-alive 可以支持 一般http请求
'websocket' upgrade;
}
server {
listen 80;
server_name localhost80;
# location /forecast {
# alias /home/fr3000f/FR3000D/jar_bin/powerforecast_web;
# try_files $uri $uri/ /index.html;
# index index.html index.htm;
#}
#location /forecast/api {
# proxy_pass http://127.0.0.1:8081/;
#}
location /forecast {
proxy_pass http://127.0.0.1:1223/forecast/;
}
location /socket/ {
proxy_http_version 1.1;
proxy_pass http://localhost:8081/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 1223;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:1223/forecast/;
}
location /forecast {
alias /home/fr3000f/FR3000D/jar_bin/powerforecast_web;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /forecast/api/ {
proxy_pass http://127.0.0.1:8081/;
}
location /socket/ {
proxy_http_version 1.1;
proxy_pass http://localhost:8081/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 1224;
server_name localhost;
location / {
root /home/fr3000f/FR3000D/jar_bin/power_trade_decision_web;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /api/ {
proxy_pass http://127.0.0.1:9090/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
- 重新加载nginx配置:
nginx -s reload
安装hiredis C库
下载路径: https://github.com/redis/hiredis
- 将hiredis C库放到/home/soft下
- 解压并安装:
unzip hiredis-master.zip
cd hiredis-master
make
make install
# 可以看到,hiredis安装到了/usr/local/lib和/usr/local/include下
- 添加动态库寻找路径:
# 打开文件
vim /etc/ld.so.conf
# 在文件最后一行添加
# 因为系统默认不寻找/usr/local/lib目录下的动态连接库
/usr/local/lib
# 使生效
ldconfig
安装Chrome浏览器
- 下载:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
- 安装:
dpkg -i google-chrome-stable_current_amd64.deb
- 修改Chrome启动文件,否则无法启动Chrome浏览器:
# 查找Chrome浏览器启动文件
whereis google-chrome
# 打开启动文件
vim /usr/bin/X11/google-chrome
# 修改启动文件内容:
# 将exec -a "$0" "$HERE/chrome" "$@"
# 改为exec -a "$0" "$HERE/chrome" "$@" --no-sandbox
# 保存后退出
- 启动Chrome浏览器:在软件列表中找到Chrome浏览器,拖到桌面工具栏中,点击打开即可。