1. Deployment server
- 59.226.29.77 (1T occupied space, 100m shared bandwidth, 32G memory, 16 core CPU):
- Running load balancing services
- fastdfs, open port 22122, 23000
- nginx accessing fastdfs files
- 59.226.29.78 (1T occupied space, 100m shared bandwidth, 32G memory, 16 core CPU):
- docker runs back-end microservices
- nginx running background management system
- 59.226.29.79 (1T occupied space, 100m shared bandwidth, 32G memory, 16 core CPU):
- docker runs back-end microservices
- nginx running background management system
- 59.226.29.80 (1T space, 100m bandwidth, 16G memory, 8-core CPU):
- Run the main database: user name root, port 3306, password 123@cnic
- nginx operation front-end mall
-
59.226.29.81 (1T occupied space, 100m shared bandwidth, 16G memory, 8-core CPU):
- Run the backup database: username root, port 3306, password 123@cnic
- nginx operation front-end mall
-
59.226.29.82 (1T occupied space, 100m shared bandwidth, 32G memory, 8-core CPU):
- The apollo configuration center includes: apollo configservice, apollo adminservice, apollo portal, port 8070, user name apollo, password admin
- zookeeper, running in docker, port 2181
- kafka, running in docker, port 9092
- elasticSearch, running in docker, port 92009300
- redis, running in docker, port 6379, password 123@cnic
6. Installing FastDFS
2. Environmental installation
1. Install JDK
Install JDK on 6 machines
-
Upload JDK compressed package
-
Unzip tar xzvf jdk-8u211-linux-x64.0 tar. gz
-
Add the following at the end of the configuration environment variable vim /etc/profile
export JAVA_HOME=/data/jdk1.8.0_211 export PATH=$JAVA_HOME/bin:$PATH
-
Load configuration file source /etc/profile
2. Install docker
Install docker on machines 2, 3 and 6
-
Installation method: Official document of docker installation
-
#Uninstall old version $ sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
-
#Install the required packages $ sudo yum install -y yum-utils \ device-mapper-persistent-data \ lvm2
-
#Use the following command to set up a stable repository $ sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
-
#Install Docker sudo yum install docker-ce docker-ce-cli containerd.io
-
#Start Docker sudo systemctl start docker
-
#Open port 2375 vim /usr/lib/systemd/system/docker.service
-
#Modify to the following configuration ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
-
#Reload docker configuration systemctl daemon-reload #Restart docker systemctl restart docker
3. Installing nginx
Install nginx on machines 1, 2, 3, 4, 5 and 6
The first nginx hides the server information and version information
1. Hide version information
In nginx Add in conf
server_tokens off;
2. Hide server information
ngnix needs to be recompiled
Enter the extracted nginx source directory
vi src/http/ngx_http_header_filter_module.c
take
static u_char ngx_http_server_string[] = "Server: nginx" CRLF; static u_char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF; static u_char ngx_http_server_build_string[] = "Server: " NGINX_VER_BUILD CRLF;
Change to
static u_char ngx_http_server_string[] = "Server: X-Web" CRLF; static u_char ngx_http_server_full_string[] = "Server: X-Web" CRLF; static u_char ngx_http_server_build_string[] = "Server: X-Web" CRLF;
Recompile nginx
Look at the Server information in the header, which has become a custom name X-Web
-
Upload compressed package
-
Unzip tar xzvf nginx-1.15.12 tar. gz
-
The installation must use the make, cmake, and gcc compilers
yum install -y make cmake gcc gcc-c++ yum -y install openssl openssl-devel yum -y install pcre-devel
-
install
cd nginx-1.15.12 ./configure --with-http_ssl_module make make install
4. Install master-slave database
Install the primary database on machine 4 and the backup database on machine 5
-
mysql 59.226.29.80 and 59.226.29.81 are installed on the two machines respectively
Download the corresponding version as needed and check the official website address
https://dev.mysql.com/downloads/mysql/5.7.html#downloads
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
tar -xzvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql
#The useradd -r parameter indicates that the mysql user is a system user and cannot be used to log in to the system cd /usr/local groupadd mysql
useradd -r -g mysql mysql
-
mount this database
#Create data directory cd /usr/local/mysql mkdir data
-
Change the owner and group of / usr/local/mysql to mysql
chown -R mysql.mysql /usr/local/mysql
-
Create my in the / usr / local / MySQL / support files directory_ default. cnf
[mysqld] sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES basedir = /usr/local/mysql datadir = /usr/local/mysql/data port = 3306 socket = /tmp/mysql.sock character-set-server=utf8 log-error = /usr/local/mysql/data/mysqld.log pid-file = /usr/local/mysql/data/mysqld.pid
-
Copy, if prompted whether to overwrite, y
cp /usr/local/mysql/support-files/my_default.cnf /etc/my.cnf
-
Initialize mysqld
cd /usr/local/mysql/ ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
-
After initialization, view the log
vi /usr/local/mysql/data/mysqld.log
-
Temporary password a8?DQir=T+k+
2019-04-08T06:14:29.790033Z 1 [Note] A temporary password is generated for root@localhost: a8?DQir=T+k+
-
Put the startup script in the startup initialization directory
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
-
service mysql start
service mysql start
-
Log in to mysql with the initial password
cd /usr/local/mysql ./bin/mysql -u root -p
-
Change Password
mysql> set password=password('123@cnic'); mysql> grant all privileges on *.* to root@'%' identified by '123@cnic'; mysql> flush privileges;
-
Add remote access
mysql> use mysql; mysql> update user set host='%' where user = 'root'; mysql> flush privileges;
-
Restart mysql to take effect
service mysql stop service mysql start
service mysql restart
-
Firewall open 3306 port
mysql master-slave synchronization
-
Edit the master server mysql configuration file
vim /etc/my.conf
server-id=1 #Server id (master and slave must be different) log-bin=mysql-bin #Open the log (the host needs to be opened). The MySQL bin can also be customized. Here, you can also add a path as the configuration of the host binlog-do-db=zgkjy-v2 #Library to synchronize with the slave #binlog-do-db= binlog-ignore-db=mysql #Libraries that are not synchronized to the slave (multiple writes and multiple lines) binlog-ignore-db=information_schema binlog-ignore-db=performance_schema binlog-ignore-db=sys expire_logs_days=7 #Automatically clean up the log file 7 days ago, which can be modified as needed
-
Setting successfully restarted Mysql service
service mysqld restart
-
Create backup account and test log_ Whether bin is successfully opened
#Log in to the master database show variables like '%log_bin%';
#Set backup account information grant replication slave on *.* to 'backup'@'%' identified by '123456';
#View snapshot show master status\G
#Turn off the read lock of the primary database unlock tables;
-
Set Mysql configuration from server
vim /etc/my.conf
[mysqld] basedir=/usr/local/mysql #mysql path datadir=/data/mysqldata #mysql data directory socket=/tmp/mysql.sock user=mysql server_id=2 #The two slave servers behind MySQLid need to be set differently port=3306 #Add the following parameters to avoid master-SLAVE replication errors caused by untimely updates and SLAVE restart. read_only = 1 master_info_repository=TABLE relay_log_info_repository=TABLE #relay_log_recovery=1 #Slave write prohibited #super_read_only=1 #Slave write prohibited
-
Restart slave database
service mysqld restart
-
Log in to the slave database and make the following settings
mysql> stop slave; mysql> change master to -> master_host='192.168.1.201', #master ip -> master_user='backup', #Backup user name -> master_password='123456', #password -> master_log_file='mysql-bin.000003', #The screenshot above should be consistent with the parameters of the master -> master_log_pos=431; #The screenshot above should be consistent with the parameters of the master
5. Installing the apollo configuration center
Install the apollo configuration center on machine 6
-
apollo official website Download: three files: Apollo configservice, Apollo adminservice, and Apollo portal
-
Upload to / data/apollo and unzip
-
Create Apollo configdb and import sql/apolloconfigdb.sql , you can also import the existing configuration sql
-
Create Apollo PORTALDB and import sql/apolloportaldb.sql , you can also import the existing configuration sql
-
Modify the Apollo configservice database connection
cd /data/apollo/apollo-configservice/config vim application-github.properties #Modify database connection and save spring.datasource.url = jdbc:mysql://59.226.29.80:3306/ApolloConfigDB?characterEncoding=utf8 spring.datasource.username = root spring.datasource.password = 123@cnic
-
Modify the Apollo adminservice database connection
cd /data/apollo/apollo-adminservice/config vim application-github.properties #Modify database connection and save spring.datasource.url = jdbc:mysql://59.226.29.80:3306/ApolloConfigDB?characterEncoding=utf8 spring.datasource.username = root spring.datasource.password = 123@cnic
-
Modifying the Apollo portal database connection
cd /data/apollo/apollo-portal/config vim application-github.properties #Modify database connection and save spring.datasource.url = jdbc:mysql://59.226.29.80:3306/ApolloConfigDB?characterEncoding=utf8 spring.datasource.username = root spring.datasource.password = 123@cnic
-
Modify the environment configuration of Apollo portal
cd /data/apollo/apollo-portal/config vim apollo-env.properties #Modify environment and save dev.meta=http://59.226.29.82:8080
-
start-up
sh /data/apollo/apollo-portal/apollo-configservice/scripts/startup.sh sh /data/apollo/apollo-portal/apollo-adminservice/scripts/startup.sh sh /data/apollo/apollo-portal/scripts/startup.sh
-
The firewall opens ports 8080 and 8070
-
Browser access 59.226.29.82:8070, user name apollo, password admin
6. Install FastDFS
-
FastDFS is an application developed in C language. The installation must use the make, cmake, and gcc compilers.
yum install -y make cmake gcc gcc-c++
-
Install FastDFS core library
Unzip after uploading the file
unzip libfastcommon-master.zip -d /data/fastdfs
libfastmon does not provide the make command installation file. Shell scripts are used to perform compilation and installation. The shell script is make sh
#compile ./make.sh #install ./make.sh install
There is a fixed default installation location. In the / usr/lib64 and / usr/include/fastcommon directories.
To create a soft connection:
#Because the Lib directory set by the FastDFS main program is / usr/local/lib, you need to create a soft link ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
-
FastDFS main program installation
Upload and unzip
tar -zxf FastDFS_v5.08.tar.gz -C /data/fastdfs
Compile and install
./make.sh ./make.sh install
After installation, the FastDFS main program is located at:
/usr/bin - The location of the executable. /etc/fdfs - Location of the configuration file. /usr/lib64 - Location of main program code /usr/include/fastdfs - Contains the location of some plug-in groups
-
Tracker service configuration startup
Copy a template profile
cd /etc/fdfs cp tracker.conf.sample tracker.conf
Open tracker Conf, modify base_path, base_path is the root directory used after fastdfstracker is started, which is used to store Tracker data and logs.
base_path=/home/yuqing/fastdfs -> base_path=/data/fastdfs/data/fastdfs-tracker
The path in the configuration needs to be created before the service can be started
mkdir -p /data/fastdfs/data/fastdfs-tracker
start-up
/etc/init.d/fdfs_trackerd start
After successful startup, the base in the configuration file_ The FastDFS service related data directory (data directory, logs directory) appears in the directory pointed to by path
Other commands:
#View status ps -ef | grep fdfs #Out of Service /etc/init.d/fdfs_trackerd stop #Restart service /etc/init.d/fdfs_trackerd restart
-
Storage configuration and startup
Modify configuration
mkdir -p /data/fastdfs/data/fastdfs-storage/base mkdir -p /data/fastdfs/data/fastdfs-storage/store cd /etc/fdfs cp storage.conf.sample storage.conf #Modify file base_path=/home/yuqing/fastdfs -> /data/fastdfs/data/fastdfs-storage/base store_path0=/home/yuqing/fastdfs -> /data/fastdfs/data/fastdfs-storage/store tracker_server=192.168.150.11:22122 -> tracker_server=59.226.29.82:22122
Start service
/etc/init.d/fdfs_storaged start
-
Fastdfs nginx module installation
Upload and unzip
tar -zxf fastdfs-nginx-module_v1.16.tar.gz -C /data/fastdfs
Modify configuration
vim /data/fastdfs/fastdfs-nginx-module/src/config CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
Compile and install Nginx
./configure --with-http_ssl_module --add-module=/data/fastdfs/fastdfs-nginx-module/src/ make && make install
Copy profile
cp /data/fastdfs/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
Modify configuration file mod_fastdfs.conf
tracker_server=59.226.29.82:22122 url_have_group_name = true store_path0=/data/fastdfs/data/fastdfs-storage/store
Copy the two configuration files (http.conf and mime.types) in the FastDFS installation package to the / etc/fdfs directory
cp /data/fastdfs/FastDFS/conf/http.conf /etc/fdfs/ cp /data/fastdfs/FastDFS/conf/mime.types /etc/fdfs/
Create a soft connection for network access to storage services
ln -s /data/fastdfs/data/fastdfs-storage/store /data/fastdfs/data/fastdfs-storage/store/data/M00
Modify nginx configuration file
location ~ /group([0-9])/M00 { ngx_fastdfs_module; }
- Firewall open port: 22122
7. Install zookeeper, kafka
-
Download Image
docker pull wurstmeister/zookeeper docker pull wurstmeister/kafka:2.11-0.11.0.3
-
Start mirroring
#Start zookeeper docker run -d --name zookeeper --publish 2181:2181 --volume /etc/localtime:/etc/localtime wurstmeister/zookeeper #Start kafka docker run -d --name kafka --publish 9092:9092 \ --link zookeeper \ --env KAFKA_ZOOKEEPER_CONNECT=59.226.29.82:2181 \ --env KAFKA_ADVERTISED_HOST_NAME=59.226.29.82 \ --env KAFKA_ADVERTISED_PORT=9092 \ --volume /etc/localtime:/etc/localtime \ wurstmeister/kafka:2.11-0.11.0.3
-
Firewall open port: 21819092
8. Install elasticSearch
docker run --name elasticsearch -d -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -e "discovery.type=single-node" -p 9200:9200 -p 9300:9300 elasticsearch:6.5.4
Firewall open port: 92009300
9. Publishing microservices
- Two machines 59.226.29.78 and 59.226.29.79 deploy common configuration commands
FROM java:8 EXPOSE 8761 VOLUME /tmp ADD /target/renren-register.jar /app.jar RUN bash -c 'touch /app.jar' RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone ENTRYPOINT ["java","-Xmx500m","-jar","/app.jar"]
- The two machines should configure their own ip and other services except register
--add-host eureka:59.226.29.39
--add-host eureka:59.226.29.78
--add-host eureka:59.226.29.79
- All services need to be configured
-v /opt/settings:/opt/settings
- pay payment service needs more configuration
-v /opt/cfca:/opt/cfca
- Gateway gateway additional configuration
-p 8080:8080
10. Open port
firewall-cmd --zone=public --list-ports
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload
11. Install redis
docker run -d --name redis -p 6379:6379 -v redis:/data --requirepass "123@cnic" redis --appendonly yes