编程环境
因为文章太长了,所以博主分了三节来讲
九、搜索优化
ElasticSearch
后面的内容持续更新 。。。(因为博主对ElasticSearch需求并不高所以就先不安装了,先把其他搭建完成后再来安装ElasticSearch)
十、分布式
Zookeeper
离线下载
解压
把离线下载的安装包放在/usr/local
下,方便管理
//创建一个文件夹用来放解压后的zookeeper
mkdir /usr/local/zookeeper
//解压
tar -zxvf /usr/local/zookeeper/apache-zookeeper-3.6.1bin.tar.gz -C /usr/local/zookeeper
文件结构
解压完成后我们需要看几个文件
- 肯定是
apache-zookeeper-3.6.1-bin
(刚刚解压得到的文件)目录下的README
里面介绍了zookeeper的官网和wiki,最关键的是说了对java版本的要求,比如这里说如果要使用java1.8来编译,应该使用u211或者更新的版本
说有的文档都放在docs文件夹中了
bin
目录下的文件
bin
目录可以说是整个文件的核心,目录结构如下
这里我们又看到了熟悉的README,内容如下
这里给出了不同的系统的Zookeeper服务的对应脚本
unix
和cygwin
可以使用.sh
msdos
和windows
可以是用.cmd
conf
目录(配置文件目录)
这个目录包含所有关于zookeeper的配置信息
目录结构如下
这里的zoo_sample.cfg
需要注意,cfg后缀的一般为服务的重要配置,内容如下
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
默认开启的配置如下
- tickTime
滴答时间间隔(通信间隔) - initLimit
初始通信时间限制 - syncLimit
同步通信时间限制 - dataDir
数据存放目录 - clientPort
客户端端口号
是不是跟tomcat的配置文件有点像呢?
自定义配置
我们可以修改这个配置文件zoo_sample.cfg
来自定义,常见修改数据存放目录和客户端端口号
修改数据存放目录
比如修改数据存放目录,把数据放在zookeeper目录下
创建一个文件夹
mkdir /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/data
把zoo_sample.cfg
中的dataDir的值改为指定文件夹就可以了
#示例
dataDir=/usr/local/zookeeper/apache-zookeeper-3.6.1-bin/data
修改客户端端口号
我们还可以修改客户端端口号,改为指定的端口号,来防止端口号的冲突
#示例
clientPort=6666
启动
因为在linux系统下,所以调用.sh
来执行
//在bin目录下
cd /usr/local/zookeeper/apache-zookeeper-3.6.1-bin
//启动zookeeper服务
./zkServer.sh start
示例输出
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/bin/../conf/z.cfg
Client port found: 2181. Client address: localhost.
Mode: standalone
坑1
这里,细致的人可能发现了在Using config: /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/bin/../conf/z.cfg
中,为什么博主使用的配置文件是z.cfg
,因为zoo_sample.cfg
是一个官方提供的模板,但是在运行时,是不会加载的
- 把这个文件改一下名字
- 直接复制该文件,并命名为
z.cfg
(其他名字也可以,实际识别的是后缀为cfg
但是不识别前缀为zoo_sample
的文件)
坑2
大家第一次启动,可能会输出下面的内容,很明显这是一个错误,启动失败
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/bin/../conf/z.cfg
Client port found: 2181. Client address: localhost.
Error contacting service. It is probably not running.
原因是什么呢?
- 首先先确定集群是否正常运行
这个在linux服务器编程环境安装中的坑附加详细安装步骤(二)说的很详细了
//查看节点状态(正常状态 为Ready)
kubectl get nodes
//状态为Running
kubectl get pods --namespace=kube-system
- 查看zookeeper状态
./zkServer.sh status
- 查看日志
xxx为hostname
cat /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/logs/zookeeper-root-server-xxx.out
- 查看ERRO信息
针对问题来解决
比如,博主曾遇到一个问题是Problem starting AdminServer on address 0.0.0.0, port 8080 and command URL
这个是端口占用问题,就是说8080端口已经被占用了,zookeeper不能使用默认端口来启动,造成了服务启动失败,我们来查看一下端口。
//查看所有端口,显示端口的PID和程序名称,并且不解析名称
netstat -apn
//我们也可以通过管道筛选一下
netstat -apn | grep 8080
博主发现是tcp6 0 0 :::8080 :::* LISTEN 1731/java
java服务占用,其实呢,是tomcat 我们都知道tomcat的默认端口就是8080
而zookeeper在3.5版本之后的默认端口也是8080
所以我们修改一下zookeeper的默认端口,在配置文件中添加
xxxx改为自己想要自定义的端口号
admin.serverPort=xxxx
重新启动
./zkServer.sh start
成功
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/bin/../conf/z.cfg
Client port found: 6666. Client address: localhost.
Mode: standalone
十一、消息队列
RabbitMQ
安装RabbitMQ会有一些依赖关系,我们先通过安装erlang
来解决一些依赖关系如yum-utils.noarch
依赖关系如下
//通过 curl 来获取rpm的bash脚本 并通过bash执行
curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
正在解决依赖关系
--> 正在检查事务
---> 软件包 yum-utils.noarch.0.1.1.31-53.el7 将被 升级
---> 软件包 yum-utils.noarch.0.1.1.31-54.el7_8 将被 更新
--> 解决依赖关系完成
依赖关系解决
=====================================================================================================================================
Package 架构 版本 源 大小
=================================================&