Centos 7.9 服務器環(huán)境搭建
1、Linux
# 查看防火墻狀態(tài)
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 | 存放二進制可執(zhí)行文件(ls,cat,mkdir等),常用命令一般都在這里。 |
/etc | 存放系統(tǒng)管理和配置文件 |
/home | 存放所有用戶文件的根目錄,是用戶主目錄的基點,比如用戶user的主目錄就是/home/user,可以用~user表示 |
/usr | 用于存放系統(tǒng)應用程序,比較重要的目錄/usr/local 本地系統(tǒng)管理員軟件安裝目錄(安裝系統(tǒng)級的應用)。這是最龐大的目錄,要用到的應用程序和文件幾乎都在這個目錄。 |
/opt | 額外安裝的可選應用程序包所放置的位置。一般情況下,我們可以把tomcat等都安裝到這里。 |
/proc | 虛擬文件系統(tǒng)目錄,是系統(tǒng)內存的映射??芍苯釉L問這個目錄來獲取系統(tǒng)信息。 |
/root | 超級用戶(系統(tǒng)管理員)的主目錄(特權階級o) |
/sbin | 存放二進制可執(zhí)行文件,只有root才能訪問。這里存放的是系統(tǒng)管理員使用的系統(tǒng)級別的管理命令和程序。如ifconfig等。 |
/dev | 用于存放設備文件。 |
/mnt | 系統(tǒng)管理員安裝臨時文件系統(tǒng)的安裝點,系統(tǒng)提供這個目錄是讓用戶臨時掛載其他的文件系統(tǒng)。 |
/boot | 存放用于系統(tǒng)引導時使用的各種文件 |
/lib | 存放跟文件系統(tǒng)中的程序運行所需要的共享庫及內核模塊。共享庫又叫動態(tài)鏈接共享庫,作用類似windows里的.dll文件,存放了根文件系統(tǒng)程序運行所需的共享文件。 |
/tmp | 用于存放各種臨時文件,是公用的臨時文件存儲點。 |
/var | 用于存放運行時需要改變數(shù)據(jù)的文件,也是某些大文件的溢出區(qū),比方說各種服務的日志文件(系統(tǒng)啟動日志等。)等。 |
/lost+found | 這個目錄平時是空的,系統(tǒng)非正常關機而留下“無家可歸”的文件(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文章來源地址http://www.zghlxwxcb.cn/news/detail-793047.html
# 解壓
tar -zxvf jdk-8u202-linux-x64.tar.gz
# 配置環(huán)境變量
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
-------------------------------------------------------------------
# 創(chuàng)建慢日志文件
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
# 查看啟動狀態(tài)
systemctl status mysqld
# 登錄 mysql
mysql -uroot -p xxx
# 修改登錄密碼
alter user 'root'@'localhost' identified by 'xxxx';
# 創(chuàng)建遠程登錄用戶以及設置密碼
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,執(zhí)行 /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的客戶端狀態(tài)
./configure --prefix=/usr/env/nginx/nginx-1.24.0 --with-http_ssl_module --with-http_stub_status_module
# 編譯并安裝
make & make install
# 啟動 nginx
## 如果沒有l(wèi)ogs目錄,需手動創(chuàng)建
./sbin/nginx
# 重啟 nginx
./sbin/nginx -s reload
文章來源:http://www.zghlxwxcb.cn/news/detail-793047.html
到了這里,關于Centos 7.9 服務器環(huán)境搭建的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!