Linux

以下都是Linux Centos 7的操作

选择java版本

java jdk-XXXX-i586与jdk-XXXX-x64区别
i586是32位系统、x64是64位系统

java jdk-XXXX-aarch64与jdk-XXXX-x64区别?(Linux)
x86_64就是我们常用的台式机的体系架构,是基于冯诺依曼体系架构的。x86_64 Linux可以理解为在普通台式机上安装的Linux操作系统。 AArch64是一种ARMv8架构,也是一种计算机的体系架构。AArch64 Linux可以理解为在ARMv8架构的计算机上安装的Linux操作系统。
使用arch或者uname -a可查看Linux版本

安装 Java环境

解压

1
tar -zxvf jdk-8u161-linux-x64.tar.gz

配置环境变量

1
vim /etc/profile

在文件的最下面添加

1
2
3
4
export JAVA_HOME=/source/java/jdk1.8.0_161 #你自己的安装路径
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

执行下面这个命令才能生效

1
. /etc/profile

执行完成后就可以使用

1
java -version

安装 Redis

首先将下载的安装包上传的的Linux下,获取官网的的的Redis的对应版本的链接,使用了wget的命令都可以的。

由于redis的的是由Ç语言开发的,所以要安装一下GCC的编译环境。(使用Yum在线安装)

yum install -y gcc

检查一下是否安装成功了.
rpm -qa |grep gcc

然后解压到指定的目录(这里没有指定解压目录,就是当前所在目录)

wget http://download.redis.io/releases/redis-3.0.0.tar.gz

tar -zxvf redis-3.0.0.tar.gz

进入到指定刚才解压的目录里面

cd redis-3.0.0

然后就是编译了

使用 make命令.

make

接下来将redis的的安装到指定的目录里面(下面的那个redis的的不需要提前创建的)

使用PREFIX = / usr / local / src / redis安装至指定目录里面.

make install PREFIX=/usr/local/src/redis

来到在/ usr / local / src/ redis的目录下

进入仓目录里面发现没有redis.conf的配置文件。

将Redis的的-3.0.0的目录下的redis.conf复制到刚才的仓目录下的。

cp redis.conf /usr/local/src/redis/bin

cd /usr/local/src/redis/bin

接下来就是启动的Redis的了的.Redis的启动的有前台启动和后台启动的两种方式的。

首先介绍一下前台启动:

cd bin

./redis-server

前台启动的弊端:这个窗口不能关闭的如果关闭了Redis的的服务就关闭了的。

修改redis.conf下的配置文件

vim redis.conf
将 daemonize修改为yes,有些版本是true

后台启动:BIN目录下。
./redis-server ./redis.conf

查看启动进程:(挂载配置文件)
ps -ef | grep -i redis

redis允许远程访问
打开redis.conf文件在NETWORK部分有说明
bind 0.0.0.0

#requirepass foobared 去掉 # 号变requirepass foobared ,注:foobared是密码;

安装 MySQL 8.0.26

官方网站下载 MySQL 8.0.26 安装包,下载地址:

https://downloads.mysql.com/archives/community

  • 下载

需要注意:Linux操作系统是32位还是64位,本案例采用Linux 64位操作系统进行讲解,通过wget命令下载安装包。
[root@VM-0-4-centos home]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

  • 解压缩文件

解压 mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz 文件,使用tar -xvf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz 命令。

  • 移动文件

将压缩包移动到usr/local目录下,并重命名文件为mysql,使用mv /home/mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/mysql命令。

1
2
3
4
5
6
7
8
[root@VM-0-4-centos home]# mv mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/mysql
[root@VM-0-4-centos home]# cd /usr/local/mysql/
[root@VM-0-4-centos mysql]# ls
bin docs include lib LICENSE man README share support-files
[root@VM-0-4-centos mysql]# cd ..
[root@VM-0-4-centos local]# ls
bin etc games include lib lib64 libexec mysql qcloud sbin share src yd.socket.server
[root@VM-0-4-centos local]#
  • 创建数据存放目录

在mysql根目录下新建一个目录data,主要用于存放数据库数据文件,使用mkdir data命令。
创建数据存放目录

1
2
3
4
5
[root@VM-0-4-centos local]# cd mysql/
[root@VM-0-4-centos mysql]# mkdir data
[root@VM-0-4-centos mysql]# ls
bin data docs include lib LICENSE man README share support-files
[root@VM-0-4-centos mysql]#
  • 创建用户组和用户

创建mysql用户组和mysql用户,使用groupadd mysql和useradd -g mysql mysql命令。

1
2
[root@VM-0-4-centos mysql]# groupadd mysql
[root@VM-0-4-centos mysql]# useradd -g mysql mysql
  • 改变mysql目录权限
    修改mysql目录权限,可以使用chown -R mysql.mysql /usr/local/mysql/命令。

  • 数据库初始化

