开发配置
fiddler
配置代理
- tools-options-script 语言改成 C#
- ctrl + r
- OnBeforeRequest(Session oSession) 方法里面加上如下代理配置
oSession.url = oSession.url.Replace("assettest.zte.com.cn/zte-erp-iasset-api", "10.4.213.48:8082/zte-erp-iasset-api");
数据库配置
设置连接数、天兔监控和buffer pool(177天兔监控)
show databases;
SELECT @@GLOBAL.sql_mode;
show variables like "max_connections";
set GLOBAL max_connections=5000; # 设置最大连接数
flush privileges; # 使设置立即生效
create database lepus default charater set utf8; # 创建天兔监控数据库
grant select, insert, update, delete, create on lepus.* to 'lepus_user'@'localhost' identified by '123456'; # 天兔本地账号授权
grant select, insert, update, delete, create on lepus.* to 'lepus_user'@'%' identified by '123456'; # 天兔外部账号授权
flush privileges;
show databases;
select @@hostname;
set global innodb_buffer_pool_size=1073741824; # 设置buffer pool 大小
set global key_buffer_size=419430400; # 设置 key buffer 大小
select @@hostname;
设置组复制(181)
install plugin group_replication soname 'group_replication.so'; # 安装组复制插件
START GROUP_REPLICATION; # 开启组复制
select * from performance_schema.replication_group_members; # 查看组复制成员
show variables like '%group_replication_ip_whitelist%'; # 查看组复制ip白名单
START GROUP_REPLICATION; # 开启组复制
stop GROUP_REPLICATION; # 停止组复制
Redis 配置
设置 Redis Exporter
./redis_exporter -redis.addr=10.89.232.11:6389,10.89.232.12:6389,10.89.232.85:6389 -redis-only-metrics -redis.alias=redis-11,redis-12,redis-85 -redis.password=654321
./bin/redis-server 0.0.0.0:6379 [cluster] # 查看到的进程信息,非命令
设置 Redis Cluster
配置信息:
dbfilename "dump.rdb" # rdb文件,默认
appendonly yes # 开启aop
appendfilename "appendonly.aof" # aop文件,默认
appendfsync everysec # aop fsync,每秒一次,默认
port 7480 # 端口
pidfile "/var/run/redis_7480.pid" # pid文件,自动生成
dir "/usr/local/redis-cluster/7480" # 目录
cluster-config-file "nodes-7480.conf" # 集群配置文件,自动生成
masterauth "xxxxxx" # 集群master密码
requirepass "xxxxxx" # 节点密码
常用命令:
auth passwordxxx # 认证
CLUSTER NODES # 查看集群节点
CLUSTER INFO # 查看集群信息
创建 Redis Cluster
/usr/local/redis-4.0.9/src/redis-trib.rb create --replicas 1 10.89.232.9:7480 10.89.232.10:7480 10.89.232.8:7480 10.89.232.12:7480
日志信息:
>>> Creating cluster
>>> Performing bash slots allocation on 6 nodes...
Using 3 masters:
10.89.232.9:7480
10.89.232.10:7480
10.89.232.8:7480
Adding replica 10.89.232.11:7480 to 10.89.232.9:7480
Adding replica 10.89.232.12:7480 to 10.89.232.10:7480
Adding replica 10.89.232.85:7480 to 10.89.232.8:7480
M: hashxxxxxxxxxxxxxxxxxxx 10.89.232.9:7480
slots:0-5460 (5461 slots) master
M: hashxxxxxxxxxxxxxxxxxxx 10.89.232.10:7480
slots:5461-10922 (5462 slots) master
M: hashxxxxxxxxxxxxxxxxxxx 10.89.232.8:7480
slots:10923-10383 (5461 slots) master
s: hashxxxxxxxxxxxxxxxxxxx 10.89.232.85:7480
replicates masterhashxxxxxxxxxxxxxxx
s: hashxxxxxxxxxxxxxxxxxxx 10.89.232.11:7480
replicates masterhashxxxxxxxxxxxxxxx
s: hashxxxxxxxxxxxxxxxxxxx 10.89.232.12:7480
replicates masterhashxxxxxxxxxxxxxxx
[OK] All 16384 slots coverd.
常见问题:
[ERR] Sorry, can't connect to node 10.89.232.9:7480
该问题是由于 redis-trib.rb
创建集群时,默认没有 auth,如果节点需要密码,则需要在 redis-trib.rb
的 connect
方法内做如下修改:
@r = Redis.new(:host => @info[:host], :port => @info[:port], :timeout => 60, :password => "xxxxxx")
常用命令
- 连接 redis
/usr/local/rdis-cluster/6379/bin/redis/cli -c -h 10.89.232.9 -p 7480
- 启动 redis
/usr/local/rdis-cluster/6379/bin/redis-server /usr/local/rdis-cluster/6379/redis.conf
天兔配置
监控机 MySql 数据库连接地址
[monitor_server]
host="127.0.0.1"
port=3306
user="lepus_user"
passwd="123456"
dbname="lepus"
重置监控账号密码
SET PASSWORD FOR 'lepus_monitor'@'%' = PASSWORD('xxxxxx');
部署配置
dockerfile
FROM base-img-name:v1.x.x
MAINTAINER Yeehom yeehom147@gmail.com
COPY run.sh /root/run.sh
COPY app.jar /usr/local/tomcat/logs/
RUN chmod 755 /root/run.sh && chmod +x /usr/local/checkRouter.sh && cat /usr/local/mysqlrouter_cron >> /usr/local/tomcat/tomcat_cron && cat /usr/local/tomcat/tomcat_cron
ENTRYPOINT ["sh", "-c", "/root/run.sh"]
dockerfile 引用的 run.sh
#!/bin/bash
# set -e
# 设置时区
export TZ=Asia/Shanghai
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 设置host
cat /root/hosts >> /etc/hosts
# 设置和启动mysqlrouter
expect -c "
spawn mysqlrouter --bootstrap root@10.30.14.174:3306 --user=mysqlrouter
expect {
\"*password*:\" {send \"${db_password}\n\"; exp_continue}
}
"
service mysqlrouter start
sleep 15
# 设置和启动cron
crontab /usr/local/tomcat/tomcat_cron
crontab -l
service crond start
# 设置pinpoint
cd /root/pp
sed -i 's#^profiler.collector.ip=.*#profiler.collector.ip='${pinpoint_ip}'#g' pinpoint.config
sed -i 's#^profiler.tomcat.excludeurl=.*#profiler.tomcat.excludeurl=\/zte-erp-iasset-api\/info#g' pinpoint.config
sed -i 's#^profiler.tomcat.hidepinpointheader=false#g' pinpoint.config
cd /usr/local/apm-agent-v2.0
sed -i 's#^profiler.collector.ip=.*#profiler.collector.ip='${apm_pinpoint_ip}'#g' pinpoint.config
# 添加 agent 3.0 版本及相关配置文件
cp /usr/local/apm_agent_prod.config /usr/local/apm-agent-v3.0/pinpoint.config
# 设置和启动微服务
cd /usr/local/tomcat/logs
# 微服务名,项目组自行修改
AGENT_ID="iasset-${HOSTNAME}"
# 微服务分类_微服务名,项目组自行修改
APPLICATION_NAME="zte-erp-iasset-api"
APM_APPLICATION_NAME="ICENTER_zte-erp-iasset-api"
# 启动时设置的profile
JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=${spring_profiles_active}"
JAVA_OPTS="$JAVA_OPTS -Dspring.cloud.config.uri=${spring_cloud_config_url}"
JAVA_OPTS="$JAVA_OPTS -Dspring.cloud.config.lable=zte-erp-iasset"
JAVA_OPTS="$JAVA_OPTS -Dspring.cloud.config.username=${spring_cloud_config_username}"
JAVA_OPTS="$JAVA_OPTS -Dspring.cloud.config.password=${spring_cloud_config_password}"
# 设置堆栈内存大小
JAVA_OPTS="$JAVA_OPTS -server -Xms3g -Xmx3g -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/root/oom.dump"
# JAVA_OPTS="$JAVA_OPTS -javaagent:/root/pp/pinpoint-bootstrap-1.7.3.jar"
JAVA_OPTS="$JAVA_OPTS -Dpinpoint.agentId=${AGENT_ID} -Dpinpoint.applicationName=${APPLICATION_NAME}"
JAVA_OPTS="$JAVA_OPTS -javaagent:/user/local/apm-agent-v3.0/pinpoint-bootstrap-1.8.1.jar"
JAVA_OPTS="$JAVA_OPTS -Dsun.net.inetaddr.ttl=300 -Dsun.net.inetaddr.negative.ttl=5"
java -jar $JAVA_OPTS app.jar
cron配置
tomcat_cron
00 00 * * * /usr/sbin/logrotate -f /usr/local/tomcat/logrotate/tomcat
* * * * * sh /usr/local/checkRouter.sh
logrotate/tomcat
/usr/local/tomcat/logs/catalina.out
/usr/local/tomcat/logs/*.log{
copytruncate
daily
rotate 2
dateext
nocompress
missingok
}
checkRouter.sh
#!/bin/bash
PATH=/usr/sbin:/sbin:$PATH
router_instance=$(service mysqlrouter status |egrep 'is\s+running|stopped'|wc -l)
#echo step1:${router_instance} >> check.log
if [ ${router_instance} -eq 0 ]; then
service mysqlrouter restart
echo "mysqlrouter starting...the time is"$(date)>>/usr/local/check.log
sleep 5
router_instance=$(service mysqlrouter status |egrep 'is\s+running' |wc -l)
if [ ${router_instance} -eq 0 ]; then
service mysqlrouter stop
fi
fi
sleep 5
router_instance=$(netstat -ntlp|grep -w 6446|wc -l)
#echo step1:${router_instance} >> check.log
if [ ${router_instance} -ne 1 ]; then
service mysqlrouter restart
echo "mysqlrouter starting...the time is"$(date)>>/usr/local/check.log
fi
其他启动命令
nohup java -Xms1g -Xmx2g -jar -Djava.security.egd=file:/dev/urandom -Dspring.profiles.active=prod xxxxxx.jar &