1. About tomcat Server scripts
1.1 Problem specification
If by order : java -jar xxx.war When starting the server in the way of , If the remote terminal is shut down , that tomcat The server will shut down as well . Affect the use of users . The above order Indicates that the foreground is running .
1.2 Online deployment commands
explain : Generally in Linux Deploy the server in the system Generally, it is run in the back end start-up tomcat The server . And specify the log file output .
command : nohup java -jar 8081.war -> 8081.log &
1.3 Instructions on document viewing
cat Output all the contents of the file
more Output all the contents of the document , Paging output , Space for the next screen ,q sign out
less Usage and more identical , Only by PgUp、PgOn Key to control q sign out
tail Used to display the number after the file , Frequently used
tail -10 nginx.conf see nginx.conf Last 10 That's ok
tail –f nginx.conf Dynamic view log , It is convenient to view the new information in the log
ctrl+c End of view
1.4 Linux Script description
explain : Linux Medium " Script "( plugin - The wilderness act ) The suffix of is .sh
create a file : vim start.sh
Execute the script :
2 Database agent description
2.1 Optimization of database structure
explain : Due to the need for users to link at the same time 2 Agents need to be introduced when there are more than one database , So we have the following deployment .
matters needing attention : User link proxy server General port number :8066 port
2.2 Mycat Introduce
2.3 Mycat Deploy
2.3.1 Upload Mycat Installation package
decompression Mycat Compressed package :
`tar -zxvf Mycat-server-1.7.0-DEV-20170416134921-linux.tar.gz`
2.3.2 Check JDK Whether to install
2.4 About Mycat Profile description
2.4.1 server.xml Profile description
explain : stay server.xml The user name, password and operation database information are defined in the configuration file , Must be with YML Consistent profile .
2). modify YML The configuration file
2.4.2 schemas Profile description
explain :schemas The main function of the file is to configure the database read-write strategy .
`<writeHost host="hostM1" url="192.168.126.129:3306" user="root" password="root">
<!-- Read database 1-->
<readHost host="hostS1" url="192.168.126.130:3306" user="root" password="root" />
<!-- Read database 2-->
<readHost host="hostS2" url="192.168.126.129:3306" user="root" password="root" />
</writeHost>`
2.5 Mycat test
Start command :
Mycat test :
2.6 Database to achieve high availability
High availability : Make sure the service doesn't go down as much as possible , Ensure the normal use of users .
2.6.1 Hot standby of database
explain : Generally, the configuration of dual hot standby in the company , Configure to be master-slave to each other .
Configuration instructions :
1. Main library 192.168.126.130
2. Slave Library 192.168.126.129
`/* Realize the mount of master-slave */
CHANGE MASTER TO MASTER_HOST="192.168.126.130",
MASTER_PORT=3306,
MASTER_USER="root",
MASTER_PASSWORD="root",
MASTER_LOG_FILE="mysql-bin.000001",
MASTER_LOG_POS=482
/* Start the master-slave service */
START SLAVE
/* Check the master-slave status */
SHOW SLAVE STATUS;`
2.6.2 High availability of database configuration
explain : After modifying the database , Upload the configuration file .
`<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<!--name Properties are custom dataNode Represents the node information of the database jtdb Represents a logical library -->
<schema name="jtdb" checkSQLschema="false" sqlMaxLimit="100" dataNode="jtdb"/>
<!-- Define the node name / Node host / Data name -->
<dataNode name="jtdb" dataHost="localhost1" database="jtdb" />
<!-- Parameter Introduction UTF-8 Wrong report in Chinese -->
<!--balance 0 Indicates that all read operations are sent to writeHost host -->
<!--1 Indicates that all read operations are sent to readHost And idle master nodes -->
<!--writeType=0 All writes are sent to the first writeHost host -->
<!--writeType=1 All writes are sent randomly to writeHost in -->
<!--dbType Represents the database type mysql/oracle-->
<!--dbDriver="native" Fixed parameter unchanged -->
<!--switchType=-1 Does not automatically switch , The slave node will not be switched automatically after the host goes down -->
<!--switchType=1 It means that it will switch automatically ( The default value is ) If the first primary node goes down ,Mycat Will be carried out in 3 Heartbeat detection , If 3 No response , It will automatically switch to the second master node -->
<!-- And will update /conf/dnindex.properties Master node information of the file localhost1=0 Represents the first node . Don't modify the file at will, otherwise there will be big problems -->
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="1"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select 1</heartbeat>
<!-- Configure the first host to write to the database , Under default conditions Mycat The main operation of the first host in the first host has achieved read-write separation . Because the default write will be sent to 137 The database of . Read operations are sent to by default 141. If the slave node is busy , Then the main node shares part of the pressure .
-->
<writeHost host="hostM1" url="192.168.126.129:3306" user="root" password="root">
<!-- Read database 1-->
<readHost host="hostS1" url="192.168.126.130:3306" user="root" password="root" />
<!-- Read database 2-->
<readHost host="hostS2" url="192.168.126.129:3306" user="root" password="root" />
</writeHost>
<!-- Define a second host Because the database has already realized dual hot standby .-->
<!--Mycat High availability . When the first host 137 After downtime .mycat It will automatically send out heartbeat detection . testing 3 Time .-->
<!-- If the host 137 Not given Mycat In response, the host is judged dead . The second host in Qidong will continue to provide services for users .-->
<!-- If 137 After the host recovers, it is in the waiting state . If 141 Downtime is 137 Once again, continue to provide services to users .-->
<!-- Premise : Realize the hot standby of two computers .-->
<writeHost host="hostM2" url="192.168.126.130:3306" user="root" password="root">
<readHost host="hostS1" url="192.168.126.130:3306" user="root" password="root" />
<readHost host="hostS2" url="192.168.126.129:3306" user="root" password="root" />
</writeHost>
</dataHost>
</mycat:schema>`
2.6.2 Realize database high availability test
testing procedure :
1. Shut down the main database , And then retrieve the data , Check whether the user's access is restricted .
2. Modify database records , Check whether the user's operation is normal . ( The operation is from the library )
3. Restart the main database Then check whether the data from the database is synchronized .
- Redis Study
===========
3.1 Restore program
3.1.1 modify YML The configuration file
3.1.2 modify pro Picture path
3.1.3 modify Nginx The configuration file
3.1.4 modify hosts file
3.2 Caching mechanisms
explain : Using cache can effectively reduce the frequency of users accessing physical devices . Fast access to data from memory , And then back to the user , At the same time, we need to ensure that the data in memory is database data .
reflection :
1. The running environment of the cache should be in memory .( fast )
2. Use C Language development cache
3. What data structure should the cache use --------K-V structure It is generally used String Most of them are types key Must be unique . v:JSON Format
4. The memory environment is erased when it is powered down , So the memory data should be persisted ( Write disk operation )
5. If the memory size is not maintained , It is easy to lead to Memory data overflow . use LRU Algorithm optimization !!!
3.3 Redis Introduce
redis It's a key-value The storage system . and Memcached similar , It supports storage value There are more types , Include string( character string )、list( Linked list )、set( aggregate )、zset(sorted set -- Ordered set ) and hash( Hash type ). These data types support push/pop、add/remove And take intersection, union and difference sets and more abundant operations , And these operations are Atomicity Of . On this basis ,redis Support various sorts of sorting . And memcached equally , To ensure efficiency , The data is cached in memory . The difference is redis Periodically, updated data is written to disk or changes are written to an appended log file , And on this basis to achieve master-slave( Master-slave ) Sync .
Redis It's open source (BSD The license ) Of , Data structure storage system in memory , It can be used as a database 、 Caching and message middleware . It supports multiple types of data structures , Such as character string (strings), hash (hashes), list (lists), aggregate (sets), Ordered set (sorted sets) And scope query , bitmaps, hyperloglogs and Geographical space (geospatial) Index radius query . Redis Built in Copy (replication),LUA Script (Lua scripting), LRU Driving events (LRU eviction), Business (transactions) And different levels of Disk persistence (persistence), And pass Redis sentry (Sentinel) And automatic Partition (Cluster) Provide high availability (high availability).
Atomicity States : Redis Is a single process, single thread operation , So there is no thread concurrency security issue . In the way of queue, one operation at a time .
Redis Common use :
1.Redis It can be used as a cache
2.Redis It can be used as a database Verification Code
3.Redis Message middleware can use Bank transfer, etc
3.4 Redis install
1). decompression Redis Installation package
`[[email protected] src]# tar -zxvf redis-5.0.4.tar.gz`
2). install Redis
explain : stay Redis Execute the command in the root directory of
command : 1.make
2.make install
3.5 modify Redis Configuration file for
command 1: Show line number :set nu
Change location 1: notes IP binding
Change location 2: Turn off protection mode
Change location 3: Turn on background start
3.6 redis Server command
1. Start command : redis-server redis.conf
2. Search command : ps -ef | grep redis
3. Enter the client : redis-cli -p 6379
4. close redis: kill -9 PID Number | redis-cli -p 6379 shutdown
- Redis Introductory cases
=============
4.1 introduce jar Package file
`<!--spring Integrate redis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>`
4.2 Editing tests API
`package com.jt.test;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;
public class TestRedis {
/**
* 1. test redis Program link is normal
* step :
* 1. Instantiation jedis Tools API object (host:port)
* 2. According to the example operation redis The method is to order
*
* The explanation about the link failure :
* 1. Check Linux A firewall
* 2. Check Redis Configuration file modification item
* 2.1 IP binding
* 2.2 Protected mode
* 2.3 Background start
* 3. Check redis Starting mode redis-server redis.conf
* 4. Check IP port And redis Whether to start ...
*
* */
@Test
public void test01(){
String host = "192.168.126.129";
int port = 6379;
Jedis jedis = new Jedis(host,port);
jedis.set("cgb2006"," study hard Day day up ");
System.out.println(jedis.get("cgb2006"));
//2. Does the exercise exist key
if(jedis.exists("cgb2006")){
jedis.del("cgb2006");
}else{
jedis.set("cgb2006", "xxxx");
jedis.expire("cgb2006", 100);
}
}
}`
Homework
1. Preview other orders Code and commands
2. review AOP Knowledge