服务器环境搭建(非docker)

67 阅读2分钟

1、安装jdk

更新软件源

sudo apt-get update

搜索jdk

sudo apt search openjdk

安装 OpenJDK 8

sudo apt install openjdk-jdk8

查看是否安装成功

java -version

2、安装mysql

参考了:blog.csdn.net/u014378628/…

注意:Ubuntu20.0.4后默认的 mysql 是 mysql8,可以直接安装

安装mysql8

apt install mysql-server

查看mysql 服务状态

systemctl status mysql

查看版本

mysql --version

linux中在 mysql8 后,mysql 的 root 登录方式是使用系统身份登录认证,可以看到 root 账户的 plugin是 auth_socket。auth_socket 是 MySQL 的一种用户身份验证插件,它是基于系统用户的身份进行认证的。当使用 auth_socket 插件时,MySQL 将使用操作系统的用户和组信息来检查用户是否有权限访问 MySQL 服务器。

具体来说,如果一个 MySQL 用户账户使用 auth_socket 插件进行身份验证,则只有拥有该用户账户同名的系统用户才能登录到 MySQL 服务器。

root@iZ7xvcns9k722thqiufsvnZ:/home/laibin# mysql --version
mysql  Ver 8.0.35-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
root@iZ7xvcns9k722thqiufsvnZ:/home/laibin# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.35-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2023, 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> 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> use mysql;
Database changed
mysql> SELECT user, authentication_string, plugin FROM mysql.user;
+------------------+------------------------------------------------------------------------+-----------------------+
| user             | authentication_string                                                  | plugin                |
+------------------+------------------------------------------------------------------------+-----------------------+
OGEo6psMPIlPidMxoXLDQ5sel2lTVb8ZeY0k5QiEP61 | caching_sha2_password |
| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| root             |                                                                        | auth_socket           |
+------------------+------------------------------------------------------------------------+-----------------------+
5 rows in set (0.00 sec)

我们需要修改root的加密规则,将其改为密码登录,其中 new_password 是自己想设置的代码。

ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'new_password';

退出后即可使用密码登录了,后面就可以在代码里面使用账号密码进行连接数据库了,但是需要其他账号的话需要自己新建。

mysql -u root -p

默认情况下,mysql服务器监听本地回环地址(127.0.0.1),如果需要从其他计算机连接,需要将其更改为适当的 IP 地址。

vim /etc/mysql/mysql.conf.d/mysqld.cnf

在该文件中修改 bind-address 字段

bind-address= 127.0.0.1 修改为 bind-address= 0.0.0.0

root 用户启用 GRANT OPTION 权限

ALTER USER 'root'@'%' WITH GRANT OPTION;

新建用户并授权远程连接数据库,对所有数据库都有增删改查创建删除功能,然后刷新权限

CREATE USER 'laibin'@'%' IDENTIFIED BY 'laibin用户密码';
GRANT ALL PRIVILEGES ON *.* TO 'laibin'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

重启服务

service mysql restart

之后用navicat等数据库可视化工具就可以连接上了,连接用户是新建的laibin。

记得要在阿里云控制台的安全组开放3306端口。

3、安装redis

更新数据源

apt update

查询redis-server

apt search redis-server

安装redis-server

apt install redis-server

安装完成后,Redis 会自动启动。你可以使用以下命令检查 Redis 是否正在运行:

systemctl status redis

连接 redis

redis-cli

远程连接redis,将bind 127.0.0.1 ::1 ,改为bind 0.0.0.0

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1 ::1

开放6379端口

4、安装nginx

4.1、apt包管理器下载

安装nginx

apt install nginx

安装的nginx默认在/etc目录下,静态资源在/var/www/html/,日志在/var/log/nginx/目录下

启动nginx服务

systemctl start nginx

关闭nginx服务

systemctl stop nginx

配置文件在/etc/nginx/nginx.conf,修改完后

systemctl reload nginx

4.2、官网下载

下载1.25.1

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

解压

tar -zxf nginx-1.25.1.tar.gz

检查配置,可能会缺少error: the HTTP rewrite module requires the PCRE library

.configure --- 缺少执行 apt-get install libpcre3 libpcre3-dev

编译

make&&make install

/usr/local/nginx/conf目录配置

执行启动停止操作需要进入/usr/local/nginx/sbin目录

./nginx              启动 Nginx
./nginx -s stop      停止 Nginx
./nginx -s reload    重新加载 Nginx
./nginx -v           查看 Nginx 版本

5、代理服务器

1、相关地址

2、上传

上传proxy-client-0.1.rar或者zip包,需要解压,安装unrar软件或者unzip

apt-get install unrar
或者
apt-get install unzip

然后解压

unrar x proxy-client-0.1.rar
或者
unzip proxy-client-0.1.rar

进入bin目录下,执行startup.sh文件,先给文件添加执行权限,再执行

laibin@iZ7xvcns9k722thqiufsvnZ:~/proxy-server-0.1/bin$ chmod +x startup.sh
laibin@iZ7xvcns9k722thqiufsvnZ:~/proxy-server-0.1/bin$ ./startup.sh
Starting the proxy server ...started
PID: 9659

接下来输入ip:端口输入设置的用户名密码即可访问。

端口开放可以去阿里云的云服务控制台的安全组中开放。