數(shù)據(jù)庫及中間件搭建
MySQL
創(chuàng)建應用文件夾
mkdir /application/tools
cd /application/tools/
下載安裝包/或者doc文件夾下有tar包
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
下載依賴環(huán)境
yum install -y bison-devel ncurses-devel libaio-devel gcc gcc-c++ automake autoconf numactl
解壓MySQL5.7安裝包
tar xf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /application
mv /application/mysql-5.7.23-linux-glibc2.12-x86_64 /application/mysql
創(chuàng)建管理用戶&&授權
useradd -s /sbin/nologin -M mysql
chown -R mysql.mysql /application/mysql/
創(chuàng)建目錄和文件并且分配屬主和屬組
mkdir -p /data/mysql/{data,logs}
touch /data/mysql/logs/{mysql-error.log,mysql-slow.log}
chown -R mysql.mysql /data/mysql
mkdir /var/run/mysql
chown -R mysql.mysql /var/run/mysql
初始化數(shù)據(jù)庫
/application/mysql/bin/mysqld --initialize-insecure --basedir=/application/mysql/ --datadir=/data/mysql/data --user=mysql
復制腳本及PATH變量賦值
\cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
echo 'PATH=$PATH:/application/mysql/bin' >> /etc/profile
source /etc/profile
修改腳本啟動路徑
sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld
替換 /etc/my.cnf
[mysql]
# CLIENT #
port = 3306
socket = /tmp/mysql.sock
[mysqld]
# GENERAL #
user = mysql
default-storage-engine = InnoDB
socket = /tmp/mysql.sock
pid-file = /var/run/mysql/mysql.pid
basedir = /application/mysql
server-id = 1
port = 3306
default-time-zone = '+08:00'
# MyISAM #
key-buffer-size = 32M
myisam-recover-options = FORCE,BACKUP
# SAFETY #
max-allowed-packet = 16M
max-connect-errors = 1000000
skip-name-resolve
sql-mode = ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_AUTO_VALUE_ON_ZERO
sysdate-is-now = 1
innodb = FORCE
secure-file-priv = ''
# DATA STORAGE #
datadir = /data/mysql/data/
# BINARY LOGGING #
log-bin = /data/mysql/data/mysql-bin
expire-logs-days = 7
binlog-format = mixed
sync-binlog = 1
#GTID:
gtid-mode = on
enforce-gtid-consistency = on
# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 500
thread-cache-size = 50
open-files-limit = 65535
table-definition-cache = 1024
table-open-cache = 200
# INNODB #
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 256M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
# 根據(jù)服務器配置調整
innodb-buffer-pool-size = 16G
# LOGGING #
log-error = /data/mysql/logs/mysql-error.log
log-queries-not-using-indexes = 1
slow-query-log = 1
slow-query-log-file = /data/mysql/logs/mysql-slow.log
啟動MySQL
/etc/init.d/mysqld start
初始化MySQL
mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: n
Securing the MySQL server deployment.
New password: <==此處輸入新密碼(如果低于八位數(shù)密碼,稍后會有系統(tǒng)提示)
Re-enter new password: <==此處重復輸入新密碼
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
把 MySQL 添加進啟動項
cd /etc/rc.d && chmod +x rc.local && vim rc.local
#開機啟動mysql
mkdir -p /var/run/mysql
chown -R mysql.mysql /var/run/mysql
/etc/init.d/mysqld start
關閉防火墻
firewall-cmd --state
如果是running的話,使用以下命令關閉防火墻
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啟動
命令參考
重啟MySQL
systemctl restart mysqld.service ,或者
/etc/init.d/mysqld [stop|start|restart|reload]
添加sql查詢賬號,特權為只讀
CREATE USER 'bi_user'@'192.168.1.115' IDENTIFIED BY 'U2FsdGVkX1CwhtF6ad2';
GRANT SELECT ON `bi`.* TO 'bi_user'@'192.168.1.115' identified by "U2FsdGVkX1CwhtF6ad2";
GRANT SELECT ON `bi_client_log`.* TO 'bi_user'@'192.168.1.115' identified by "U2FsdGVkX1CwhtF6ad2";
FLUSH PRIVILEGES;
添加web機器訪問權限
grant all privileges on *.* to root@'192.168.1.115' identified by "tiantangbi";192.168.1.29
FLUSH PRIVILEGES;
java -jar xxl-job-admin-1.0-SNAPSHOT.jar --spring.profiles.active=tthx
Java
cd /application/tools/
下載或者上傳tar
wget https://repo.huaweicloud.com/java/jdk/8u201-b09/jdk-8u201-linux-x64.tar.gz
解壓
tar -zxvf jdk-8u201-linux-x64.tar.gz
移動文件夾
mv jdk1.8.0_201 /usr/local/jdk1.8/
配置環(huán)境變量
vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.8
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
source /etc/profile
檢查是否安裝成功
java -version
Zookeeper
cd /application/tools/
下載或者上傳tar
wget https://downloads.apache.org/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz
解壓
tar -xzvf apache-zookeeper-3.6.2-bin.tar.gz
移動
mv apache-zookeeper-3.6.2-bin /application/zookeeper
修改配置文件
cd /application/zookeeper/conf/
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg
修改日志路徑
dataDir=/data/zookeeper
創(chuàng)建目錄
mkdir /data/zookeeper
mkdir /data/zookeeper/data
mkdir /data/zookeeper/log
修改環(huán)境變量
vim /etc/profile
export ZOOKEEPER_INSTALL=/application/zookeeper/
export PATH=$PATH:$ZOOKEEPER_INSTALL/bin
source /etc/profile
啟動ZK
./bin/zkServer.sh start
./bin/zkServer.sh status
Kafka
cd /application/tools/
下載或者上傳tar
wget https://downloads.apache.org/kafka/2.7.0/kafka_2.12-2.7.0.tgz
解壓
tar -zvxf kafka_2.12-2.7.0.tgz
移動目錄
mv kafka_2.12-2.7.0 /application/kafka
修改配置文件
vim kafka/config/server.properties
log.dirs=/data/kafka-logs
zookeeper.connect=localhost:2181 # 根據(jù)實際修改
listeners=PLAINTEXT://192.168.1.29:9092
advertised.listeners=PLAINTEXT://192.168.1.29:9092
mkdir /data/kafka-logs
啟動kafka
./bin/kafka-server-start.sh -daemon config/server.properties &
相關命令
./bin/kafka-server-stop.sh stop #停止kafka
創(chuàng)建Topic
./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test1
查看Topic
./kafka-topics.sh --list --zookeeper localhost:2181
生產(chǎn)消息
./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test1
消費topic消息
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test1 --from-beginning
查看消費進度
./bin/kafka-consumer-groups.sh --group 消費者組名稱 --describe --bootstrap-server 192.168.1.29:9092
./bin/kafka-topics.sh --delete --zookeeper 192.168.1.29:2181 --topic EquipOperating
Redis
yum install gcc-c++
下載或者上傳tar
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
tar xzf redis-5.0.7.tar.gz
cd redis-5.0.7
make && make install
移動文件夾
mv redis-5.0.7 /application/redis
修改配置文件
vim redis.conf
把文件中的daemonize屬性改為yes(表明需要在后臺運行)
bind 192.168.1.82(本機ip)
設置開機啟動
vi /etc/rc.d/rc.local
/application/redis/src/redis-server /application/redis/redis.conf
然后用命令啟動
/application/redis/src/redis-server /application/redis/redis.conf
ElasticSearch
下載或上傳安裝包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.3-linux-x86_64.tar.gz
解壓
tar -zxvf elasticsearch-7.9.3-linux-x86_64.tar.gz
mv elasticsearch-7.9.3 /application/elasticsearch
創(chuàng)建用戶
groupadd elastic
useradd -g elastic elastic
chown -R elastic.elastic /application/elasticsearch/
chgrp -R elastic /application/elasticsearch
修改配置文件
vim elasticsearch.yml
cluster.name: bi-elasticsearch
node.name: node-1
path.data: /data/elasticsearch/data
path.logs: /data/elasticsearch/logs
http.host: 0.0.0.0
network.host: 0.0.0.0
discovery.seed_hosts: ["0.0.0.0", "[::1]"]
cluster.initial_master_nodes: ["node-1"]
xpack.license.self_generated.type: trial
xpack.security.enabled: true
vim jvm.options
-Xms4g
-Xmx4g
創(chuàng)建文件夾
mkdir -p /data/elasticsearch/data
mkdir -p /data/elasticsearch/logs
chown -R elastic:elastic /application/elasticsearch/
chown -R elastic:elastic /data/elasticsearch/data
chown -R elastic:elastic /data/elasticsearch/logs
vim /etc/security/limits.conf
在文件最后,增加如下配置:
* soft nofile 65536
* hard nofile 65536
vim /etc/sysctl.conf
在文件最后添加一行
vm.max_map_count=655360
添加完畢之后,執(zhí)行命令:
sysctl -p
啟動
su elastic
./bin/elasticsearch -d
設置密碼
.bin/elasticsearch-setup-passwords interactive
這個時候要設置多個賬號密碼
如果忘記密碼:
curl -XGET "localhost:9200/_cat/indices" -H 'Content-Type: application/json'
curl -XDELETE localhost:9200/.security-7
安裝IK分詞器
下載 https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.9.3/elasticsearch-analysis-ik-7.9.3.zip
移動zip 包到 /application/elasticsearch/plugins/ik
unzip elasticsearch-analysis-ik-7.9.3.zip
重啟即可(kill)
Kibana
下載或上傳安裝包
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.9.3-linux-x86_64.tar.gz
解壓
tar -zxvf kibana-7.9.3-linux-x86_64.tar.gz
mv kibana-7.9.3-linux-x86_64 /application/kibana
修改配置
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://192.168.3.95:9200"]
kibana.index: ".kibana"
xpack.monitoring.ui.container.elasticsearch.enabled: true
elasticsearch.username: elastic
elasticsearch.password: aoshu123
i18n.locale: "zh-CN"
授權
chown -R elastic.elastic /application/kibana/
啟動
su elastic
nohup ./bin/kibana >/dev/null 2>&1 &
filebeat
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.9.3-linux-x86_64.tar.gz
tar -zxvf filebeat-7.9.3-linux-x86_64.tar.gz
mv filebeat-7.9.3-linux-x86_64 /application/filebeat
chown -R elastic.elastic /application/filebeat/
修改配置文件
filebeat.inputs:
# Prepaid 日志
- input_type: log
# 這里是容器內的path
paths:
- /data/log/fqcalog/Prepaid/*.log #改對應路徑
# 指定被監(jiān)控的文件的編碼類型,使用plain和utf-8都是可以處理中文日志
encoding: plain
# 添加tags
fields:
log_topic: "Prepaid"
# 忽略在指定時間跨度之前修改的任何文件
ignore_older: 3h
# 指定的時間內沒有被讀取,將關閉文件句柄
close_inactive: 1h
# 文件被刪除時,filebeat關閉文件的處理讀取
close_removed: true
# 如果文件在磁盤上找不到,將從注冊表中清除
clean_removed: true
# Filebeat如何積極地抓取新文件進行更新
backoff: 10s
# 以多快的頻率去prospector指定的目錄下面檢測文件更新
scan_frequency: 10s
output:
kafka:
hosts: ["192.168.1.29:9092"]
# message topic selection + partitioning
topic: '%{[fields.log_topic]}'
partition.round_robin:
reachable_only: false
required_acks: 1
compression: gzip
max_message_bytes: 1000000
# 關閉自動添加的字段模板
processors:
- drop_fields:
fields: ["agent", "ecs", "host", "@metadata"]
logging.level: error
啟動文章來源:http://www.zghlxwxcb.cn/news/detail-506520.html
nohup ./filebeat -c filebeat.yml &
su elastic
nohup ./filebeat -e -c filebeat.yml -d "Publish" >/dev/null 2>filebeat.log &
tail -f filebeat.log
MinIO
wget https://dl.min.io/server/minio/release/linux-amd64/minio ## 國外資源,龜速下載
chmod +x minio
MINIO_ROOT_USER=root MINIO_ROOT_PASSWORD=password ./minio server /data/minio --console-address ":9001"
## /data/minio 存儲目錄;--console-address 是 UI 界面的端口
啟動腳本文章來源地址http://www.zghlxwxcb.cn/news/detail-506520.html
#!/bin/bash
#--------------------------------------------
# 腳本說明
# 配置下面參數(shù)
# 用法:
# sh minio_startup.sh start 啟動應用
# sh minio_startup.sh restart 重啟應用
# sh minio_startup.sh stop 停止應用
# sh minio_startup.sh stauts 查看應用狀態(tài)
#${xx} 此占位符的內容需要自定義
#--------------------------------------------
# 最終的啟動命令為 MINIO_ACCESS_KEY=$USER_ACCOUNT MINIO_SECRET_KEY=$USER_PASSWORD nohup $APP_HOME/$APP_NAME server --config-dir $APP_HOME/config --address :$IN_PORT --console-address :$OUT_PORT $APP_DATA> $APP_LOGS/minio.log 2>&1 &#
#應用上級路徑
APP_HOME=${應用上級路徑}
#應用名稱(其他的服務可以相對應改)
APP_NAME=minio
#入端口
IN_PORT=${入端口}
#出端口
OUT_PORT=${出端口}
#賬號
USER_ACCOUNT=${賬號}
#密碼
USER_PASSWORD=${密碼}
#應用數(shù)據(jù)存放路徑
APP_DATA=${應用數(shù)據(jù)存放路徑}
#應用日志存放路徑
APP_LOGS=${應用日志存放路徑}
if [ "$1" = "" ];
then
echo -e "\033[0;31m 請輸入命令類型 \033[0m \033[0;34m {start|stop|restart|status} \033[0m"
exit 1
fi
if [ "$APP_NAME" = "" ];
then
echo -e "\033[0;31m 未配置應用名稱AppName \033[0m"
exit 1
fi
#啟動應用
function start()
{
PID=`ps -ef |grep $APP_HOME/$APP_NAME|grep -v grep|awk '{print $2}'`
if [ x"$PID" != x"" ]; then
echo "【$APP_NAME】 is running ... ,nothing happen. "
else
MINIO_ACCESS_KEY=$USER_ACCOUNT MINIO_SECRET_KEY=$USER_PASSWORD nohup $APP_HOME/$APP_NAME server --config-dir $APP_HOME/config --address :$IN_PORT --console-address :$OUT_PORT $APP_DATA> $APP_LOGS/minio.log 2>&1 &
echo "Start 【$APP_NAME】 success... , you can use 'tailf $APP_HOME/logs/minio.log' to see the log out. "
fi
}
#停止應用
function stop()
{
echo -e "\033[34m Stoping $APP_HOME/$APP_NAME \033[0m"
PID=`ps -ef |grep $APP_HOME/$APP_NAME|grep -v grep|awk '{print $2}'`
if [ x"$PID" != x"" ]; then
kill -TERM $PID
echo -e "\033[34m $APP_HOME/$APP_NAME (pid:$PID) exiting... \033[0m"
while [ x"$PID" != x"" ]
do
sleep 1
PID=`ps -ef |grep $APP_HOME/$APP_NAME|grep -v grep|awk '{print $2}'`
done
echo -e "\033[31m 【$APP_NAME】 exited. \033[0m"
else
echo -e "\033[34m 【$APP_NAME】already stopped,nothing happen exited. \033[0m"
fi
}
#重啟應用
function restart()
{
stop
sleep 2
start
}
#查看應用狀態(tài)
function status()
{
PID=`ps -ef |grep $APP_HOME/$APP_NAME|grep -v grep|awk '{print $2}'`
if [ x"$PID" != x"" ];then
echo -e "\033[32m【$APP_NAME】(Pid:$PID) is running... \033[0m"
else
echo -e "\033[34m【$APP_NAME】is not running... \033[0m"
fi
}
#定義啟動參數(shù)
case $1 in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
status;;
*)
esac
到了這里,關于項目部署 Java Mysql ES Redis的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!