数据库初始化./bin/mysqld –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data –initialize命令,得到临时密码。

1
2
3
4
5
6
7
8
[root@VM-0-2-centos mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2022-01-16T07:32:18.729960Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2022-01-16T07:32:18.729960Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.26) initializing of server in progress as process 7691
2022-01-16T07:32:18.740975Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-01-16T07:32:19.800287Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-01-16T07:32:21.721672Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-01-16T07:32:21.722106Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-01-16T07:32:21.787669Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: j-6lA2aXv=Pz

需要注意:记录一下mysql数据库的临时密码 j-6lA2aXv=Pz,后面安装步骤是需要使用的

  • 修改my.cnf文件

修改my.cnf文件,使用vim /etc/my.cnf命令。

1
2
3
4
5
6
7
8
9
10
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /usr/local/mysql/mysql.sock
character-set-server=utf8
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
socket = /usr/local/mysql/mysql.sock
default-character-set=utf8
  • 创建mysql服务

1)将mysql.server启动文件复制到/etc/init.d目录,使用cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld命令。
2)赋予权限,使用chmod +x /etc/rc.d/init.d/mysqld命令;
3)使用chkconfig –add mysqld创建mysql服务。

1
2
3
[root@VM-0-4-centos mysql]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@VM-0-4-centos mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@VM-0-4-centos mysql]# chkconfig --add mysqld

检查mysql服务是否生效,使用chkconfig –list mysqld命令。

  • 配置全局环境变量

编辑/etc/profile文件,使用vim /etc/profile命令,在profile文件中添加如下两行配置,使用:wq命令保存后退出。

1
2
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
export PATH

设置环境变量立即生效使用source /etc/profile命令。

1
2
[root@VM-0-4-centos ~]# source /etc/profile
[root@VM-0-4-centos ~]#
  • 启动mysql服务
    启动mysql服务,使用service mysql start命令;使用service mysql status命令,查看是否启动成功。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    [root@VM-0-4-centos ~]# service mysql start
    Redirecting to /bin/systemctl start mysql.service
    [root@VM-0-4-centos ~]# service mysql status
    Redirecting to /bin/systemctl status mysql.service
    ● mysqld.service - LSB: start and stop MySQL
    Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
    Active: active (running) since Sun 2022-01-16 17:17:55 CST; 8s ago
    Docs: man:systemd-sysv-generator(8)
    Process: 27231 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
    CGroup: /system.slice/mysqld.service
    ├─27242 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/VM-0-4-centos.pid
    └─27408 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=VM-0-4-cent...

    Jan 16 17:17:54 VM-0-4-centos systemd[1]: Starting LSB: start and stop MySQL...
    Jan 16 17:17:54 VM-0-4-centos mysqld[27231]: Starting MySQL.Logging to '/usr/local/mysql/data/VM-0-4-centos.err'.
    Jan 16 17:17:55 VM-0-4-centos mysqld[27231]: SUCCESS!
    Jan 16 17:17:55 VM-0-4-centos systemd[1]: Started LSB: start and stop MySQL.
  • 登录mysql修改密码
    登录mysql数据库,使用mysql -uroot -p密码命令,临时密码是j-6lA2aXv=Pz。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    [root@VM-0-4-centos ~]# mysql -uroot -p
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 13
    Server version: 8.0.26

    Copyright (c) 2000, 2021, Oracle and/or its affiliates.

    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    mysql>

修改mysql临时密码,也就是将第七步数据库初始化生成的临时密码修改成自己需要设置的密码。

修改mysql数据库密码,使用ALTER USER ‘root‘@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘123456’;命令。

1
2
3
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)
mysql>

注意:此处123456修改为自己的需要密码即可。

  • 设置mysql远程登录

1)切换数据库,使用use mysql;命令。

2)修改mysql库中host值,使用update user set host=’%’ where user=’root’ limit 1;命令。

3)刷新mysql权限,使用flush privileges;命令。

1
2
3
4
5
6
7
8
9
10
11
12
13
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host='%' where user='root' limit 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>

安装 nginx

  • 依赖下载

yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

  • 下载

wget http://nginx.org/download/nginx-1.25.1.tar.gz

  • 解压包,并转换到nginx文件夹下

tar -zxf nginx-1.25.1.tar.gz
cd nginx-1.25.1

  • 配置nginx

./configure

  • 出现下述画面即成功
1
2
3
4
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
  • 编译安装nginx

make&&make install

  • 出现情况即成功

nake[1]: Leaving directory '/usr/java/nginx-1.25

  • 运行

cd /usr/local/nginx/sbin
./nginx

重启
./nginx -s reload

nginx 配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
worker_processes  1;

events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;


sendfile on;

