搭建中间件zk,kafka,ngnix

1、 Sun JDK搭建
1.1 卸载open jdk
通过rpm命令查看Open JDK具体版本信息
rpm -qa | grep java
结果显示:
[root@SZB-L0024178 ~]# rpm -qa | grep java

tzdata-java-2015e-1.el6.noarch
java-1.7.0-openjdk-1.7.0.79-2.5.5.4.el6.x86_64
java-1.6.0-openjdk-1.6.0.35-1.13.7.1.el6_6.x86_64
  • 1
  • 2
  • 3

1.2 通过rmp卸载open jdk

rpm  -e --nodeps  tzdata-java-2015e-1.el6.noarch
rpm -e --nodeps  java-1.7.0-openjdk-1.7.0.79-2.5.5.4.el6.x86_64
rpm -e --nodeps  java-1.6.0-openjdk-1.6.0.35-1.13.7.1.el6_6.x86_64
  • 1
  • 2
  • 3

1.3 安装SUN JDK1.7
1)使用ssh工具把jdk-7u67-linux-x64.tar.gz 放到/opt目录下
2)输入解压命令tar -zxvf jdk-7u67-linux-x64.tar.gz
1.4 配置全局环境变量
1)在 /etc/profile文件 内追加以下内容

# jdk7 settings
JAVA_HOME=/opt/jdk1.7.0_67
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

2)然后执行 source /etc/profile 使配置生效。

2、 zookeeper伪集群搭建
2.1 安装zookeeper
1)使用ssh工具把zookeeper-3.4.8.tar.gz 放到/home/oracle/zookeeper1目录下
2)输入解压命令tar -zxvf zookeeper-3.4.8.tar.gz
3)把解压后的文件分别复制到/home/oracle/zookeeper2、/home/oracle/zookeeper3
2.2 修改配置文件
1)复制/home/oracle/zookeeper1/zookeeper-3.4.8/conf/zoo_sample.cfg文件为zoo.cfg,
其他节点zookeeper2、zookeeper3执行同样操作
2)修改zookeeper1、zookeeper2、zookeeper3三个节点的zoo.cfg文件配置,
Zookeeper1修改如下:

dataDir=/home/oracle/zookeeper1/data
dataLogDir=/home/oracle/zookeeper1/log
clientPort=52181    
server.1=127.0.0.1:2881:3881  
server.2=127.0.0.1:2882:3882  
server.3=127.0.0.1:2883:3883  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Zookeeper2修改如下:

dataDir=/home/oracle/zookeeper2/data
dataLogDir=/home/oracle/zookeeper2/log
clientPort=52182
maxClientCnxns=1000
server.1=127.0.0.1:2881:3881  
server.2=127.0.0.1:2882:3882  
server.3=127.0.0.1:2883:3883  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

