一、服务器
1、查看服务器版本
查看服务器版本为20.04
lsb_release -a
2、服务器信息
服务器初始账号密码 sxd / 123456
首先,更改自身密码都输入123456
sudo passwd
创建最高权限root账号,密码为 123456
su root
3、更新服务器源
1、更新源列表
sudo apt-get update
2、安装 openssh-server和vim
途中输入y
sudo apt-get install openssh-server
apt install vim
安装ssh后可通过ssh软件连接服务器,首先获取自身ip为192.168.220.143
ip a
3、通过finalshell连接服务器
登录ssh后将用户切换到root用户
su root
4、默认创建文件夹权限
使创建的文件夹默认权限为读写,编辑bashrc
vim ~/.bashrc
source ~/.bashrc
软件安装
1、安装jdk
下载以及配置
cd /usr/local/
mkdir java
cd java/
上传jdk-8u391-linux-x64.tar.gz或者 下载jdk
wget https://www.oracle.com/webapps/redirect/signon?nexturl=https://download.oracle.com/otn/java/jdk/8u401-b10/4d245f941845490c91360409ecffb3b4/jdk-8u401-linux-x64.tar.gz
由于下载版本不同,根据版本更改文件夹名称
#解压jdk
tar -zxvf jdk-8u391-linux-x64.tar.gz
#配置环境变量
chmod 777 /etc/profile
vim /etc/profile
在最后一行输入以下内容
JAVA_HOME=/usr/local/java/jdk1.8.0_391
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
执行命令并查看jdk版本是否安装成功
source /etc/profile
java -version
设置jdk开机自动识别
cd ~
vim .bashrc
JAVA_HOME=/usr/local/java/jdk1.8.0_391
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
source .bashrc
2、安裝mysql8.0
安装并且启动
#安装mysql
sudo apt-get install mysql-server
#获取mysql状态
service mysql status
#停止mysql
service mysql stop
#启动mysql
service mysql start
#开机自启mysql
systemctl enable mysql
进入mysql,需要密码的话回车跳过
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
flush privileges;
#更改root连接权限
use mysql;
update user set host='%' where user = 'root';
flush privileges;
配置mysq连接
设置mysql允许其他用户访问,打开文件注释掉bind-address=127.0.0.1
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
设置模式
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
重启mysql服务
service mysql restart
通过数据连接软件测试数据库是否连接成功
3、安装redis
下载及配置
#下载并解压压缩包
cd /usr/local
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
tar -zxvf redis-6.2.6.tar.gz
mv redis-6.2.6 redis
cd redis
#安装编译环境
sudo apt install build-essential -y
sudo make -j4
#安装redis
sudo make PREFIX=/usr/local/redis install
#设置redis文件权限
chmod -R 777 /usr/local/redis
如果执行命令 sudo make 出现错误:
cd src && make all
make[1]: 进入目录“/usr/local/redis-7.0.10/src”
CC adlist.o
In file included from adlist.c:34:
zmalloc.h:50:10: fatal error: jemalloc/jemalloc.h: 没有那个文件或目录
50 | #include <jemalloc/jemalloc.h>
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [Makefile:403:adlist.o] 错误 1
make[1]: 离开目录“/usr/local/redis-7.0.10/src”
make: *** [Makefile:6:all] 错误 2
针对上述错误,执行如下命令重新编译。
sudo make MALLOC=libc
执行如下命令将 redis-server 和 redis-cli 放置到系统路径(/usr/bin)下。
ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis-cli
ln -s /usr/local/redis/bin/redis-server /usr/bin/redis-server
设置redis配置文件 vim redis.conf
#(1)修改 1
# 注释掉 bind 127.0.0.1 -::1 允许远程连接
#bind 127.0.0.1 -::1
bind 0.0.0.0
# (2)修改2
# 将 daemonize no 修改为 daemonize yes,设置后台运行
daemonize yes
# (3)修改3
# 指定 log 文件路径
logfile "/var/log/redis-server.log"
#启动redis服务
sudo redis-server /usr/local/redis/redis.conf
#查看redis是否运行
ps -ef | grep redis
启动客户端,执行指令如果设置了密码 执行auth +密码再执行
开机自启动
拷贝启动脚本 redis_init_script 到目录 /etc/init.d/redis 下,并编辑配置文件。
sudo cp /usr/local/redis/utils/redis_init_script /etc/init.d/redis
vim /etc/init.d/redis
创建配置文件,使其开机自启
sudo mkdir /etc/redis
sudo cp /usr/local/redis/redis.conf /etc/redis/6379.conf
sudo update-rc.d -f redis defaults
systemctl start redis
systemctl status redis
通过redis客户端软件测试
4、安裝minio
下载及配置
# 创建minio应用程序目录
mkdir -p /usr/local/minio/bin
# 创建minio数据目录
mkdir -p /usr/local/minio/data
# 创建minio日志目录
mkdir -p /usr/local/minio/logs
#将软件下载
cd /usr/local/minio/bin
# 下载服务端
wget https://dl.min.io/server/minio/release/linux-amd64/minio
# 将下载所得minio文件拷贝到指定文件夹并赋权
sudo chmod +x /usr/local/minio/bin/minio
测试执行minio
MINIO_ROOT_USER=myname
MINIO_ROOT_PASSWORD=mypassword
nohup /usr/local/minio/bin/minio server /usr/local/minio/data --console-address ":7047" --address ":7048" > /usr/local/minio/logs/minio.log 2>&1 &
sudo minio server /usr/local/minio/data --console-address ":7047" --address ":7048" > /usr/local/minio/logs/minio.log 2>&1 &
配置minio
创建minio配置文件
sudo vim /etc/default/minio
# 指定数据存储目录(注意:这个目录要存在且拥有相对应的权限)
MINIO_VOLUMES="/usr/local/minio/data"
# 监听端口
MINIO_OPTS="--address :7048 --console-address :7047"
# 新版本使用;指定默认的用户名和密码,其中用户名必须大于3个字母,否则不能启动
MINIO_ROOT_USER="myname"
MINIO_ROOT_PASSWORD="mypassword"
# 区域值,标准格式是“国家-区域-编号”,
MINIO_REGION="cn-north-1"
创建服务
sudo vim /usr/lib/systemd/system/minio.service
[Unit]
Description=MinIO
Documentation=https://docs.min.io
Wants=network-online.target
After=network-online.target
AssertFileIsExecutable=/usr/local/minio/bin/minio
[Service]
WorkingDirectory=/usr/local/minio/
ProtectProc=invisible
# 指向3.1节中的配置文件
EnvironmentFile=/etc/default/minio
ExecStartPre=/bin/bash -c "if [ -z \"${MINIO_VOLUMES}\" ]; then echo \"Variable MINIO_VOLUMES not set in /etc/default/minio\"; exit 1; fi"
ExecStart=/usr/local/minio/bin/minio server $MINIO_OPTS $MINIO_VOLUMES
# Let systemd restart this service always
Restart=always
# Specifies the maximum (1M) file descriptor number that can be opened by this process
LimitNOFILE=1048576
# Specifies the maximum number of threads this process can create
TasksMax=infinity
# Disable timeout logic and wait until process is stopped
TimeoutStopSec=infinity
SendSIGKILL=no
SuccessExitStatus=0
[Install]
WantedBy=multi-user.target
Alias=minio.service
通过systemctl将服务生效并启动服务
# 重新加载服务配置文件,使服务生效
systemctl daemon-reload
# 将服务设置为开机启动
systemctl enable minio
# 服务立即启动
systemctl start minio
# 查看minio服务当前状态
systemctl status minio
点击Create Bucket并输入teaching
进入teaching,点击Access Policy设置成public,点击Anonymous 设置下图可读写
5、安装nacos
下载nacos
速度比较慢
/usr/local
wget https://github.com/alibaba/nacos/releases/download/2.3.1/nacos-server-2.3.1.tar.gz
mv nacos-server-2.3.1 nacos
#设置nacos文件夹权限
chmod -R 777 /usr/local/nacos
#创建nacos服务
sudo vim /usr/lib/systemd/system/nacos.service
文件配置
[Unit]
Description=nacos
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nacos/bin/startup.sh -m standalone
ExecReload=/usr/local/nacos/bin/shutdown.sh
ExecStop=/usr/local/nacos/bin/shutdown.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
配置nacos启动项配置
vim /usr/local/nacos/bin/startup.sh
将修改jdk配置并注释其他三行
调用nacos服务
systemctl daemon-reload # 重新加载服务配置
systemctl enable nacos.service # 设置为开机启动
systemctl is-enabled nacos.service # 查看是否开机启动
systemctl start nacos.service # 启动nacos服务
systemctl stop nacos.service # 停止nacos服务
systemctl status nacos.service # 查看nacos服务状态
访问 http://192.168.220.143:8848/nacos
6、安装nginx
安装所需编译包
cd /usr/local
#安装编译用的组件包
sudo apt-get install libxml2-dev build-essential openssl libssl-dev make curl libcurl4-gnutls-dev libjpeg-dev libpng-dev libtool-bin bison zlib1g-dev libpcre3 libpcre3-dev libssl-dev libxslt1-dev libgeoip-dev libgoogle-perftools-dev libperl-dev libtool
#从远程下载文件
c
#解压文件到 /usr/local 目录
tar -xvf nginx-1.20.1.tar.gz -C /usr/local
cd /usr/local/nginx-1.20.1
#进入目录并执行命令
sudo ./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \--with-http_stub_status_module \--with-http_ssl_module \--with-file-aio \--with-http_realip_module
#创建临时目录
mkdir /var/temp/nginx -p
#进行编译和安装
cd /usr/local/nginx-1.20.1
sudo make
sudo make install
#安装结束后可删除nginx-1.20.1
rm -rf /usr/local/nginx-1.20.1
cd /usr/local/nginx
#安装后目录为 /usr/local/nginx
创建pid文件
mkdir /usr/local/nginx/logs
touch nginx.pid
配置nginx pid文件,將pid改为
pid /usr/local/nginx/logs/nginx.pid;
vim /usr/local/nginx/conf/nginx.conf
配置nginx服务
vim /etc/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
#请确认相关命令是否可执行
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#重载系统服务
systemctl daemon-reload
#测试 服务是否生效
systemctl start nginx.service
# 设置服务为开机启动服务
systemctl enable nginx.service
#开机服务查询
systemctl list-units --type=service
7、开机自启jar包
1、创建脚本
cd /etc/init.d/
vim startServer.sh
2、脚本配置项
nohup java -jar /opt/web/a.jar &
nohup java -jar /opt/web/a.jar &
tail -f /opt/web/nohup.out
echo "---------TeachingServer is running"
3、赋予脚本权限:
chomd 755 /etc/init.d/startServer.sh
4、添加到启动脚本中,在init.d目录下执行
update-rc.d startServer.sh defaults 90
如果需要移除输入update-rc.d startServer.sh remove
5.重启生效
reboot