keepalive_timeout 65;

server {
listen 80;
server_name localhost;

location / {
root html;
index index.html index.htm;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

server {
listen 70;
server_name location;

location / {
root /AAtest/web/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}

location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

}

}
  • 主要说明

端口号
listen 70;

服务器ip地址
server_name location;

/prod-api/ 是前端路径
location /prod-api/

8080是后端端口
proxy_pass http://localhost:8080/;

安装docker

  • 查看是否已安装
    docker –version

有返回信息 就需要卸载

  • 卸载命令
1
2
3
4
5
6
7
8
9
10
11
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine \
docker-ce
  • 更新你的包列表

sudo yum update
安装必要的包,这些包可以让yum使用HTTPS:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

  • 添加Docker的存储库

    sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    如果失败试一下下面这个命令,未失败直接进行下一步

    1
    2
    3
    4
    5
    6
    7
    8
    # 设置docker镜像源
    yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

    sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo

    yum makecache fast
  • 安装Docker

sudo yum install docker-ce
启动Docker服务:
sudo systemctl start docker
设置Docker服务开机自启
sudo systemctl enable docker
验证Docker是否安装成功
sudo docker run hello-world

第一步:配置加速地址:设置registry mirror

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://do.nark.eu.org",
"https://dc.j8.work",
"https://docker.m.daocloud.io",
"https://dockerproxy.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn"
]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
systemctl status docker

第二步:重启完docker之后检查registry mirror刚刚配置的加速地址是否成功,最尾部有刚刚添加地链接
docker info

再尝试运行helloworld

安装gitea

官方文档
https://docs.gitea.com/zh-cn/installation/install-with-docker

首先创建一个 gitea 工作目录,后续工作都在这个目录下完成。
mkdir ~/gitea && cd ~/gitea

预先创建 data 和 config 目录,稍后用于数据挂载
mkdir data config
chown 1000:1000 data config

创建 docker-compose.yml
使用下面的模板创建 docker-compose.yml,这里使用到的镜像是 gitea/gitea:1.17.2-rootless

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
version: "3"

services:
server:
image: gitea/gitea:1.17.2-rootless
container_name: gitea
restart: always
volumes:
- ./data:/var/lib/gitea
- ./config:/etc/gitea
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "2222:2222"

参数解析

volumes:数据挂载

./data:/data,将主机当前目录下的 data 目录挂载到容器内的 /var/lib/gitea 目录。/data 是 Gitea 标准容器的数据存储点,包含了 Git 仓库、SQLite 数据库文件、缓存文件等。
./config:/etc/gitea 挂载 Gitea 的 app.ini 配置文件所在的目录。
/etc/timezone:/etc/timezone:ro 用于指定时区
/etc/localtime:/etc/localtime:ro 同上,用于指定本地时间

ports:端口映射

3000:3000 HTTP 端口,从左到右的顺序是从主机映射到 Docker 容器。在此,您可以通过 http://127.0.0.1:3000 直接访问到 Gitea 的 Web 界面,或通过反向代理引擎提供更具有扩展性的 SSL 集成,例如 Nginx。
2222:2222 SSH 端口。这里主机侧暴露的端口为 2222 避免了与默认 SSH 服务端口冲突。禁用 SSH 时删除端口转发即可。如果您希望将主机完全作为 Gitea 服务器,可以将主机配置文件 /etc/ssh/sshd_config 中的端口 Port 22 更改为其他值,使得 Docker 可以使用 Gitea 内建的 Go SSH 或 OpenSSH 占用 22 端口作为 Git 服务。

启动 Gitea 实例

使用 docker compose 命令拉取镜像并启动 Gitea 实例:
docker compose up -d

docker compose ps 查看容器

1
2
3
WARN[0000] /root/gitea/docker-compose.yml: `version` is obsolete 
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
gitea gitea/gitea:1.17.2-rootless "/usr/local/bin/dock…" server 3 days ago Up 3 days 0.0.0.0:2222->2222/tcp, :::2222->2222/tcp, 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp

docker compose logs -f 查看容器日志:
当看到上述日志的时候可以认为实例已经启动了,在浏览器中输入 http://localhost:3000/ 即可登陆 Gitea 实例进行初始化设置。

启动脚本

sh ./run.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
NAME="ruoyi-admin.jar"
echo"服务名:$NAME"
ID=`ps -ef|grep "$NAME" grep |grep -v "$0" | grep -v "grep" | awk '{print $2}'`
echo $ID
echo "----------"
for id in $ID
do
kill -9 $id
echo "kill $id"
done
echo "killed all ruoyi-admin.jar process"
java -jar -Xms5120m -Xmx512m ruoyi-admin.jar --spring.profiles.active=test > ruoyi-admin.log 2>&1 &
echo "ruoyi-admin service started"