目录
前言
一、Jdk安装
1.查看是否自带或者已安装
2.下载并上传安装包
3.解压
4.配置环境变量
二、mysql安装(8.0.21)
1.下载安装包
2.上传&解压
3.安装
4.启动等操作
5.初始化MySQL数据库
三、nacos安装
1.下载解压、上传到服务器上
2.nacos配置持久化
3.Nacos配置
4.开放nacos端口号
5.nacos启动
注意:如果链接的数据库是阿里云的RDS,则需要开启服务白名单,不开启的话,启动不会报错,nacos连接到是内置的数据库。
四、seate安装
1.下载解压、上传到服务器上
2.Seata配置持久化
3.Seata配置
4.使用脚本在 nacos中生成Seata配置文件
注意:如果链接的数据库是阿里云的RDS,则需要开启服务白名单
五、redis安装
五、nginx安装
1、下载解压、上传到服务器上
2、Nginx 配置
3、启动 Nginx
前言
数据库最好使用8.0以上的
一、Jdk安装
1.查看是否自带或者已安装
$java -version
2.下载并上传安装包
方式一:ftp上传(推荐)
下载地址:Java Downloads | Oracle
下载完后用FileZilla文件传输器,把jdk安装包传到虚拟机对应的文件夹当中
方式二:wget 网址
在线下载JDK安装包,下载到 /usr/local/目录下存jdk压缩包
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" /otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm
3.解压
$tar -zxvf jdk-8u131-linux-x64.tar.gz
z :表示 tar 包是被 gzip 压缩过的 (后缀是.tar.gz),所以解压时需要用 gunzip 解压 (.tar不需要)
x :表示 从 tar 包中把文件提取出来
v :表示 显示打包过程详细信息
f :指定被处理的文件是什么
4.配置环境变量
打开环境变量配置$vim /etc/profile#jdk环境变量export JAVA_HOME=/usr/java/jdk1.8.0_141export JRE_HOME=${JAVA_HOME}/jreexport CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATHexport JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/binexport PATH=$PATH:${JAVA_PATH}重新加载环境变量$source /etc/profile
二、mysql安装(8.0.21)
1.下载安装包
下载地址:MySQL :: Download MySQL Community Server (Archived Versions)
2.上传&解压
tar -xvf mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar
3.安装
执行命令yum localinstall *.rpm
4.启动等操作
管理MySql服务systemctl start mysqldsystemctl stop mysqldsystemctl restart mysqldsystemctl status mysqld#设置开机启动systemctl enable mysqldsystemctl daemon-reload
放防火墙端口firewall-cmd --query-port=3306/tcpfirewall-cmd --zone=public --add-port=3306/tcp --permanentfirewall-cmd --reload
5.初始化MySQL数据库
①生成默认密码
#默认账号和密码cat /var/log/mysqld.log | grep "A temporary password"
②修改默认密码
● 修改MySQL密码mysql_secure_installation // 需要校验密码强度,弱密码将会提示 并重新输入● 输入上面的随机密码
③进入MySql创建远程管理员账户
登录mysql -u root -p 输入刚才修改后的密码
如果第二步修改密码失败可使用该方法,成功则忽略
#然后修改密码ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';或set password for 'root'@'localhost'=password('123456');
添加远程登录用户
#选择 mysql 数据库:use mysql;#在 mysql 数据库的 user 表中查看当前 root 用户的相关信息:select host, user from user;#查看表格中 root 用户的 host,默认应该显示的 localhost,只支持本地访问,不允许远程访问。#授权 root 用户的所有权限并设置远程访问GRANT ALL ON *.* TO 'root'@'%'; 或 update user set host='%' where user ='root';#然后使用下面命令使修改生效flush privileges;
三、nacos安装
1.下载解压、上传到服务器上
下载地址nacos官方下载链接:https://nacos.io/zh-cn/docs/quick-start.html
下载之后将Nacos上传到服务器上,我上传到了usr/local
解压并移动重命名
cd /usr/downloadtar -zxvf seata-server-1.4.2.tar.gztar -zxvf seata-1.4.2.tar.gztar -zxvf nacos-server-1.4.3.tar.gzmv nacos-server-1.4.3 /usr/local/nacosmv seata-server-1.4.2 /usr/local/seata
2.nacos配置持久化
cd /usr/local/nacos/conf
打开数据库连接,创建nacos数据库,字符集utf8 ,执行nacos-mysql.sql
3.Nacos配置
修改nacos配置文件凡是需要修改到配置文件的,都先备份,出错了还可以还原
cd /usr/local/nacos/confcp application.properties application.properties.bakvim application.properties
4.开放nacos端口号
如果是阿里云服务器还得去配置安全组
防火墙相关
#查看防火状态
$systemctl status firewalld
#暂时关闭防火墙
$systemctl stop firewalld
#永久关闭防火墙
$systemctl disable firewalld
重启防火墙
$systemctl enable firewalld
#在指定区域打开端口(记得重启防火墙)
$firewall-cmd --zone=public --add-port=80/tcp(永久生效再加上 --permanent)
#查看指定区域所有打开的端口
$firewall-cmd --zone=public --list-ports
说明:
–zone 作用域
–add-port=8080/tcp 添加端口,格式为:端口/通讯协议
–permanent 永久生效,没有此参数重启后失效
5.nacos启动
sh startup.sh -m standalone //bin目下nacos启动启动命令tail -n 200 start.out //logs目录下查看启动日志./shutdown.sh stop //bin目录下nacos停止命令
浏览器访问:ip:8848/nacos ,账号和密码都是 nacos
注意:如果链接的数据库是阿里云的RDS,则需要开启服务白名单,不开启的话,启动不会报错,nacos连接到是内置的数据库。
四、seate安装
1.下载解压、上传到服务器上
Seata官方下载链接:Releases · seata/seata · GitHub
解压并移动重命名同nacos
2.Seata配置持久化
cd /usr/local/seata-1.4.2/script/server/db
同Nacos一致,创建seata数据库,字符集utf8,执行建表语句
3.Seata配置
修改nacos配置文件cd /usr/local/seata/confcp file.conf file.conf.bakvim file.conf
修改registry.conf文件
cp registry.conf registry.conf.bakvim registry.conf
4.使用脚本在 nacos中生成Seata配置文件
文件内容参照地址:
/seata/seata/blob/develop/script/config-center/config.txt
创建config.txt文件、并修改,放在seata/conf目录下,(里面是Seata的配置信息)
5.创建nacos-cnfig.sh脚本放在Seata/conf目录下:主要是把config.txt文件中的信息生成到nacos中
脚本地址:seata/script/config-center/nacos at develop · seata/seata · GitHub
#!/bin/sh# Copyright 1999- Seata.io Group.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at、##/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.while getopts ":h:p:g:t:u:w:" optdocase $opt inh)host=$OPTARG;;p)port=$OPTARG;;g)group=$OPTARG;;t)tenant=$OPTARG;;u)username=$OPTARG;;w)password=$OPTARG;;?)echo " USAGE OPTION: $0 [-h host] [-p port] [-g group] [-t tenant] [-u username] [-w password] "exit 1;;esacdoneif [ -z ${host} ]; thenhost=127.0.0.1fiif [ -z ${port} ]; thenport=8848fiif [ -z ${group} ]; thengroup="SEATA_GROUP"fiif [ -z ${tenant} ]; thentenant=""fiif [ -z ${username} ]; thenusername="nacos"fiif [ -z ${password} ]; thenpassword="nacos"finacosAddr=$host:$portcontentType="content-type:application/json;charset=UTF-8"echo "set nacosAddr=$nacosAddr"echo "set group=$group"urlencode() {length="${#1}"i=0while [ $length -gt $i ]; dochar="${1:$i:1}"case $char in[a-zA-Z0-9.~_-]) printf $char ;;*) printf '%%%02X' "'$char" ;;esaci=`expr $i + 1`done}failCount=0tempLog=$(mktemp -u)function addConfig() {dataId=`urlencode $1`content=`urlencode $2`curl -X POST -H "${contentType}" "http://$nacosAddr/nacos/v1/cs/configs?dataId=$dataId&group=$group&content=$content&tenant=$tenant&username=$username&password=$password" >"${tempLog}" 2>/dev/nullif [ -z $(cat "${tempLog}") ]; thenecho " Please check the cluster status. "exit 1fiif [ "$(cat "${tempLog}")" == "true" ]; thenecho "Set $1=$2 successfully "elseecho "Set $1=$2 failure "failCount=`expr $failCount + 1`fi}count=0COMMENT_START="#"for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); doif [[ "$line" =~ ^"${COMMENT_START}".* ]]; thencontinueficount=`expr $count + 1`key=${line%%=*}value=${line#*=}addConfig "${key}" "${value}"doneecho "========================================================================="echo " Complete initialization parameters, total-count:$count , failure-count:$failCount "echo "========================================================================="if [ ${failCount} -eq 0 ]; thenecho " Init nacos config finished, please start seata-server. "elseecho " init nacos config fail. "fi
修改配置nacos-config.sh,host:naocs地址
执行脚本生成配置信息
$sh ./nacos-config.sh
生成原理:读取conf.txt文件中配置信息
生成结果:默认会生成到nacos命名空间为public下,然后将public下所有配置克隆到seata_local下面
6.启动seata-serve
$cd /usr/local/seata/bin
#赋予文件权限
$chmod u+x seata-server.sh
$./seata-server.sh
#后台启动
$nohup ./seata-server.sh >log.out 2>1 &
打开nacos是否注册服务成功
注意:如果链接的数据库是阿里云的RDS,则需要开启服务白名单
五、redis安装
1、下载目前最新稳定版本 Redis 5.0.3wget http://download.redis.io/releases/redis-5.0.3.tar.gz2、解压到当前目录tar -xvzf redis-5.0.3.tar.gz3、删除压缩包rm redis-5.0.3.tar.gz5、进入解压出来的目录cd redis-5.0.36、编译源码包make7、在根目录打开并修改配置文件 redis.confvim ./redis.conf8、需要更改的配置进行更改# 远程访问需要把bind注释掉bind 127.0.0.1 修改为 # bind 127.0.0.1# 默认启动时为后台启动daemonize yes# 设置密码,找到 # requirepass foobared 字符,在下面添加一行不加注视的:requirepass 需要设置的密码9、进入 src 文件夹以配置文件的形式启动项目cd src./redis-server ../redis.conf10、查看是否启动成功,如果有 6379 端口的服务代表启动成功netstat -nlpt11、测试连接./redis-cli# 进入客户端交互模式后输入auth 密码成功后响应 ok12、退出客户端交互模式exit
如果是阿里云的服务器,需要开放端口号 6379 才能连接上
五、nginx安装
1、下载解压、上传到服务器上
1.Nginx下载地址:/en/download.html[root@bogonsrc]# cd /usr/local[root@bogonsrc]# wget/download/nginx-1.6.2.tar.gz
2、解压安装包
[root@bogonsrc]# tar -zxvf nginx-1.6.2.tar.gz
3、进入安装包目录
[root@bogonsrc]# cd nginx-1.6.2
4、编译安装
[root@bogonnginx-1.6.2]# ./configure [root@bogonnginx-1.6.2]# make[root@bogonnginx-1.6.2]# make install
5、查看nginx版本
[root@bogonnginx-1.6.2]# /usr/local/nginx/sbin/nginx -v
到此,nginx安装完成。
2、Nginx 配置
配置nginx.conf将/usr/local/webserver/nginx/conf/nginx.conf替换为以下内容
[root@bogon conf]# cat /usr/local/webserver/nginx/conf/nginx.confuser www www;worker_processes 2; #设置值和CPU核心数一致error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别pid /usr/local/webserver/nginx/nginx.pid;#Specifies the value for maximum file descriptors that can be opened by this process.worker_rlimit_nofile 65535;events{use epoll;worker_connections 65535;}http{include mime.types;default_type application/octet-stream;log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" $http_x_forwarded_for';#charset gb2312;server_names_hash_bucket_size 128;client_header_buffer_size 32k;large_client_header_buffers 4 32k;client_max_body_size 8m;sendfile on;tcp_nopush on;keepalive_timeout 60;tcp_nodelay on;fastcgi_connect_timeout 300;fastcgi_send_timeout 300;fastcgi_read_timeout 300;fastcgi_buffer_size 64k;fastcgi_buffers 4 64k;fastcgi_busy_buffers_size 128k;fastcgi_temp_file_write_size 128k;gzip on; gzip_min_length 1k;gzip_buffers 4 16k;gzip_http_version 1.0;gzip_comp_level 2;gzip_types text/plain application/x-javascript text/css application/xml;gzip_vary on;#limit_zone crawler $binary_remote_addr 10m;#下面是server虚拟主机的配置server{listen 80;#监听端口server_name localhost;#域名index index.html index.htm index.php;root /usr/local/webserver/nginx/html;#站点目录location ~ .*\.(php|php5)?${#fastcgi_pass unix:/tmp/php-cgi.sock;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;include fastcgi.conf;}location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)${expires 30d;# access_log off;}location ~ .*\.(js|css)?${expires 15d;# access_log off;}access_log off;}}
检查配置文件nginx.conf的正确性命令:
[root@bogonconf]# /usr/local/nginx/sbin/nginx -t
3、启动 Nginx
Nginx 启动命令如下:[root@bogonconf]# /usr/local/nginx/sbin/nginx
如果觉得《【SpringCloud环境搭建】SpringCloud环境搭建jdk mysql Nacos Seata redis nginx》对你有帮助,请点赞、收藏,并留下你的观点哦!