1、系统初始化
# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
# 关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config #永久
setenforce 0 # 临时
# 关闭THP
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
# 时间同步
yum install ntpdate -y
ntpdate time.windows.com
echo "*/5 * * * * /usr/sbin/ntpdate ntp.api.bz >/dev/null 2 >&1" >> /var/spool/cron/root
2、安装JAVA环境
tar -xzf jdk-11.0.9_linux-x64_bin.tar.gz -C /usr/local/
cd /usr/local/
mv jdk-11.0.9 java
启用环境变量:
cat << EOF >> /etc/profile
JAVA_HOME=/usr/local/java
JAVA_BIN=$JAVA_HOME/bin
PATH=$PATH:$JAVA_BIN
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
EOF
然后source 使其生效
ln -vs /usr/local/java/bin/java /usr/bin/java
source /etc/profile
java -version
3、安装并配置MySQL
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar
rpm -qa | grep mariadb
rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps
tar -xvf mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar
rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm --nodeps --force
rpm -qa | grep mysql
mysqld --initialize
chown mysql:mysql /var/lib/mysql -R
mkdir /data
mv /var/lib/mysql /data/
cat /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
#skip-name-resolve
max_allowed_packet = 500M
default-character-set = UTF8MB4
[mysqld]
port = 3306
socket = /tmp/mysql.sock
datadir = /data/mysql
default-storage-engine = Innodb
character-set-server = UTF8MB4
collation-server=utf8mb4_general_ci
init_connect='SET NAMES utf8mb4'
performance_schema=ON
default_authentication_plugin=mysql_native_password
default-time_zone='+8:00'
skip_name_resolve = ON
myisam-recover-options
#skip-grant-tables
connect_timeout = 300
key_buffer_size = 768M
max_allowed_packet = 64M
table_open_cache = 400000
join_buffer_size = 128M
sort_buffer_size = 1M
read_buffer_size = 4M
read_rnd_buffer_size = 64M
.NET_buffer_length = 64K
myisam_sort_buffer_size = 2M
myisam_max_sort_file_size = 256M
#myisam_repair_threads = 1
max_connections = 1000
max_connect_errors = 30000
max_heap_table_size = 256M
wait_timeout = 7200
interactive_timeout = 7200
thread_cache_size = 128
thread_stack = 512k
tmp_table_size = 384M
#back_log = 500
#binlog-cache-size = 4M
binlog_format = Mixed
#binlog_format = ROW
binlog_expire_logs_seconds = 259200
bulk_insert_buffer_size = 256M
long_query_time = 2
slow_query_log = 1
#log-queries-not-using-indexes
#slow_query_log_file = /data/logs/mysql.slow.txt
log_bin = mysql-bin
log_replica_updates = ON
binlog_cache_size = 67108864 #binlog缓存大小 64M
sync_binlog = 100
binlog_stmt_cache_size = 67108864
#innodb_dedicated_server=ON
relay_log=mysql-relay-bin
#auto_increment_increment=1 #步进值,主节点数量
#auto_increment_offset=1 #起始值,一般填写第n台主机mysql,第二台填写2
replica_parallel_workers=100
replica_parallel_type=LOGICAL_CLOCK
replica_preserve_commit_order=on
#log_bin_trust_function_creators
open_files_limit = 65000
log-error = /data/mysql/mysql.error
#general_log = ON
innodb_file_per_table = ON
innodb_data_home_dir = /data/mysql
innodb_data_file_path = ibdata1:12M:autoextend
innodb_buffer_pool_size = 5G
innodb_log_file_size = 1024M
innodb_log_buffer_size = 1024M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_io_capacity = 1000
innodb_io_capacity_max = 4000
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_open_files = 60000
innodb_rollback_on_timeout = ON
innodb_print_all_deadlocks = ON
innodb_online_alter_log_max_size = 1G
innodb_buffer_pool_load_at_startup = ON
innodb_buffer_pool_dump_at_shutdown = ON
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
server-id = 1
net_read_timeout = 300
net_write_timeout = 300
#slave-skip-errors = 1032,1062,2013
#read-only = 1
#relay_log_recovery = 1
[mysqldump]
quick
max_allowed_packet = 64M
[mysql]
no-auto-rehash
default-character-set = utf8
[myisamchk]
key_buffer_size = 2M
sort_buffer_size = 2M
read_buffer = 4M
write_buffer = 4M
[mysqlhotcopy]
interactive-timeout
systemctl restart mysqld.service
systemctl enable mysqld
cat /var/log/mysqld.log | grep password #查看数据库的密码
mysql -uroot -p',jlmMKj49wAP'
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
use mysql;
update user set host='%' where user ='root';
alter user 'root'@'%' identified with mysql_native_password by '123456';
flush privileges;
4、安装并配置Maven
wget https://dlcdn.Apache.org/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz --no-check-certificate
tar -xzf apache-maven-3.8.4-bin.tar.gz -C /usr/local/
cd /usr/local/
mv apache-maven-3.8.4 maven
vim /etc/profile
export MAVNE_HOME=/usr/local/maven
export PATH=$PATH:$JAVA_HOME/bin:$MAVNE_HOME/bin
source /etc/profile
# 检查maven安装
mvn -version
5、配置apollo数据库
wget https://raw.githubusercontent.com/ctripcorp/apollo/master/scripts/sql/apolloconfigdb.sql
wget https://raw.githubusercontent.com/ctripcorp/apollo/master/scripts/sql/apolloportaldb.sql
mysql -uroot -p123456
source /root/apolloconfigdb.sql;
source /root/apolloportaldb.sql;
6、配置并启动apollo
wget https://github.com/ctripcorp/apollo/releases/download/v1.9.1/apollo-adminservice-1.9.1-github.zip
wget https://github.com/ctripcorp/apollo/releases/download/v1.9.1/apollo-configservice-1.9.1-github.zip
wget https://github.com/ctripcorp/apollo/releases/download/v1.9.1/apollo-portal-1.9.1-github.zip
unzip apollo-adminservice-1.9.1-github.zip -d /data/apollo/apollo-adminservice
unzip apollo-configservice-1.9.1-github.zip -d /data/apollo/apollo-configservice
unzip apollo-portal-1.9.1-github.zip -d /data/apollo/apollo-portal
修改配置
vi /data/apollo/apollo-adminservice/config/Application-github.properties
# DataSource
spring.datasource.url = jdbc:mysql://192.168.52.20:3306/ApolloConfigDB?characterEncoding=utf8
spring.datasource.username = root
spring.datasource.password = 123456
vi /data/apollo/apollo-configservice/config/application-github.properties
# DataSource
spring.datasource.url = jdbc:mysql://192.168.52.20:3306/ApolloConfigDB?characterEncoding=utf8
spring.datasource.username = root
spring.datasource.password = 123456
vi /data/apollo/apollo-portal/config/application-github.properties
# DataSource
spring.datasource.url = jdbc:mysql://192.168.52.20:3306/ApolloPortalDB?characterEncoding=utf8
spring.datasource.username = root
spring.datasource.password = 123456
修改端口启动和日志路径
vi /data/apollo/apollo-adminservice/scripts/startup.sh
LOG_DIR=/data/logs/apollo-adminservice
export JAVA_OPTS="-Xms2048m -Xmx2048m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m -XX:NewSize=256m -XX:MaxNewSize=1024m -XX:SurvivorRatio=8"
vi /data/apollo/apollo-configservice/scripts/startup.sh
LOG_DIR=/data/logs/apollo-configservice
export JAVA_OPTS="-Xms2048m -Xmx2048m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m -XX:NewSize=256m -XX:MaxNewSize=1024m -XX:SurvivorRatio=8"
vi /data/apollo/apollo-portal/scripts/startup.sh
LOG_DIR=/data/logs/apollo-portal
export JAVA_OPTS="-Xms2048m -Xmx2048m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m -XX:NewSize=256m -XX:MaxNewSize=1024m -XX:SurvivorRatio=8"
修改protal组件的apollo-env.properties
vi /data/apollo/apollo-portal/config/apollo-env.properties
local.meta=http://localhost:8080
dev.meta=http://localhost:8080
fat.meta=http://fill-in-fat-meta-server:8080
uat.meta=http://fill-in-uat-meta-server:8080
lpt.meta=${lpt_meta}
pro.meta=http://fill-in-pro-meta-server:8080
#启动脚本
cat apollo-start.sh
/data/apollo/apollo-configservice/scripts/startup.sh
/data/apollo/apollo-adminservice/scripts/startup.sh
/data/apollo/apollo-portal/scripts/startup.sh
#停止脚本
cat apollo-shutdown.sh
data/apollo/apollo-configservice/scripts/shutdown.sh
/data/apollo/apollo-adminservice/scripts/shutdown.sh
/data/apollo/apollo-portal/scripts/shutdown.sh
浏览器访问
链接:http://192.168.52.20:8070 用户名密码:apollo/admin
7、配置 apollo测试样例
1、maven 生成 jar 包
vi /usr/local/maven/conf/settings.xml
### 修改为国内源 ###
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
tar xf springboot-apollo-demo.tar.gz -C /data/
cd /data/springboot-apollo-demo/
cat src/main/resources/application.yaml
server:
port: 7070
spring:
application:
name: apollo-demo
app:
id: apollo-demo # 应用ID 对应 apollo 项目中的AppId
apollo:
cacheDir: /opt/data/ # 配置本地配置缓存目录
meta: http://localhost:8080 # 配置中心地址
autoUpdateInjectedSpringProperties: true # 是否开启 Spring 参数自动更新
bootstrap:
enabled: true # 是否开启 Apollo
eagerLoad:
enabled: false # 将Apollo加载提到初始化日志系统之前
mvn clean package
cd target/
java -jar apollo-demo-0.0.1.jar
- 通过 apollo 为程序添加变量
发布成功后,通过浏览器访问:
http://192.168.52.20:7070/test