常用中间件的安装脚本

安装脚本

基于Centos7.8系统环境下, 安装单节点的中间件:redis/rocketmq/mysql/elasticsearch/kibana/nacos

部署脚本如下:

#!/bin/bash

# 单机基本环境安装:redis/rocketmq/es/kibana/mysql
# java/git/maven

read -p "input ip:" addr

echo '-------------docker installing-------------'

yum -y remove docker-*
yum -y remove containerd*
rm -rf /var/lib/docker

yum list installed |grep docker
rpm -qa |grep docker


sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

sudo yum install -y yum-utils
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

sudo yum install docker-ce-20.10.1 docker-ce-cli-20.10.1 containerd.io docker-compose-plugin

sudo systemctl start docker
sudo systemctl enable docker

echo '-------------docker installed-------------'

echo '--------------pulling image-------------'
echo 'pull mysql 8.0'
docker pull mysql/mysql-server:8.0

echo 'pull redis 6.0'
docker pull redis:6.0

echo 'pull rocket latest'
docker pull rocketmqinc/rocketmq

echo 'pull rmq console dashboard'
docker pull pangliang/rocketmq-console-ng

echo  'pull elastic'
docker network create elastic
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.12.1
docker pull docker.elastic.co/kibana/kibana:7.12.1

echo 'pull nacos'
docker pull nacos/nacos-server

echo '-------------- pull image finished -------------'

echo 'run mysql container'
docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql/mysql-server:8.0

echo 'run redis container'
mkdir -p /usr/local/docker/redis/

echo -e 'bind 0.0.0.0\n
daemonize yes\n
protected-mode no\n' > /usr/local/docker/redis/redis.conf

docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 6379:6379 --name myredis -v \
/usr/local/docker/redis/redis.conf:/etc/redis/redis.conf -v /usr/local/docker/redis/data:/data -d redis:6.0  \
redis-server /etc/redis/redis.conf

echo 'start rocketmq container'
mkdir -p  /docker/rocketmq/data/namesrv/logs   /docker/rocketmq/data/namesrv/store

docker run -d \
--restart=always \
--name rmqnamesrv \
-p 9876:9876 \
-v /docker/rocketmq/data/namesrv/logs:/root/logs \
-v /docker/rocketmq/data/namesrv/store:/root/store \
-e "MAX_POSSIBLE_HEAP=100000000" \
rocketmqinc/rocketmq \
sh mqnamesrv
echo 'roketmq namesrv success start '

mkdir -p  /docker/rocketmq/data/broker/logs   /docker/rocketmq/data/broker/store /docker/rocketmq/conf

echo -e 'brokerClusterName = DefaultCluster
      brokerName = broker-a
      #0表示Master,大于0表示不同的slave
      brokerId = 0
      #表示几点做消息删除动作,默认是凌晨4点
      deleteWhen = 04
      #在磁盘上保留消息的时长,单位是小时
      fileReservedTime = 48
      #有三个值:SYNC_MASTER,ASYNC_MASTER,SLAVE;同步和异步表示Master和Slave之间同步数据的机制;
      brokerRole = ASYNC_MASTER
      #刷盘策略,取值为:ASYNC_FLUSH,SYNC_FLUSH表示同步刷盘和异步刷盘;SYNC_FLUSH消息写入磁盘后才返回成功状态,ASYNC_FLUSH不需要;
      flushDiskType = ASYNC_FLUSH
      # 设置broker节点所在服务器的ip地址
      brokerIP1 = '${addr}'
      # 磁盘使用达到95%之后,生产者再写入消息会报错 CODE: 14 DESC: service not available now, maybe disk full
      diskMaxUsedSpaceRatio=95' > /docker/rocketmq/conf/broker.conf

docker run -d  \
--restart=always \
--name rmqbroker \
--link rmqnamesrv:namesrv \
-p 10911:10911 \
-p 10909:10909 \
-v  /docker/rocketmq/data/broker/logs:/root/logs \
-v  /docker/rocketmq/data/broker/store:/root/store \
-v /docker/rocketmq/conf/broker.conf:/opt/rocketmq-4.4.0/conf/broker.conf \
-e "NAMESRV_ADDR=namesrv:9876" \
-e "MAX_POSSIBLE_HEAP=200000000" \
rocketmqinc/rocketmq \
sh mqbroker -c /opt/rocketmq-4.4.0/conf/broker.conf

echo 'run rmq dashboard'

docker run -d \
--restart=always \
--name rmqadmin \
-e "JAVA_OPTS=-Drocketmq.namesrv.addr=${addr}:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" \
-p 9999:8080 \
pangliang/rocketmq-console-ng

echo 'run elastic'
docker run -d --name es01-test --net elastic -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.12.1
docker run -d --name kib01-test --net elastic -p 5601:5601 -e "ELASTICSEARCH_HOSTS=http://es01-test:9200" docker.elastic.co/kibana/kibana:7.12.1

echo 'run nacos'
docker run --env MODE=standalone --name mynacos -d -p 8848:8848 docker.io/nacos/nacos-server

echo 'install jdk8'
yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel

echo 'install git'
yum install -y git

echo 'install maven'
yum install -y maven

echo 'update maven mirror'
echo '
      
          
              
                  ali-maven
                  *
                  ali mirror
                  https://maven.aliyun.com/repository/public
              
          
      ' > /etc/maven/settings.xml

echo 'successful!'

echo 'install node 14.x'
curl -sL https://rpm.nodesource.com/setup_16.x | bash
sudo yum install -y nodejs
npm install -g cnpm --registry=https://registry.npm.taobao.org

echo "please run : CREATE USER demo@'%' IDENTIFIED BY 'demo@123';
GRANT ALL ON *.* TO 'demo'@'%'; flush privileges;"
docker exec -it mysql-test /bin/bash -c "mysql -uroot -p123456;"



你可能感兴趣的:(kubernetes,java-rocketmq,mysql,rocketmq)