Centos 7.9 服务器环境搭建

Centos 7.9 服务器环境搭建
1、Linux
# 查看防火墙状态
systemctl status firewalld

# 查看已开放端口命令
firewall-cmd --list-all

# 开放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent

# 关闭端口
firewall-cmd --zone=public --remove-port=3306/tcp --permanent

# 开放端口后需要重新加载防火墙
firewall-cmd --reload
目录
/bin 存放二进制可执行文件(ls,cat,mkdir等),常用命令一般都在这里。
/etc 存放系统管理和配置文件
/home 存放所有用户文件的根目录,是用户主目录的基点,比如用户user的主目录就是/home/user,可以用~user表示
/usr 用于存放系统应用程序,比较重要的目录/usr/local 本地系统管理员软件安装目录(安装系统级的应用)。这是最庞大的目录,要用到的应用程序和文件几乎都在这个目录。
/opt 额外安装的可选应用程序包所放置的位置。一般情况下,我们可以把tomcat等都安装到这里。
/proc 虚拟文件系统目录,是系统内存的映射。可直接访问这个目录来获取系统信息。
/root 超级用户(系统管理员)的主目录(特权阶级o)
/sbin 存放二进制可执行文件,只有root才能访问。这里存放的是系统管理员使用的系统级别的管理命令和程序。如ifconfig等。
/dev 用于存放设备文件。
/mnt 系统管理员安装临时文件系统的安装点,系统提供这个目录是让用户临时挂载其他的文件系统。
/boot 存放用于系统引导时使用的各种文件
/lib 存放跟文件系统中的程序运行所需要的共享库及内核模块。共享库又叫动态链接共享库,作用类似windows里的.dll文件,存放了根文件系统程序运行所需的共享文件。
/tmp 用于存放各种临时文件,是公用的临时文件存储点。
/var 用于存放运行时需要改变数据的文件,也是某些大文件的溢出区,比方说各种服务的日志文件(系统启动日志等。)等。
/lost+found 这个目录平时是空的,系统非正常关机而留下“无家可归”的文件(windows下叫什么.chk)就在这里
2、宝塔面板
# 安装命令
yum install -y wget && wget -O install.sh https://download.bt.cn/install/install_6.0.sh && sh install.sh ed8484bec
3、JDK

上传 JDK 包,如 jdk-8u202-linux-x64.tar.gz

# 解压
tar -zxvf jdk-8u202-linux-x64.tar.gz

# 配置环境变量
vim /etc/profile

export JAVA_HOME=/usr/env/jdk/jdk1.8.0_202
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

# 生效命令
source /etc/profile
4、MySQL
# 下载安装包
wget https://dev.mysql.com/get/Downloads/MySQL-8.2/mysql-8.2.0-1.el7.x86_64.rpm-bundle.tar

# 解压
tar -xvf mysql-8.2.0-1.el7.x86_64.rpm-bundle.tar

# 安装
rpm -ivh mysql-community-common-8.2.0-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-libs-8.2.0-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-client-8.2.0-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-server-8.2.0-1.el7.x86_64.rpm --nodeps --force

# 查询是否安装成功
rpm -qa|grep mysql

# 安装成功
[root@lavm-8iaicsw6v3 mysql]# rpm -qa|grep mysql
mysql-community-common-8.2.0-1.el7.x86_64
mysql-community-libs-8.2.0-1.el7.x86_64
mysql-community-server-8.2.0-1.el7.x86_64
mysql-community-client-8.2.0-1.el7.x86_64

# 修改 my.inf
vim /etc/my.cnf

## my.inf
-------------------------------------------------------------------
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8mb4
 
[mysql]
default-character-set=utf8mb4
no-auto-rehash
 
[mysqld]
port=3306
 
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
 
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
init_connect='SET NAMES utf8mb4'
 
lower_case_table_names=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
 
skip-external-locking
skip_name_resolve
max_connect_errors=10
 
slow_query_log=on
long_query_time=3
slow_query_log_file=/var/log/slowsql.log
 
key_buffer_size=128M
read_buffer_size=1M
read_rnd_buffer_size=2M
max_allowed_packet=1M
table_open_cache=64
sort_buffer_size=512K
net_buffer_length=8K
 
default_storage_engine=InnoDB
innodb_buffer_pool_size=1024M
innodb_flush_log_at_trx_commit=2
innodb_log_file_size=256M
innodb_log_buffer_size=8M
innodb_log_files_in_group=3
innodb_lock_wait_timeout=50
-------------------------------------------------------------------

# 创建慢日志文件
touch /var/log/slowsql.log
chown mysql:mysql /var/log/slowsql.log
chmod 664 /var/log/slowsql.log

# 初始化
## 赋权限
chown -R mysql:mysql /var/lib/mysql
cat /etc/passwd
chmod -R 755 /var/lib/mysql

## mysql初始化
mysqld --user=mysql --initialize
-------------------------------------------------------------------
报错:
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

