2) Modify the nginx configuration file and add the monitoring status configuration
Add the following code to the server block of nginx.conf
location /nginx_status {
# Turn on nginx stats
stub_status on;
# I do not need logs for stats
access_log off;
# Security: Only allow access from 192.168.1.100 IP #
#allow 192.168.1.100;
# Send rest of the world to /dev/null #
#deny all;
}
xplanation:
Active connections: The number of active connections initiated by the backend.
Server accepted handling requests: Nginx handled a total of 655 connections, successfully created 655 times handshake (proved no failure in the middle), handled a total of 1985 requests.
Reading: Nginx Number of Header messages read to the client.
Writing: Nginx Number of Header messages returned to the client.
Waiting: In the case of keep-alive, this value is equal to active - (reading + writing), meaning that Nginx
Concurrency Level: 5000
Time taken for tests: 46.416 seconds
Complete requests: 100000
Failed requests: 90202
(Connect: 0, Receive: 0, Length: 90202, Exceptions: 0)
Write errors: 0
Non-2xx responses: 90282
Total transferred: 36624606 bytes
HTML transferred: 18815922 bytes
Requests per second: 2154.42 [#/sec] (mean)
Time per request: 2320.813 [ms] (mean)
Time per request: 0.464 [ms] (mean, across all concurrent requests)
Transfer rate: 770.55 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 18 1251 2273.8 824 31950
Processing: 298 839 299.1 855 6307
Waiting: 1 648 298.8 651 6194
Total: 408 2090 2323.2 1697 36083
Percentage of the requests served within a certain time (ms)
50% 1697
66% 1758
75% 1802
80% 1843
90% 2583
95% 4601
98% 8399
99% 8807
100% 36083 (longest request)
Generally in the beginning of the need for their own company’s IT environment to have a general understanding of 1-2 months after the need to open the port has a clear understanding of what the port is used to do, whether it is illegal open port , Their own mind to be the number of unknown Trojans through a strange port to the black out on the embarrassment. So as the operation and maintenance personnel need to open the port of each company has a clear understanding of the port, at the same time have to face the strange port how to determine the port corresponding to what kind of service, the service is illegal and so on.
Need to use the command :
Ss -tnl shows all tcp has been listening on the port
Lsof -i : The port displays all the processes that open the port
Working example:
One day through ss -tnl found that do not know the port is being monitored
For the port 49994 I do not know why it is doing, so use the lsof-i command to see which ports are open
It is found here that the port corresponds to the rpc.statd command.
(If prompted not to remember the command yum install-y lsof)
If you do not know rpc.statd, a very simple way is baidu
Through the baidu can know that the order is nfslock service of a process, if you want to close the port only need to close nfslock service
Service nfslock stop
And then perform ss-tnl found 49994 port disappeared
In the future if you encounter an unknown port can use the above method to judge.
Garbage Priority Garbage Collector (G1 GC) Use notes
G1 GC is a new garbage collection strategy, starting with JDK7, mainly for server-side JVM, and large memory applications, the goal is to achieve similar high-throughput CMS. G1 is still the idea of ??sub-management, the main use of the idea of ??block management, through the memory is divided into no more than 2048 blocks, each size between 1M-32M, Eden, Survivor space and old generation are one Series of discontinuous logical regions.
Here do not talk about the concrete realization of G1 ideas, only record how to configure and use.
Start the G1 GC
-XX: + UseG1GC
Several parameters and default values
-XX:MaxGCPauseMillis=200 Maximum pause time, which is a target value, JVM will try to close to this target, the default value of 200.
-XX:G1HeapRegionSize=n G1 area block size, 1M-32M, must be a power of 2, G1 will be based on the size of the block plan is not more than 2048 blocks.
-XX:G1NewSizePercent=5 Young generation in the heap in the smallest percentage, the default value is 5%
-XX:G1MaxNewSizePercent=60 The maximum percentage of young generations in the heap, the default is 60%
-XX:ParallelGCThreads=nSets the value of the STW worker thread. Set the value of n to the number of logical processors. The value of n is the same as the number of logical processors, up to 8. If there are more than eight logical processors, set the value of n to about 5/8 of the number of logical processors. This applies to most cases unless it is a larger SPARC system, where the value of n can be about 5/16 of the number of logical processors.
-XX:ConcGCThreads=nSets the number of threads that are marked in parallel. Set n to 1/4 of the amount of parallel garbage collection threads (ParallelGCThreads).
-XX:InitiatingHeapOccupancyPercent=45 Mark the garbage threshold, the default 45%
-XX:G1ReservePercent=10Set the percentage of reserved memory as free space to reduce the risk of target space spillovers. The default value is 10%.
Suggest
Avoid using the -Xmn option or other related options such as -XX: NewRatio to explicitly set the young generation size. Fixed young generation size will cover the pause time target.
Pause time goals are not too small, because pause time and throughput are a contradictory indicator.
yum install gcc make
cd ~
mkdir init
wget http://download.redis.io/releases/redis-3.2.3.tar.gz
tar -zxvf redis-3.2.3.tar.gz
cd redis-3.2.3
make
make install
#cd utils
#./install_server.sh
cd src/
cp redis-server redis-cli /usr/local/bin
cp redis-sentinel redis-benchmark redis-check-aof redis-check-dump /usr/local/bin
mkdir /etc/redis
mkdir -p /var/lib/redis/6379
Set the vm.overcommit_memory to 1, which means always, this will avoid data to be truncated, take a look here for more.
sysctl -w vm.overcommit_memory=1
Change the maximum of backlog connections some value higher than the value on tcp-backlog option of redis.conf, which defaults to 511. You can find more on sysctl based ip networking “tunning” on kernel.org website.
sysctl -w net.core.somaxconn=512
Disable transparent huge pages support, that is known to cause latency and memory access issues with Redis.
echo never > /sys/kernel/mm/transparent_hugepage/enabled
Redis.conf is the Redis configuration file, however you will see the file named as 6379.conf here, where the number is the same as the network port is listening to. This name is recommended if you are going to run more than one Redis instance.
cp redis.conf /etc/redis/6379.conf
vim /etc/redis/6379.conf
daemonize yes #note
pidfile /var/run/redis_6379.pid
port 6379
loglevel notice
logfile /var/log/redis_6379.log
dir /var/lib/redis/6379
Starting at boot
cp utils/redis_init_script /etc/init.d/redis_6379
vim /etc/systemd/system/redis_6379.service
[Unit]
Description=Redis on port 6379
[Service]
Type=forking
ExecStart=/etc/init.d/redis_6379 start
ExecStop=/etc/init.d/redis_6379 stop
[Install]
WantedBy=multi-user.target
vim /etc/sysctl.conf
vm.overcommit_memory = 1
net.core.somaxconn=512
For the transparent huge pages support there is no sysctl directive, so you can put the command at the end of /etc/rc.local
echo never > /sys/kernel/mm/transparent_hugepage/enabled
1.Linux under MySQL to create a user backup role, and granted the role of SELECT, RELOAD, SHOW DATABASES, LOCK TABLES and other permissions.
mysql> create user 'backuper'@'localhost' identified by '********';
Query OK, 0 rows affected (0.00 sec)
mysql> grant SELECT, RELOAD, SHOW DATABASES, LOCK TABLES on *.* to backuper@localhost;
Query OK, 0 rows affected (0.00 sec)
2. In the system to find a relatively large hard disk to create a backup directory, and create a shell script
vim backup_mohan_db.sh
#!/bin/bash
mysqldump -ubackuper -p******** qianyu_veeker_db > /home/mysql/backup/mohan_db_$(date +%Y%m%d_%H%M%S)
3. To add the scheduled task, you need to install the crontab
vixie-cron package is the main program for cron; the
crontabs package is the program used to install, uninstall, or list the tables used to drive the cron daemon.
[root@~]# yum -y install vixie-cron
[root@~]# yum -y install crontabs
4. Set boot to start
[root@ ~]# chkconfig --level 345 crond on
[root@linuxidc etc]# vim crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
#| .------------- hour (0 - 23)
#| | .---------- day of month (1 - 31)
#| | | .------- month (1 - 12) OR jan,feb,mar,apr ...
#| | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
#| | | | |
#* * * * * user-name command to be executed
0 0 * * * /home/mysql/backup/mohan_db.sh
Forget how to do root, forget to initialize MySQL generated when the random password how to do, or simply did not register that random password, do not tell me to clear all the data under data, reinitialize, of course, you have to be so wayward can also be.
Do not pull, the following is the title.
There are several ways in the official document, I read the next, you remember the following I said a bar, the other you try it, so good to make me no matter
Use –skip-grant-tables to start mysql server
bin / mysqld_safe –user = mysql01 –skip-grant-tables – skip-networking &
Two options are meaning –
skip-grant-tables skip authorization –
skip-networking does not allow remote network connection
Skip-networking can not, to prevent other users to connect the remote operation of the database, do not look at the actual situation. Just learn an option.
Client login
bin / mysql -uroot -p
update mysql.user set authentication_string = password (‘root’), password_expired = ‘N’ where user = ‘root’;
flush privileges;
Change the password if you still remember ALTER USER ‘root’ @ ‘localhost’ IDENTIFIED BY ‘root’;
it is best not to use, it may prompt anonymous users do not allow to change the password and the like.
Description
All relevant directories, links, parameters, etc., please adjust according to the actual situation.
1. Background
MySQL database centralized operation and maintenance, through a server, the deployment of running multiple MySQL service process, through a different socket to monitor different service ports to provide their services. Each instance is independent of each other, each instance of the datadir, port, socket, pid are different.
2. Multi-instance features
* Effective use of server resources, when a single server resources are left, you can make full use of the remaining resources to provide more services.
* Resources to each other to seize the problem, when a service instance service is high or open slow query, it will consume more memory, CPU, disk IO resources, resulting in other instances of the server to provide services to reduce the quality.
[root@MySQL ~]# mkdir -v /usr/local/mysql/mysql-files
mkdir: created directory `/usr/local/mysql/mysql-files’
[root@MySQL ~]# mkdir -vp /data/mysql_data{1..4}
mkdir: created directory `/data’
mkdir: created directory `/data/mysql_data1′
mkdir: created directory `/data/mysql_data2′
mkdir: created directory `/data/mysql_data3′
mkdir: created directory `/data/mysql_data4′
[root@MySQL ~]# /etc/init.d/mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is not running
MySQL server from group: mysqld2 is not running
MySQL server from group: mysqld3 is not running
MySQL server from group: mysqld4 is not running
[root@MySQL ~]# /etc/init.d/mysqld_multi start
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
MySQL server from group: mysqld3 is running
MySQL server from group: mysqld4 is running
[root@MySQL ~]# /usr/local/mysql/bin/mysql -S /tmp/mysql.sock1 -p’z+Ilo*>s:3kw’
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.18
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
[root@MySQL ~]# /usr/local/mysql/bin/mysql -S /tmp/mysql.sock2 -p’b*AHUrTgu1rl’
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.18
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
CentOS 7 under the local installation of MySQL 5.7, but the springboot integration jpa will appear hibernateException, do not know why, for a MySQL5.6 version of MySQL, source installation, cmake has been through, and later into rpm installation.
Local installation of mysql5.7, but the integration of springboot jpa will appear hibernateException, do not know why, for a mysql5.6 version of the mysql, source installation, cmake has been through, and later changed to rpm installation
Where el6 identifies centos 6, el7 identifies centos 7
2, installation
Rpm -ivh MySQL- *
3, start
Systemctl start mysql
4, view the initial password
Cat /root/.mysql_secret
5, change the password
Mysql -uroot -pKAKt5JmEjm6B8omV
SET PASSWORD = PASSWORD('root');
6, remote login settings
Mysql> user mysql;
Mysql > select host, user, password from user;
Mysql > update user set password = password ( ' root ' ) where user = ' root ' ;
MySQL > Update the User the SET Host = ' % ' the WHERE the User = ' root ' and Host = ' localhost ' ;
authorized
GRANT ALL PRIVILEGES . ON * * the TO 'root' @ '%' IDENTIFIED BY 'Here is your password' the WITH GRANT
7, set the boot start
[Root @ localhost ~ ] # chkconfig mysql on
[Root @ localhost ~] # chkconfig --list | grep mysql
8, MySQL default installation location
/ Var / lib / mysql / # database directory
/ usr / share / mysql # configuration file directory
/ usr / bin # related command directory
/etc/init.d/mysql # start script
9, modify the default character set and so on
Vim /etc/my.cnf
[client]
password = root
port = 3306
default-character-set=utf8
[mysqld]
port = 3306
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
lower_case_table_names=1
max_connections=1000
[mysql]
default-character-set= utf8
10, view the character set
Show variables like ' % collation% ' ;
Show variables like ' % char% ' ;
Since MySQL 5.6, there have been some improvements in the index, such as the index condition pushdown (ICP), strictly speaking, the optimizer level improvement.
If it is simple to understand, that is, the optimizer will try to index the treatment from the Server layer to the storage engine layer. As an example, there is a table containing the combined index idx_cols containing (c1, c2, …, cn) n columns, if there is a range scan on the where1 condition, then the remaining c2, …, cn this n-1 On the index can not be used to extract and filter data, and ICP is to optimize this thing.
We are in the MySQL 5.6 environment to a simple test.
We create the table emp, which contains a primary key, a combined index to illustrate.
Create Table EMP (
EMPNO smallint The (. 5) unsigned Not null AUTO_INCREMENT,
ename VARCHAR (30) Not null,
DEPTNO smallint The (. 5) unsigned Not null,
Job VARCHAR (30) Not null,
Primary Key (EMPNO),
Key idx_emp_info (DEPTNO, Ename)
) engine = InnoDB charset = utf8;
Of course, I also randomly inserted a few data, meaning that
ICP control in the database parameters have an optimizer parameter optimizer_switch to unified management, I think this is the MySQL optimizer from our closest time. You can use the following way to view.
Show variables like ‘optimizer_switch’;
Of course, in the previous version of 5.6, you can not see the index condition pushdown this kind of words. The results in the 5.6 version are as follows:
In the same way as in the case of the following event: index_merge_switch = on, mrr = on, mrr_cost_based = on, block_nested_loop = on, batched_key_access = off, materialization = On, semijoin = on, loosescan = on, firstmatch = on, subquery_materialization_cost_based_ed, use_index_extensions = on Here we use two statements to compare the description, through the implementation of the plan to contrast.
Set optimizer_switch = “index_condition_pushdown = off”
And if it is turned on, see if ICP is enabled.
Set optimizer_switch = “index_condition_pushdown = on”;> explain select * from emp where deptno between 10 and 3000 and ename = ‘jeanron100’;
> Explain select * from emp where deptno between 1 and 300 and ename = ‘jeanron100’;
+ —- + ————- + ——- + — — + ————— + —— + ——— + —— + —— +
| __- + | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+ —- + ——– —– + ——- + —— + ————— + —— + —— —
| + + + + + _— + | 1 | SIMPLE | emp | ALL | idx_emp_info | NULL | NULL | NULL | 4 | Using where |
+ —- + ————- + ——- + —— + ———– —- + —— + ——— + —— + —— + ————- +
1 row in set (0.00 sec) This place is worth considering.
Recent Comments