disconf是一个专门用来集中管理分布式配置文件的一款开源项目
1:disconf依赖的环境,要想成功搭建disconf必须先在你的Linux系统中安装一下软件,至于这些软件的安装过程,自行百度,这里不做细说
- Zookeeper
- Redis
- Nginx
- MySQL
- Tomcat
- Maven
2:cd /usr/local/mysoft (如果你的local目录下没有mysoft文件夹,则新建一个。我一般把自定义安装的软件都放在mysoft目录下)
[root@myLinux bin]# cd /usr/local/mysoft/
[root@myLinux mysoft]# ls
apache-maven-3.5.4 apache-tomcat-7.0.93 jdk1.8.0_251 nginx-1.12.0 redis-5.0.7 zookeeper-3.4.14
3:在mysoft目录下新建一个disconf文件夹
[root@myLinux mysoft]# mkdir disconf
[root@myLinux mysoft]# ls
apache-maven-3.5.4 apache-tomcat-7.0.93 disconf jdk1.8.0_251 nginx-1.12.0 redis-5.0.7 zookeeper-3.4.14
4:cd disconf/ 进入disconf目录
5:在disconf目录下新建3个文件夹,分别是resource src war
[root@myLinux disconf]# mkdir resource
[root@myLinux disconf]# mkdir src
[root@myLinux disconf]# mkdir war
[root@myLinux disconf]# ls
resource src war
6:cd src 进入src目录
7:git clone https://github.com/knightliao/disconf.git
下载disconf源码(假如克隆代码时提示没有git命令,则要先安装git:yum install git -y)
[root@myLinux src]# git clone https://github.com/knightliao/disconf.git
8:克隆完成后ls,发现src目录下多了一个disconf文件夹,它就是我们下载的disconf源码
[root@myLinux src]# ls
disconf
9:cd disconf/disconf-web/profile/rd 在src目录下执行这段命令,进入rd文件夹
[root@myLinux src]# cd disconf/disconf-web/profile/rd
[root@myLinux rd]# ls
application-demo.properties jdbc-mysql.properties log4j.properties logback.xml redis-config.properties zoo.properties
9:cp * /usr/local/mysoft/disconf/resource 将rd文件夹下的所有文件拷贝到我们前面新建的resource目录下
[root@myLinux rd]# cp * /usr/local/mysoft/disconf/resource
10:cd /usr/local/mysoft/disconf/resource/ 进入resource目录
[root@myLinux rd]# cd /usr/local/mysoft/disconf/resource/ [root@myLinux resource]# ls application-demo.properties jdbc-mysql.properties log4j.properties logback.xml redis-config.properties zoo.properties
11:mv application-demo.properties application.properties 将application-demo.properties文件重命名为application.properties
[root@myLinux resource]# mv application-demo.properties application.properties
[root@myLinux resource]# ls
application.properties jdbc-mysql.properties log4j.properties logback.xml redis-config.properties zoo.properties
12:vim application.properties 编辑application.properties,将domain的值改为你自己服务器的ip (ESC键 :wq 退出并保存)
# # \u670d\u52a1\u5668\u7684domain # domain=72.46.188.188 # # \u90ae\u7bb1\u8bbe\u7f6e # EMAIL_MONITOR_ON = true EMAIL_HOST = smtp.163.com EMAIL_HOST_PASSWORD = password EMAIL_HOST_USER = sender@163.com EMAIL_PORT = 25 DEFAULT_FROM_EMAIL = disconf@163.com # # \u5b9a\u65f6\u6821\u9a8c\u4e2d\u5fc3\u7684\u914d\u7f6e\u4e0e\u6240\u6709\u5ba2\u6237\u7aef\u914d\u7f6e\u7684\u4e00\u81f4\u6027 # CHECK_CONSISTENCY_ON= true
13:vim jdbc-mysql.properties 编辑jdbc-mysql.properties文件
如果你服务器中的mysql 是8.0版本,请做如下配置,用户名和密码根据自己实际的情况填写
jdbc.driverClassName=com.mysql.cj.jdbc.Driver jdbc.db_0.url=jdbc:mysql://72.46.188.188:3306/disconf?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=GMT jdbc.db_0.username=root jdbc.db_0.password=root jdbc.maxPoolSize=20 jdbc.minPoolSize=10 jdbc.initialPoolSize=10 jdbc.idleConnectionTestPeriod=1200 jdbc.maxIdleTime=3600
14:vim redis-config.properties 编辑redis-config.properties,做如下配置,不要问为什么
redis.group1.retry.times=2 redis.group1.client1.name=BeidouRedis1 redis.group1.client1.host=127.0.0.1 redis.group1.client1.port=6379 redis.group1.client1.timeout=5000 redis.group1.client1.password=foobared redis.group1.client2.name=BeidouRedis2 redis.group1.client2.host=127.0.0.1 redis.group1.client2.port=6379 redis.group1.client2.timeout=5000 redis.group1.client2.password=foobared redis.evictor.delayCheckSeconds=300 redis.evictor.checkPeriodSeconds=30 redis.evictor.failedTimesToBeTickOut=6
15:vim zoo.properties 编辑zoo.properties文件,将hosts的值改为自己服务器ip:2181(zookeeper的端口号)
hosts=72.46.188.188:2181
# zookeeper\u7684\u524D\u7F00\u8DEF\u5F84\u540D
zookeeper_url_prefix=/disconf
16:vim /etc/profile 配置环境变量,在配置文件中新增如下配置
ONLINE_CONFIG_PATH=/usr/local/mysoft/disconf/resource WAR_ROOT_PATH=/usr/local/mysoft/disconf/war export ONLINE_CONFIG_PATH export WAR_ROOT_PATH
17:source /etc/profile 使配置文件生效
[root@myLinux resource]# source /etc/profile
18:cd /usr/local/mysoft/disconf/src/disconf/disconf-web 编辑该目录下的pom文件,在该pom文件的profiles节点中新增以下内容
<profile> <id>doclint-java8-disable</id> <activation> <jdk>[1.8,)</jdk> </activation> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <configuration> <additionalparam>-Xdoclint:none</additionalparam> </configuration> </plugin> </plugins> </build> </profile>
ps:该pom文件较长,使用vim编辑器,修改容易出错,我们可以使用xftp进入/usr/local/mysoft/disconf/src/disconf/disconf-web目录,右击pom文件,用记事本编辑,编辑完成后ctrl+s保存
19:cd /usr/local/mysoft/disconf/src/disconf 进入该目录,编辑该目录下的pom文件,将该目录下的mysq 5.0l驱动依赖换成8.0的驱动依赖(因为我的mysql是8.0版本,如果你的事mysql 5.0则不需要执行此步骤)
20:cd /usr/local/mysoft/disconf/src/disconf/disconf-web 进入该目录下执行 sh deploy/deploy.sh 命令(该过程有点长,请耐心等待)
[root@myLinux disconf]# cd /usr/local/mysoft/disconf/src/disconf/disconf-web/
[root@myLinux disconf-web]# sh deploy/deploy.sh
21:部署完毕后 cd /usr/local/mysoft/disconf/war 进入我们前面新建的war目录下,可以发现该目录下多了如下文件
[root@myLinux disconf-web]# cd /usr/local/mysoft/disconf/war [root@myLinux war]# ll total 38200 -rw-r--r-- 1 root root 422 Apr 30 15:00 application.properties -rw-r--r-- 1 root root 39064307 Apr 30 18:24 disconf-web.war drwxr-xr-x 4 root root 4096 Apr 30 18:24 html -rw-r--r-- 1 root root 344 Apr 30 17:54 jdbc-mysql.properties -rw-r--r-- 1 root root 186 Apr 30 14:53 jpaas_control -rw-r--r-- 1 root root 764 Apr 30 14:58 log4j.properties -rw-r--r-- 1 root root 2229 Apr 30 14:58 logback.xml drwxr-xr-x 3 root root 4096 Apr 30 18:24 META-INF -rw-r--r-- 1 root root 499 Apr 30 17:17 redis-config.properties -rw-r--r-- 1 root root 49 Apr 30 14:53 Release drwxr-xr-x 2 root root 4096 Apr 30 18:26 tmp drwxr-xr-x 4 root root 4096 Apr 30 18:24 WEB-INF -rw-r--r-- 1 root root 105 Apr 30 17:18 zoo.properties
22:cd cd /usr/local/mysoft/apache-tomcat-7.0.93/conf 进入你自己的tomcat的conf目录下
[root@myLinux war]# cd /usr/local/mysoft/apache-tomcat-7.0.93/conf
[root@myLinux conf]# ls
Catalina catalina.policy catalina.properties context.xml logging.properties server.xml tomcat-users.xml web.xml
23:vim server.xml 编辑server.xml,在host节点下添加如下内容
<Context path="" docBase="/usr/local/mysoft/disconf/war"></Context>
24:cd /usr/local/nginx/conf 进入你自己的nginx的conf目录
[root@myLinux conf]# cd /usr/local/nginx/conf [root@myLinux conf]# ls fastcgi.conf fastcgi_params koi-utf mime.types nginx.conf scgi_params uwsgi_params win-utf fastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf.default scgi_params.default uwsgi_params.default
25:
upstream disconf { server 72.46.188.188:8080; #代理tomcat,动态请求转发至后端tomcat程序,自己的服务器ip:tomcat的端口号 } server { listen 8081; #服务端口号 server_name 72.46.188.188; #它必须与 application.properties配置文件中的domain保持一致。 #charset koi8-r; #access_log logs/host.access.log main; location / { #root html; #index index.html index.htm; root /usr/local/mysoft/disconf/war/html; #服务静态资源地址 if ($query_string) { expires max; } } location ~ ^/(api|export) { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_pass http://disconf; }
26:cd /usr/local/mysoft/disconf/src/disconf/disconf-web/sql 进入该目录下按照readme.md的只是,依次执行sql,初始化数据库
- 0-init_table.sql create db,tables
- 1-init_data.sql create data
- 201512/20151225.sql patch
- 20160701/20160701.sql patch
27:开启你的zookeeper,mysql,nginx,tomcat,redis服务,在地址栏中输入 服务器ip:8081 如果出现如下界面,则初步完成
28:点击登录,账号密码都为admin,如果出现下面界面,说明你的disconf搭建成功
29:假如你登录时长时间没反应,并提示系统内部错误,则可以做如下尝试,到数据库中执行flush hosts;命令