Zookeeper3修改如下:
“`
dataDir=/home/oracle/zookeeper3/data
dataLogDir=/home/oracle/zookeeper3/log
clientPort=52183
server.1=127.0.0.1:2881:3881
server.2=127.0.0.1:2882:3882
server.3=127.0.0.1:2883:3883

3)然后创建目录/home/oracle/zookeeper1/data、/home/oracle/zookeeper2/data、
      /home/oracle/zookeeper3/data,


4)执行
echo 1 > /home/oracle/zookeeper1/data/myid
echo 2 > /home/oracle/zookeeper2/data/myid
echo 3 > /home/oracle/zookeeper3/data/myid
5)在每个zk节点的bin目录zkEnv.sh文件最后一行
      JVMFLAGS="-Djute.maxbuffer=5242880 -Xms256m -Xmx1g"
2.3 启动zookeeper服务
分别进入各个Zookeeper节点的bin目录,然后运行“./zkServer.sh start”来启动Zookeeper服务。

2.4 查看zookeeper状态
     启动Zookeeper之后,由于Zookeeper自己会有一套leader的选举算法,所以此时如果想知道那个     Zookeeper是leader可以在各个Zookeeper的bin目录运行“./zkServer.sh status”命令来查看。
3、mongodb搭建

3.1安装mongodb
1)使用ssh工具把mongodb-linux-x86_64-2.6.4.gz放到/home/oracle/mongodb目录
2)输入解压命令tar  -zxvf  mongodb-linux-x86_64-2.6.4.gz

3.2创建数据库和日志的目录
mkdir log
mkdir db

3.3把新增mongodb.conf配置文件放到bin目录下

启动服务
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

/home/oracle/mongodb/mongodb-linux-x86_64-2.6.4/bin/mongod –config /home/oracle/mongodb/mongodb-linux-x86_64-2.6.4/bin/mongodb.conf -auth
3.4创建db和用户
1)打开客户端
./mongo localhost:27017
2)添加admin用户, 切换到admin数据库
use admin
添加用户
db.addUser(“root”,”root”)
使用认证模式登陆b.auth(“root”,”root”)后可以创建需要的数据库和相关用户,我这里有
pafa5admin pafa5admin/pafa5admin
account account/account
esb esb/esb
4、 redis搭建
4.1安装redis
1)使用ssh工具把redis-3.0.6.tar.gz放到/home/oracle/redis目录
2)输入解压命令tar -zxvf redis-3.0.6.tar.gz
3)编译

cd /home/oracle/redis/redis-3.0.6
make
make install
  • 1
  • 2
  • 3

4.2修改配置文件
1)vi /home/oracle/redis/redis-3.0.6/redis.conf
修改配置如下
daemonize yes
logfile /home/oracle/redis/log/redis.log
requirepass redis1234
2)新建文件目录/home/oracle/redis/log
4.3启动服务
1)先进入目录:cd /home/oracle/redis/redis-3.0.6/src
2)执行 ./redis-server ../redis.conf
测试redis
需要认证方式:./redis-cli -a redis1234

127.0.0.1:6379> set foo bar
        OK
        127.0.0.1:6379> get foo
        "bar"
        $ 
  • 1
  • 2
  • 3
  • 4
  • 5

关闭redis
需要认证方式:./redis-cli -a redis1234 shutdown
1. //删除当前数据库中的所有Key
2. flushdb
3. //删除所有数据库中的key
4. flushall

5、 kafka伪集群搭建
5.1安装kafka
1)使用ssh工具把kafka_2.11-0.9.0.1.gz放到/home/oracle/kafka目录
2)输入解压命令tar -zxvf kafka_2.11-0.9.0.1.gz
5.2修改配置
1)把文件 /home/oracle/kafka/kafka_2.11-0.9.0.1/config/server.properties
复制server1.properties、server2.properties,
server.properties相关配置修改为

broker.id=0
port=9092
listeners=PLAINTEXT://:9092
log.dir= /home/oracle/kafka/log0
zookeeper.connect=localhost:52181,localhost:52182,localhost:52183
  • 1
  • 2
  • 3
  • 4
  • 5

server1.properties相关配置修改为

broker.id=1
port=9093
listeners=PLAINTEXT://:9093
log.dir= /home/oracle/kafka/log1
zookeeper.connect=localhost:52181,localhost:52182,localhost:52183
  • 1
  • 2
  • 3
  • 4
  • 5

server2.properties相关配置修改为

broker.id=2
port=9094
listeners=PLAINTEXT://:9094
log.dir= /home/oracle/kafka/log2
zookeeper.connect=localhost:52181,localhost:52182,localhost:52183
  • 1
  • 2
  • 3
  • 4
  • 5

2)新建目录/home/oracle/kafka/log0、/home/oracle/kafka/log1、/home/oracle/kafka/log2

5.3启动服务
1)cd /home/oracle/kafka/kafka_2.11-0.9.0.1

启动三个broker,我们启动是为每个broker都指定了不同的JMX Port,JMX Port主要用来利用jconsole等工具进行监控和排错

env JMX_PORT=10002 bin/kafka-server-start.sh config/server-2.properties &
env JMX_PORT=10001 bin/kafka-server-start.sh config/server-1.properties & 
env JMX_PORT=10000 bin/kafka-server-start.sh config/server.properties &
  • 1
  • 2
  • 3

2)创建一个含有2个Partition分区和3个备份的broker
bin/kafka-topics.sh –create –zookeeper localhost:52181,localhost:52182,localhost:52183 –replication-factor 2 –partitions 3 –topic wh-topic

3)启动Producer发送消息

bin/kafka-console-producer.sh –broker-list localhost:9092,localhost:9093,localhost:9094 –topic wh-topic
启动一个消费者来消费消息
bin/kafka-console-consumer.sh –zookeeper localhost:52181 –topic wh-topic –from-beginning

6、 zookeeper和kafka开机启动设置
1)准备工作
在/home/oracle/kafka目录下,新建脚本kafka.sh,文件内容如下:
#kafka start
/home/oracle/kafka/kafka_2.11-0.9.0.1/bin/kafka-server-start.sh /home/oracle/kafka/kafka_2.11-0.9.0.1/config/server-2.properties &
/home/oracle/kafka/kafka_2.11-0.9.0.1/bin/kafka-server-start.sh /home/oracle/kafka/kafka_2.11-0.9.0.1/config/server-1.properties &
/home/oracle/kafka/kafka_2.11-0.9.0.1/bin/kafka-server-start.sh /home/oracle/kafka/kafka_2.11-0.9.0.1/config/server.properties &

执行授权命令chmod +x kafka.sh
2)切换到/etc/rc.d/init.d/目录下,创建zookeeper文件:touch zookeeper
3)更新权限:chmod +x zookeeper
4)编辑文件,在zookeeper里面输入如下内容

#!/bin/bash
# chkconfig:   2345 10 90 
# description:  zookeeper
export JAVA_HOME=/opt/jdk1.7.0_67
export PATH=$JAVA_HOME/bin:$PATH
case $1 in
         start) su root  /home/oracle/zookeeper1/zookeeper-3.4.8/bin/zkServer.sh start; 
su root  /home/oracle/zookeeper2/zookeeper-3.4.8/bin/zkServer.sh start;
su root  /home/oracle/zookeeper3/zookeeper-3.4.8/bin/zkServer.sh start;
sh  /home/oracle/kafka/kafka.sh;;
         *)  echo "requirestart " ;;
esac
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

5)添加开机启动

chkconfig --add zookeeper
chkconfig zookeeper on
  • 1
  • 2

6)验证

chkconfig --list zookeeper
  • 1

7、 其他相关服务开机启动
在文件/etc/rc.d/rc.local设置开机启动

#redis start
  • 1

/home/oracle/redis/redis-3.0.6/src/redis-server /home/oracle/redis/redis-3.0.6/redis.conf

#mongodb start
  • 1

/home/oracle/mongodb/mongodb-linux-x86_64-2.6.4/bin/mongod –config /home/oracle/mongodb/mongodb-linux-x86_64-2.6.4/bin/mongodb.conf -auth
8、 Oracle开机启动
8.1设置oracle环境变量
1)vi /home/oracle/.bashrc

2)添加如下内容

umask 022
export ORACLE_BASE=/home/oracle/app/
export ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=whtest
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

3)source /home/oracle/.bashrc

8.2修改相关配置
1)user root 下面修改:
[root@ora11gr2 ~]# vi /etc/orata
ORCL:/home/oracle/app/oracle/product/11.2.0/dbhome_1:N
cwtest:/home/oracle/app/oracle/product/11.2.0/dbhome_1:N
ZFTEST:/home/oracle/app/oracle/product/11.2.0/dbhome_1:N
whtest:/home/oracle/app/oracle/product/11.2.0/dbhome_1:Y
将需要启动的实例的N改为Y
2)user oracle 下面修改:

su - oracle
cd  $ORACLE_HOME/bin
  • 1
  • 2

[oracle@ora11gr2 bin]vidbstartORACLEHOMELISTNER=vidbstart找到ORACLEHOMELISTNER=1 这行, 修改成:
ORACLE_HOME_LISTNER=ORACLEHOMEdbshut[oracle@ora11gr2bin]ORACLEHOME同样道理修改dbshut[oracle@ora11gr2bin] vi dbshut

3)测试运行 dbshut, dbstart 看能否启动oracle 服务及listener服务

[oracle@ora11gr2 bin]psefw|grepora[oracle@ora11gr2bin]ps−efw|grepora[oracle@ora11gr2bin] lsnrctl status
[oracle@ora11gr2 bin]$ ps -efw | grep LISTEN | grep -v grep
8.3新建oracle服务启动脚本
1) vi /etc/init.d/oracle
注意文件里面的oracle目录路径根据自己的实际安装路径修改

#!/bin/sh
# chkconfig: 345 61 61
# description: Oracle 11g R2 AutoRun Servimces
# /etc/init.d/oracle
#
# Run-level Startup script for the Oracle Instance, Listener, and
# Web Interface


export ORACLE_BASE=/home/oracle/app/

export ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1

export ORACLE_SID=whtest

export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin

export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib

ORA_OWNR="oracle"

# if the executables do not exist -- display error

if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi

# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display

case "$1" in
start)
# Oracle listener and instance startup
su $ORA_OWNR -c $ORACLE_HOME/bin/dbstart
echo "Oracle Start Succesful!OK."
;;
stop)
# Oracle listener and instance shutdown
su $ORA_OWNR -c $ORACLE_HOME/bin/dbshut
echo "Oracle Stop Succesful!OK."
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo $"Usage: `basename $0` {start|stop|reload|reload}"
exit 1
esac
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51

2)赋予脚本执行权限并链接好

# chmod 750 /etc/init.d/oracle
# ln -s /etc/init.d/oracle /etc/rc1.d/K61oracle
# ln -s /etc/init.d/oracle /etc/rc3.d/S61oracle
  • 1
  • 2
  • 3

3)把oracle启动脚本添加到系统服务里并设置自启动:

# chkconfig --add oracle
# chkconfig --level 345 oracle on
  • 1
  • 2

4)重启系统看效果

9、 Nginx搭建
9.1 环境准备
1)安装依赖库
yum -y install gcc gcc-c++ autoconf automake make
yum -y install zlib zlib-devel openssl openssl–devel pcre pcre-devel
2)使用ssh工具上传tar -xzvf nginx-1.11.3.tar.gz到/home/oracle/nginx
3)解压
tar -xzvf nginx-1.11.3.tar.gz
9.2编译安装
1)cd nginx-1.11.3
2)配置安装目录和执行目录
./configure –prefix=/home/oracle/nginx –sbin-path=/home/oracle/nginx
3)编译安装
make && make install
4)启动
./nginx
测试配置是否正确
./nginx -t
重启
./nginx -s reload

5)配置信息
Configuration summary

+ using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/home/oracle/nginx"
  nginx binary file: "/home/oracle/nginx"
  nginx modules path: "/home/oracle/nginx/modules"
  nginx configuration prefix: "/home/oracle/nginx/conf"
  nginx configuration file: "/home/oracle/nginx/conf/nginx.conf"
  nginx pid file: "/home/oracle/nginx/logs/nginx.pid"
  nginx error log file: "/home/oracle/nginx/logs/error.log"
  nginx http access log file: "/home/oracle/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

10、 VNC安装
1)查看是否安装vnc
rpm -qa | grep ‘tigervnc-server’
2)安装vnc
yum install tigervnc tigervnc-server -y
3)添加vncserver用户和分辨率
vim /etc/sysconfig/vncserv“`
VNCSERVERS=”2:oracle”
VNCSERVERARGS[2]=”-geometry 1024×800”
VNCSERVERS=”1:root”
VNCSERVERARGS[1]=”-geometry 10240×800”

4)关闭SELINUX

vi /etc/selinux/config #编辑配置文件
  • 1
  • 2
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加

发表评论