Linux Learning notes one by one
- Linux Learning Note 11
- Daily management of Linux systems
- Wireshark Tools
- Task Scheduler for Linux Systems
- Some new changes in Rhelcentos 7x
- Curl Common Commands
- Lamp Environment Construction
- Install MySQL
- Installing Apache
- Installing MD5 validation Files
- Apache Install extension Module-mod_status
- Install PHP
- Get PHP
- PHP Expansion Module Installation-Memcache
- Common tricks
- LNMP Environment Construction
- Installing Nginx
- Start up error job for Nginxservice failed because the control
- Access has been 502 error
- Common MySQL Operations
- MySQL Backup
- MySQL Recovery
- NFS Service Configuration
- CentOS 7 Installation Configuration NFS
- Run script after system boot is complete
- MySQL Tuning
- MySQL adjusts several key buffer and cache and other parameter adjustments
daily management of Linux systems
Http://www.apelearn.com/study_v2/chapter16.html
Wireshark Tools
Installation:yum install -y wireshark
Use the command:
tshark -n -t a -R http.request -T fields -e "frame.time" -e "ip.src" -e "http.host" -e "http.request.method" -e "http.request.uri"
Task Scheduler for Linux Systems
crontab
PS: You can vim /etc/crontab
edit the configuration information with view.
Options:
>
-u
: Specifies a user, without the-u option, for the current user
-e
: To make a planning task;
-l
: List Scheduled Tasks;
-r
: Deletes a scheduled task.
Example: Making a scheduled task
crontab -e
Open configuration file
In the pop-up input box, enter56 18 6 4 3 touch c.txt
PS: This sentence means: 18:56 on April 6 (Wednesday) to create a c.txt
file, can be used in *
place of the Time field, representing any one, such as the first fields *
, it represents any (every) one minute.
PS: * * * * * user-name command
from left to right, in order: minute, time, day, month, week, user, command line. The user can be omitted, omitted, represents the current user.
PS: crontab -e
This file is actually opened /var/spool/cron/username
(if it is root /var/spool/cron/root
). The Vim editor is used, so if you want to save it, enter it in command mode: Wq. However, do not directly edit that file, because there may be errors, so be sure to use crontab -e
to edit. View Scheduled Tasks use crontab -l
commands, delete scheduled Tasks crontab -r
, or use crontab -e -u 用户名
to edit a specified user's schedule task. Of course, viewing and deleting can also specify the user's.
After you have set up all the scheduled tasks, you need to check to see if the Crond service is started: service crond status
, if it is off, you need to start: service crond start
.
Case:
Problem:
每天凌晨1点20分清除/var/log/slow.log这个文件
每周日3点执行 “/bin/sh /usr/local/sbin/backup.sh”
每月14号4点10分执行 “/bin/sh /usr/local/sbin/backup_month.sh”
每隔8小时执行 “ntpdate time.windows.com”
每天的1点,12点,18点执行 “/bin/sh /usr/local/sbin/test.sh”
每天的9点到18点执行 “/bin/sh /usr/local/sbin/test2.sh”
Answer:
20 1 * * * echo "" > /var/log/slow.log
0 3 * * 0 /bin/sh /usr/local/sbin/backup.sh
10 4 14 * * /bin/sh /usr/local/sbin/backup_month.sh
0 */8 * * * nepdate time.windows.com
0 1,12,18 * * * /bin/sh /usr/local/sbin/test.sh
0 9-18 * * * /bin/sh /usr/local/sbin/test2.sh
some new changes in Rhel/centos 7.x
Http://www.ha97.com/5657.html
Curl Common Commands
Http://www.cnblogs.com/gbyukg/p/3326825.html
Lamp Environment Construction
Http://www.apelearn.com/study_v2/chapter17.html#lamp
install MySQL
wget http://cdn.mysql.com/archives/mysql-5.1/mysql-5.1.30-linux-x86_64-icc-glibc23.tar.gz
Linux install MySQL times wrong libstdc++.so.5:cannot open shared object file:no such file or directory
Use yum install -y compat-libstdc++-33
installation support.
Installing Apache
installing MD5 validation Files
yum install -y isomd5sum
Apache Install extension module-mod_status
/usr/local/apache2/bin/apachectl -l
Yesmod_so.c
Enter the module directory:
cd /usr/local/src/httpd-2.2.24/modules/generators/
Installation module:
/usr/local/apache2/bin/apxs -i -a -c -n mod_status mod_status.c
vim /usr/local/apache2/conf/httpd.conf
Install PHP
Get PHP
Go to Catalogcd /usr/local/src
Download filewget http://cn2.php.net/distributions/php-5.5.34.tar.gz
PHP Expansion Module Installation-Memcache
wget http://www.lishiming.net/data/attachment/forum/memcache-2.2.3.tgz
tar zxvf memcache-2.2.3.tgz
cd memcache-2.2.3
yum install -y autoconf
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
vim /usr/local/php/etc/php.ini
PS: This module installs, in the PHP7 will prompt 致命错误:ext/standard/php_smart_str.h:没有那个文件或目录
, this should be the version compatibility issue, if installs the suggestion to use the old version PHP.
Common Tricks
View Apache Compilation parameterscat /usr/local/apache2/build/config.nice
View Apache-loaded modules/usr/local/apache2/bin/apachectl -M
Test the Apache configuration file correctly/usr/local/apache2/bin/apachectl -t
After you change the configuration file, reload/usr/local/apache2/bin/apachectl graceful
View MySQL Compilation parameterscat /usr/local/mysql/bin/mysqlbug|grep configure
View PHP Compilation parameters/usr/local/php/bin/php -i |head
View PHP Loading module/usr/local/php/bin/php -m
See where PHP.ini is/usr/local/php/bin/php -i |grep ‘Configuration File‘
View Extension_dir Path/usr/local/php/bin/php -i |grep ‘extension_dir‘
LNMP Environment Construction
Http://www.apelearn.com/study_v2/chapter18.html#lnmp
Installing Nginx
Startup error Job for nginx.service failed because the control
occurred
The reason is that Apache and Nginx listen to the same port conflict. You can choose to stop Apache or change the Nginx listening port.
[[email protected] nginx-1.4.4]# /usr/local/apache2/bin/apachectl stop
[[email protected] nginx-1.4.4]# netstat -lnp |grep httpd
[[email protected] nginx-1.4.4]# /etc/init.d/nginx start
Starting nginx (via systemctl): [ 确定 ]
[[email protected] nginx-1.4.4]#
PS: Here is the first way.
Access has been 502 error
PS: This problem, looked for a long time did not solve, and later again.
PS: Look for the error log later to vim /usr/local/nginx/logs/nginx_error.log
find the following error
2016/04/08 19:27:18 [crit] 887#0: *1 connect() to unix:/tmp/php-fcgi.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /2.php HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-fcgi.sock:", host: "localhost"
The core is just connect() to unix:/tmp/php-fcgi.sock failed (13: Permission denied)
this paragraph.
Then find out if /tmp/php-fcgi.sock
there is a problem with this file permission, attach the change record:
[[email protected] Desktop]# curl localhost/2.php
<body bgcolor="white">
<center> </body>
[[email protected] Desktop]# ls -lh /tmp/php-fcgi.sock
srw-rw---- 1 root root 0 4月 8 19:26 /tmp/php-fcgi.sock
[[email protected] Desktop]# chmod 777 /tmp/php-fcgi.sock
[[email protected] Desktop]# ls -lh /tmp/php-fcgi.sock
srwxrwxrwx 1 root root 0 4月 8 19:26 /tmp/php-fcgi.sock
[[email protected] Desktop]# curl localhost/2.php
ok[[email protected] Desktop]#
Common MySQL Operations
Http://www.apelearn.com/study_v2/chapter19.html#mysql
MySQL backup
mysqldump -u root -p‘密码‘ -h ‘主机地址‘ -P‘端口号‘ --default-character=字符集 数据库名 > /tmp/mysql.sql
PS: Remote backup requires -h``-P
options, you can specify the default character set.
MySQL Recovery
mysql -u root -p‘密码‘ --default-character=字符集 数据库名 </tmp/mysql.sql
NFS Service Configuration
Http://www.apelearn.com/study_v2/chapter20.html#nfs
CentOS 7 Installation configuration NFS
Http://www.linuxidc.com/Linux/2015-05/117378.htm
run script after system boot is complete
vim /etc/rc.local
PS: You can add to this file some commands that need to be run with the boot.
MySQL tuning
Architecture layer: Do from the library, to achieve read and write separation
System level: Increase memory, do RAID0 or RAID5 disk to increase the disk read and write speed, can re-mount the disk, and add noatime parameters, so as to reduce the disk I/O;
-
MySQL itself tuning:
-
(1) If the master-slave synchronization is not configured, you can turn off the Log-bin function and reduce the disk I/O
-
(2) in the my.cnf with Skip-name-resolve, which avoids the slow MySQL execution due to the resolution of host name delay
-
(3) adjusts several key buffer and cache. The basis of adjustment, mainly according to the state of the database debugging.
Application hierarchy: View the slow query log, based on SQL statements in the slow query log optimizer, such as increasing the index
MySQL adjusts several key buffer and cache and other parameter adjustments
-
-
Content:
-
-
1) Key_buffer_size first can be based on the system's memory size set it, probably a reference value: 1G or less memory settings 128m;2g/256m; 4g/384m;8g/1024m;16g/2048m. This value can be checked by checking the status values key_read_requests and key_reads to see if the key_buffer_size settings are reasonable. The proportional key_reads/key_read_requests should be as low as possible, at least 1:100,1:1000 better (the above status values can be obtained using the show status like ' key_read% '). Note: This parameter value setting is too large to be the overall efficiency of the server down!
-
-
2) Table_open_cache open a table, will temporarily put the data inside the table in this part of memory, generally set to 1024 is enough, its size we can measure by this way: if you find Open_tables equals Table_ Cache, and Opened_tables is growing, you need to increase the value of Table_cache (the above status values can be obtained using the show status like ' Open%tables '). Note that you cannot blindly set the Table_cache to a very large value. If set too high, it may cause insufficient file descriptors, resulting in performance instability or connection failures.
-
-
3) Sort_buffer_size the size of the buffer that can be used when the query is sorted, the allocated memory for that parameter is per-connection exclusive! If there are 100 connections, the actual allocated total sort buffer size is 100x4 = 400MB. Therefore, the recommended setting for a server that has around 4GB is 4-8m.
-
-
4) read_buffer_size The buffer size that can be used for sequential read query operations. As with Sort_buffer_size, the allocated memory for this parameter is exclusive to each connection!
-
-
5) join_buffer_size The buffer size that can be used by the Federated query operation, as with Sort_buffer_size, the allocated memory for this parameter is exclusive to each connection!
-
-
6) Myisam_sort_buffer_size This buffer is primarily used to fix the memory used by the sort index during the table process or the memory size used to sort the index when indexing, generally 4G memory to 64M.
-
-
7) query_cache_size MySQL query operation buffer size, adjusted by the following practices: SHOW STATUS like ' qcache% ' if qcache_lowmem_ Prunes this parameter records how many queries have been removed from the query cache because of insufficient memory. With this value, the user can adjust the cache size appropriately. If the value is very large, it indicates that buffering is often insufficient, and the cache size needs to be increased; Qcache_free_memory: Query cache memory size, through this parameter can be very clear know the current system query memory is sufficient, is more, or not enough, we can make adjustments according to the actual situation. In general, 4G memory setting 64M is sufficient.
-
-
8) thread_cache_size indicates that the number of threads stored in the cache can be re-used, referring to the following values:1g-> 8 2g-> 3g-> >4G->
-
-
9) Thread_concurrency This value is set to twice times the number of CPU cores
-
-
wait_timeout indicates idle connection timeout, default is 28800s, this parameter is used with Interactive_timeout, that is, to make the parameter effective, you must set the Interactive_timeout , it is recommended that both of them are set to ten
-
-
one) max_connect_errors is a security-related counter value in MySQL that is responsible for blocking excessive attempts by clients that fail to prevent brute-force password violations. is not much related to performance. In order to avoid some errors, we generally set a larger, such as 10000
-
-
max_connections Maximum number of connections, according to the amount of business request to adjust appropriately, set 500 enough
-
-
max_user_connections refers to the maximum number of connections that the same account can connect to the MySQL service at the same time. Set to 0 to indicate no limit. Usually we set it to 100 enough
Refer to "Learn Linux with Amin"
Linux Learning Notes