安装libaio:
yum install -y libaio
-------------------------------------------------------------------

## 查看随机密码
cat /var/log/mysqld.log | grep password

2024-01-12T07:38:37.325515Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: eAF00Rhnkh>&

# 启动 mysql
systemctl start mysqld

# 查看启动状态
systemctl status mysqld

# 登录 mysql
mysql -uroot -p xxx

# 修改登录密码
alter user 'root'@'localhost' identified by 'xxxx';

# 创建远程登录用户以及设置密码
create user 'admin'@'%' identified by '2233';

# 赋权限
grant all privileges on *.* to 'admin'@'%' with grant option;
flush privileges;

# 删除安装包
rm -rf /xxx

# 查看是否开机自启动命令
service mysqld status

[root@lavm-8iaicsw6v3 mysql]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2024-01-12 15:42:45 CST; 11min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 26967 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 26992 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─26992 /usr/sbin/mysqld

Jan 12 15:42:44 lavm-8iaicsw6v3 systemd[1]: Starting MySQL Server...
Jan 12 15:42:45 lavm-8iaicsw6v3 systemd[1]: Started MySQL Server.

# 修改默认端口
## 停止 mysql
systemctl stop mysqld
## 修改 my.cnf
vim /etc/my.cnf
-------------------------------------------------------------------
port=3307
-------------------------------------------------------------------
## 启动 mysql
systemctl start mysqld
5、Redis
# 下载安装包
wget https://github.com/redis/redis/archive/7.2.4.tar.gz

# 解压
tar -zvxf 7.2.4.tar.gz

# 安装 gcc
yum install gcc-c++

# 编译
cd /usr/env/redis/redis-7.2.4
make

# 安装
make PREFIX=/usr/env/redis install

# 修改 redis.conf
vim /redis.conf
-------------------------------------------------------------------
port 16379
requirepass 123321
bind 0.0.0.0
daemonize yes
protected-mode no
-------------------------------------------------------------------

# 启动 redis
cp /usr/env/redis/redis-7.2.4/redis.conf ./redis.conf
./redis-server redis.conf

[root@lavm-8iaicsw6v3 bin]# ./redis-server redis.conf
8023:C 12 Jan 2024 17:32:55.904 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

# 关闭 redis
./redis-cli -p 6379
shutdown
6、Nacos
# 下载安装包
wget https://github.com/alibaba/nacos/releases/download/2.0.2/nacos-server-2.0.2.tar.gz

# 解压
tar -zxvf nacos-server-2.0.2.tar.gz

# 安装 mysql,执行 /usr/env/nacos/nacos-2.0.2/conf/nacos-mysql.sql
...

# 修改 application.properties
vim /usr/env/nacos/nacos-2.0.2/conf/application.properties
-----------------------------------------------------------------------------
### If use MySQL as datasource:
spring.datasource.platform=mysql
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=nacos
db.password.0=nacos
-----------------------------------------------------------------------------
# 单机启动(bin目录)
sh startup.sh -m standalone

[root@lavm-8iaicsw6v3 bin]# sh startup.sh -m standalone
/usr/env/jdk/jdk1.8.0_202/bin/java  -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Djava.ext.dirs=/usr/env/jdk/jdk1.8.0_202/jre/lib/ext:/usr/env/jdk/jdk1.8.0_202/lib/ext -Xloggc:/usr/env/nacos/nacos-2.0.2/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -Dloader.path=/usr/env/nacos/nacos-2.0.2/plugins/health,/usr/env/nacos/nacos-2.0.2/plugins/cmdb -Dnacos.home=/usr/env/nacos/nacos-2.0.2 -jar /usr/env/nacos/nacos-2.0.2/target/nacos-server.jar  --spring.config.additional-location=file:/usr/env/nacos/nacos-2.0.2/conf/ --logging.config=/usr/env/nacos/nacos-2.0.2/conf/nacos-logback.xml --server.max-http-header-size=524288
nacos is starting with standalone
nacos is starting,you can check the /usr/env/nacos/nacos-2.0.2/logs/start.out

# 查看启动日志
cat /usr/env/nacos/nacos-2.0.2/logs/start.out

# 关闭 nacos(bin目录)
sh shutdown.sh
7、Nginx
# 下载安装包
wget https://nginx.org/download/nginx-1.24.0.tar.gz

# 解压
tar -zxvf nginx-1.24.0.tar.gz

# 配置configure
## --prefix 代表安装的路径,--with-http_ssl_module 安装ssl,--with-http_stub_status_module查看nginx的客户端状态
./configure --prefix=/usr/env/nginx/nginx-1.24.0 --with-http_ssl_module --with-http_stub_status_module

# 编译并安装
make & make install 

# 启动 nginx
## 如果没有logs目录,需手动创建
./sbin/nginx

# 重启 nginx
./sbin/nginx -s reload

你可能感兴趣的:(Linux,服务器,centos,linux)