# 云服务环境配置Centos7.6篇
- 重启大法天下无敌
- 重启大法天下无敌
- 重启大法天下无敌
- 遇事不决重启解决
- JDK-8(java环境)
- Mysql-5.7
- Redis-6
- Nacos-2.0.0
- Maven3.2+安装
- Nacos
- Sentinel-1.6.2
- Docker
- Zookeeper-3.4.9
- Docker Compose
- RocketMQ-4.3.2
- Elasticsearch-6.7.1
- Apisix-2.6
重启大法天下无敌
重启大法天下无敌
重启大法天下无敌
遇事不决重启解决
JDK-8(java环境)
- 安装java
yum -y install java-1.8.0-openjdk-devel.x86_64
- 环境变量
vim /etc/profile
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el7_8.x86_64/JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
- 更新环境变量
source /etc/profile
- 查看版本
java -version
Mysql-5.7
- Mysql-yum源下载安装
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum install mysql-server
- 启动、关闭、查看状态
systemctl start mysqld
systemctl stop mysqld
//注意有些会自动升级MySQL版本,一定要确定是5.7
systemctl status mysqld
- 查看mysql数据库默认密码
grep "password" /var/log/mysqld.log
- 授权远程访问
systemctl start mysqld
mysql -uroot -p
输入上一步查询的默认密码,不行的话直接按回车
- 设置密码级别、长度、密码
//密码级别
set global validate_password_policy=LOW;
//密码长度6
set global validate_password_length=6;
//6位密码 P@SSwrd
SET PASSWORD = PASSWORD('P@SSw0rd');
- 授权远程访问
grant all privileges on *.* to root@"%" identified by "123456" with grant option;
flush privileges;
- 查看账户远程权限配置
use mysql;
select host,user from user;
Redis-6
- 安装依赖
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
gcc版本低解决,最好是都执行一遍
yum install centos-release-scl scl-utils-build
yum install -y devtoolset-8-toolchain
scl enable devtoolset-8 bash
- 下载redis安装包
wget https://download.redis.io/releases/redis-6.2.5.tar.gz
- 解压
tar zxvf redis-6.2.5.tar.gz
- 源码安装
cd redis-6.2.5/
make install
- 创建配置文件
sudo mkdir /etc/redis
cp redis.conf /etc/redis/
mkdir -p /data/6379
mkdir -p /data/6379/log
- 配置文件修改
vim /etc/redis/redis.conf
logfile "/data/6379/log/redis.log"
rdbchecksum yes
dir /data/6379/
# requirepass 密码,建议和数据库一致
requirepass P@SSw0rd
#bind 127.0.0.1 -::1
- 后台启动
nohup redis-server /etc/redis/redis.conf &
- 关闭
//获取id
netstat -lntp
kill id
服务器添加端口6379
Nacos-2.0.0
Maven3.2+安装
- 下载maven
wget https://mirror-hk.koddos.net/apache/maven/maven-3/3.8.2/binaries/apache-maven-3.8.2-bin.tar.gz
- 解压
tar zxvf apache-maven-3.8.2-bin.tar.gz
mv apache-maven-3.8.2 /usr/local/maven
- 配置环境变量
vim /etc/profile
export MAVEN_HOME=/usr/local/maven
export PATH=$MAVEN_HOME/bin:$PATH
- 更新环境变量
source /etc/profile
- 查看版本
mvn -v
Nacos
- 下载
//更新wget版本
yum update wget
wget https://github.com/alibaba/nacos/releases/download/2.0.3/nacos-server-2.0.3.tar.gz
- 解压
mkdir /usr/local/nacos
tar zxvf nacos-server-2.0.3.tar.gz -C /usr/local/nacos/
- 单机启动、关闭
sh /usr/local/nacos/nacos/bin/startup.sh -m standalone
sh /usr/local/nacos/nacos/bin/shutdown.sh -m standalone
- 访问地址
//记得开放服务器8848端口
http://服务器ip:8848/nacos/#/login
Sentinel-1.6.2
- 下载
mkdir /usr/local/sentinel
wget wget https://github.com/alibaba/Sentinel/releases/download/1.6.2/sentinel-dashboard-1.6.2.jar
mv sentinel-dashboard-1.6.2.jar sentinel-dashboard.jar
- 直接jar 启动
//记得配服务ip
nohup java -Dserver.port=8849 -Dcsp.sentinel.dashboard.server=服务器ip:8849 -Dproject.name=sentineldashboard -jar /usr/local/sentinel/sentinel-dashboard.jar 1>>/usr/local/sentinel/sentinel.log 2>&1 &
- 启动参数
java -Dserver.port 端口
-Dcsp.sentinel.dashboard.server 服务器地址、外部访问
nohup 后台启动
- 日志位置
/usr/local/sentinel/
Docker
- yum 包更新到最新
yum update
- 安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
- 设置yum源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- 安装docker,出现输入的界面都按 y
yum install -y docker-ce
- 查看docker版本,验证是否验证成功
docker -v
- 镜像加速器
阿里云镜像获取地址:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors,登陆后,左侧菜单选中镜像加速器就可以看到你的专属地址了:
在/etc/docker/daemon.json,文件末尾增加如下内容
{
"registry-mirrors": ["https://你的ID.mirror.aliyuncs.com"]
}
- 进程相关命令
启动docker服务:
systemctl start docker
停止docker服务:
systemctl stop docker
重启docker服务:
systemctl restart docker
查看docker服务状态:
systemctl status docker
设置开机启动docker服务:
systemctl enable docker
Zookeeper-3.4.9
- 拉取镜像
docker pull zookeeper:3.4.9
- 创建数据和日志目录
mkdir -p /data/zookeeper/data
mkdir -p /data/zookeeper/datalog
- 运行
docker run -d -p 2181:2181 -v /data/zookeeper/conf:/conf -v /data/zookeeper/data:/data -v /data/zookeeper/datalog:/datalog --name zookeeper --restart always zookeeper:3.4.9
Docker Compose
- 以编译好的二进制包方式安装在Linux系统中。
curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
- 设置文件可执行权限
chmod +x /usr/local/bin/docker-compose
- 查看版本信息
docker-compose -version
- 卸载Docker Compose
# 二进制包方式安装的,删除二进制文件即可
rm /usr/local/bin/docker-compose
RocketMQ-4.3.2
- 拉取镜像
docker pull rocketmqinc/rocketmq:4.3.2
- 创建数据和日志目录
mkdir -p /data/rmqserver/store
mkdir -p /data/rmqserver/logs
mkdir -p /data/rmqbroker/store
mkdir -p /data/rmqbroker/logs
mkdir -p /data/rmqbroker/conf
- 修改rmqbroker配置文件
vim /data/rmqbroker/conf/broker.conf
# 注意配服务器ip
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
brokerIP1 = 服务器ip
- Docker-compose
vim /data/rmqserver/docker-compose.yml
version: '3.5'
services:
rmqnamesrv:
image: rocketmqinc/rocketmq:4.3.2
container_name: rmqnamesrv
ports:
- 9876:9876
volumes:
- /data/rmqserver/logs:/opt/logs
- /data/rmqserver/store:/opt/store
environment:
TZ: Asia/Shanghai
JAVA_OPT_EXT: "-server -Xms512m -Xmx512m -Xmn256m"
command: sh mqnamesrv
networks:
rmq:
aliases:
- rmqnamesrv
rmqbroker:
image: rocketmqinc/rocketmq:4.3.2
container_name: rmqbroker
ports:
- 10911:10911
- 10909:10909
volumes:
- /data/rmqbroker/logs:/opt/logs
- /data/rmqbroker/store:/opt/store
- /data/rmqbroker/conf/broker.conf:/opt/rocketmq4.3.2/conf/broker.conf
environment:
TZ: Asia/Shanghai
NAMESRV_ADDR: "rmqnamesrv:9876"
MAX_POSSIBLE_HEAP: 200000000
JAVA_OPT_EXT: "-server -Xms1g -Xmx1g -Xmn512m"
command: sh mqbroker -c /opt/rocketmq-4.3.2/conf/broker.conf
links:
- rmqnamesrv:namsrv
networks:
rmq:
aliases:
- rmqconsole
rmqconsole:
image: pangliang/rocketmq-console-ng
container_name: rmqconsole
ports:
- 8888:8080
environment:
TZ: Asia/Shanghai
JAVA_OPTS: "-Drocketmq.namesrv.addr=rmqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
networks:
rmq:
aliases:
- rmqconsole
networks:
rmq:
name: rmq
driver: bridge
- 运行
cd /data/rmqserver/
docker-compose -f docker-compose.yml up -d
//浏览器访问
服务器ip:8888
Elasticsearch-6.7.1
- 拉取镜像
docker pull elasticsearch:6.7.1
- 创建数据和日志目录
mkdir -p /data/elasticsearch/data
mkdir -p /data/elasticsearch/config
- 运行
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -v /data/elasticsearch/data:/usr/share/elasticsearch/data elasticsearch:6.7.1
Apisix-2.6
- 下载apisix镜像地址
yum install git
cd /data
git clone https://github.com/apache/apisix-docker.git
//如果上一步出错才执行,20M不够就50M
git config --global http.postBuffer 20M
- 覆盖docker-compose
cd /data/apisix-docker/example
vim docker-compose.yml
version: "3"
services:
apisix-dashboard:
image: apache/apisix-dashboard:2.7
restart: always
volumes:
- ./dashboard_conf/conf.yaml:/usr/local/apisix-dashboard/conf/conf.yaml
ports:
- "9000:9000"
networks:
apisix:
apisix:
image: apache/apisix:2.6-alpine
restart: always
volumes:
- ./apisix_log:/usr/local/apisix/logs
- ./apisix_conf/config.yaml:/usr/local/apisix/conf/config.yaml:ro
depends_on:
- etcd
# network_mode: host
ports:
- "9080:9080/tcp"
- "9091:9091/tcp"
- "9443:9443/tcp"
networks:
apisix:
etcd:
image: bitnami/etcd:3.4.15
user: root
restart: always
volumes:
- ./etcd_data:/bitnami/etcd
environment:
ETCD_ENABLE_V2: "true"
ALLOW_NONE_AUTHENTICATION: "yes"
ETCD_ADVERTISE_CLIENT_URLS: "http://0.0.0.0:2379"
ETCD_LISTEN_CLIENT_URLS: "http://0.0.0.0:2379"
ports:
- "2379:2379/tcp"
networks:
apisix:
web1:
image: nginx:1.19.0-alpine
restart: always
volumes:
- ./upstream/web1.conf:/etc/nginx/nginx.conf
ports:
- "9081:80/tcp"
environment:
- NGINX_PORT=80
networks:
apisix:
web2:
image: nginx:1.19.0-alpine
restart: always
volumes:
- ./upstream/web2.conf:/etc/nginx/nginx.conf
ports:
- "9082:80/tcp"
environment:
- NGINX_PORT=80
networks:
apisix:
networks:
apisix:
driver: bridge
- 进行安装
docker-compose -f docker-compose.yml -p docker-apisix up -d
- 运行
docker-compose -p docker-apisix up -d
//etcd权限错误
//etcdmain: cannot access data directory: mkdir /bitnami/etcd/data: permission denied
chmod 777 /data/apisix-docker/example/etcd_data
- 测试是否安装成功
curl "http://127.0.0.1:9080/apisix/admin/services/" -H 'X-API-KEY:edd1c9f034335f136f87ad84b625c8f1'
返回结果为成功:
{"node":{"dir":true,"nodes":{},"key":"\/apisix\/services"},"count":"1","action":"get"}