注意:如下操做均在Root權限下進行,若有單獨帳號需求,請自行搜索解決html
基礎支持安裝: yum install -y gccjava
====安裝JDK========================================================mysql
下載JDK:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htmllinux
獲得安裝包:jdk-8u91-linux-x64.rpmgit
安裝:yum localinstall -y jdk-8u91-linux-x64.rpmgithub
安裝好了之後配置JAVA_HOME環境變量:vi /etc/profileredis
在最後加上:export JAVA_HOME=/usr/java/jdk1.8.0_91sql
配置好了之後須要執行一次才生效:source /etc/profileapache
使用java,javac,java -version 測試bash
====安裝Mysql========================================================
下載源:http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
獲得安裝包:mysql-community-release-el6-5.noarch.rpm
安裝:yum localinstall -y mysql-community-release-el6-5.noarch.rpm
完成後安裝 MysqlServer:yum install -y mysql-server
安裝完成MysqlServer後啓動: service mysqld start
第一次使用設置Root密碼:mysqladmin -u root password 'yourpassword'
進入Mysql:mysql -u root -p yourpassword
進入Mysql庫: use mysql;
### 刪除無用的帳號? delete from user where user is null; delete from user where user = ''; ### 更新Root帳號的訪問IP限制: UPDATE user SET password=PASSWORD("1234") WHERE user='root'; UPDATE user SET host='localhost' where user='root' and host='%'; UPDATE user SET host='192.168.%.%' where user='root' and host='localhost.localdomain'; FLUSH PRIVILEGES; exit; ### 重啓:service mysqld restart
設置Mysql開機啓動:chkconfig mysqld on
====安裝RocketMQ========================================================
下載:https://github.com/alibaba/RocketMQ/releases
獲得包:alibaba-rocketmq-3.2.6.tar.gz
解壓:tar -xzvf alibaba-rocketmq-3.2.6.tar.gz
進入啓動腳本目錄: cd alibaba-rocketmq-3.2.6/bin
修改JVM使用的內存:
vi runbroker.sh 和 runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:PermSize=128m -XX:MaxPermSize=320m" ### 請根據機子內存大小進行合適的調整
啓動 NameServer: nohup sh mqnamesrv >/dev/null 2>&1 & ### 默認啓動端口 9876
啓動 Broker:nohup sh mqbroker -n "127.0.0.1:9876" &
關閉服務
./mqshutdown namesrv
./mqshutdown broker
### 注意:若是此處啓動不起來,差很少都是JAVA_HOME沒配置好,查看環境變量的命令: env
====安裝Zookeeper========================================================
下載: http://zookeeper.apache.org/releases.html
獲得:zookeeper-3.4.8.tar.gz
解壓: tar -xzvf zookeeper-3.4.8.tar.gz
進入配置目錄:cd zookeeper-3.4.8/conf
### 編輯配置文件:vi zoo.cfg tickTime=2000 initLimit=10 syncLimit=5 dataDir=/opt/apps/zookeeper-3.4.8/data ### 注意此處的數據目錄須要存在,而且有權限操做 clientPort=2181
保存退出!
進入啓動腳本的目錄:cd zookeeper-3.4.8/bin
啓動: ./zkServer.sh start
中止:./zkServer.sh stop
====安裝Redis========================================================
下載:http://download.redis.io/releases/redis-3.2.1.tar.gz
獲得 redis-3.2.1.tar.gz
解壓:tar xzf redis-3.2.1.tar.gz
進入Redis目錄: cd redis-3.2.1
安裝: make install
安裝完成後啓動: redis-server &
使用測試命令測試: redis-cli
127.0.0.1:6379> set a b OK 127.0.0.1:6379> get a "b"
退出測試: exit
中止服務: redis-cli -p 6379 shutdown
在 redis.conf 配置文件中配置(find / -name redis.conf)
配置認證密碼: requirepass YourPassword
配置可訪問的IP: bind 192.168.30.33 127.0.0.1
配置後臺啓動: daemonize yes
啓動: ./redis-server redis.conf
====================================================================
====以上爲單機環境下一些使用工具的安裝,下面爲多機集羣安裝==================
====================================================================
====Mysql主從配置====================================================
首先編輯Mysql的配置文件主從都須要使用:
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html ### 編輯Mysql的配置文件: vi /etc/my.cnf [mysqld] ### server-id 每一個服務器不能同樣 server-id=2 port=3306 log-bin = mysql-bin log-bin-index = mysql-bin.index sync_binlog = 1 ### 配置不須要同步的庫和表 replicate-wild-ignore-table=mysql.%,information_schema.%,performance_schema.% replicate-ignore-db = mysql,information_schema,performance_schema binlog_format = MIXED ### 主庫使用 0 標識能夠讀寫,從庫使用 1 標識只讀 read-only=0 ### 配置自增ID的起點和每次的間隔 auto-increment-offset=2 auto-increment-increment=2 relay_log=mysql-relay-bin log-slave-updates=on max_connections = 1024 character-set-server = utf8 max_allowed_packet = 32M tmp-table-size = 128M innodb_buffer_pool_size = 512M join_buffer_size = 256M sort_buffer_size = 64M read_rnd_buffer_size = 256M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid slow_query_log=1 slow_query_log_file=/var/log/mysqlSlow.log
注意:須要同步的庫,須要在主從上都要先把庫建好
在主庫上建立同步的帳號:
create user backup; GRANT REPLICATION SLAVE ON *.* TO 'backup'@'192.168.%.%' IDENTIFIED BY 'mysql';
啓動同步:
### 設置主庫 CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=0,MASTER_HOST='192.168.1.2',MASTER_USER='backup',MASTER_PASSWORD='mysql'; ### 啓動 start slave; ### 查看狀態 show slave status\G; ### 中止同步 stop slave; ### 清除同步信息 reset slave all;
====Zookeeper集羣配置====================================================
首先配置Zookeeper的配置文件:
### 修改 Zookeeper/conf 下的 zoo.cfg (若是沒有此文件則建立一個) ### 內容(此處1,2,3,4標識4臺機子): tickTime=2000 initLimit=10 syncLimit=5 dataDir=/opt/apps/zookeeper-3.4.8/data clientPort=2181 server.1=192.168.1.11:2555:3555 server.2=192.168.1.12:2555:3555 server.3=192.168.1.13:2555:3555 server.4=192.168.1.14:2555:3555
配置完成後,須要在Data目錄中建立文件 myid
進入目錄: cd /opt/apps/zookeeper-3.4.8/data
vi myid
內容只是須要寫入id : 1
如 192.168.1.11 這臺機子上 /opt/apps/zookeeper-3.4.8/data/myid 的內容爲 1
如 192.168.1.12 這臺機子上 /opt/apps/zookeeper-3.4.8/data/myid 的內容爲 2
配置完成後啓動(進入Zookeeper/bin目錄):
./zkServer.sh start
查看日誌:
cat zookeeper.out
====RocketMQ集羣配置====================================================
首先修改配置文件:位置:alibaba-rocketmq\conf\2m-2s-async 這裏使用雙主雙從
主配置:
### broker-a.properties 和 broker-b.properties brokerClusterName=DefaultCluster brokerName=broker-a brokerId=0 namesrvAddr=192.168.10.191:9876;192.168.10.192:9876;192.168.10.196:9876;192.168.10.197:9876 defaultTopicQueueNums=4 autoCreateTopicEnable=true autoCreateSubscriptionGroup=true listenPort=10911 deleteWhen=04 fileReservedTime=120 mapedFileSizeCommitLog=1073741824 mapedFileSizeConsumeQueue=50000000 destroyMapedFileIntervalForcibly=120000 redeleteHangedFileInterval=120000 diskMaxUsedSpaceRatio=88 storePathRootDir=/opt/apps/alibaba-rocketmq/data/store storePathCommitLog=/opt/apps/alibaba-rocketmq/data/logs maxMessageSize=65536 flushCommitLogLeastPages=4 flushConsumeQueueLeastPages=2 flushCommitLogThoroughInterval=10000 flushConsumeQueueThoroughInterval=60000 checkTransactionMessageEnable=false sendMessageThreadPoolNums=128 pullMessageThreadPoolNums=128 brokerRole=SYNC_MASTER flushDiskType=ASYNC_FLUSH
從配置:
### broker-a-s.properties 和 broker-b-s.properties brokerClusterName=DefaultCluster brokerName=broker-a brokerId=1 namesrvAddr=192.168.10.191:9876;192.168.10.192:9876;192.168.10.196:9876;192.168.10.197:9876 defaultTopicQueueNums=4 autoCreateTopicEnable=true autoCreateSubscriptionGroup=true listenPort=10911 deleteWhen=04 fileReservedTime=120 mapedFileSizeCommitLog=1073741824 mapedFileSizeConsumeQueue=50000000 destroyMapedFileIntervalForcibly=120000 redeleteHangedFileInterval=120000 diskMaxUsedSpaceRatio=88 storePathRootDir=/opt/apps/alibaba-rocketmq/data/store storePathCommitLog=/opt/apps/alibaba-rocketmq/data/logs maxMessageSize=65536 flushCommitLogLeastPages=4 flushConsumeQueueLeastPages=2 flushCommitLogThoroughInterval=10000 flushConsumeQueueThoroughInterval=60000 checkTransactionMessageEnable=false sendMessageThreadPoolNums=128 pullMessageThreadPoolNums=128 brokerRole=SLAVE flushDiskType=ASYNC_FLUSH
配置完成後啓動四臺nameserver:
nohup ./bin/mqnamesrv >/dev/null 2>&1 &
啓動2臺broker
主:nohup ./bin/mqbroker -c ./conf/2m-2s-sync/broker-a.properties >/dev/null 2>&1 &
主:nohup ./bin/mqbroker -c ./conf/2m-2s-sync/broker-b.properties >/dev/null 2>&1 &
備:nohup ./bin/mqbroker -c ./conf/2m-2s-sync/broker-a-s.properties >/dev/null 2>&1 &
備:nohup ./bin/mqbroker -c ./conf/2m-2s-sync/broker-b-s.properties >/dev/null 2>&1 &
====Redis集羣配置====================================================