Skip to content

Instantly share code, notes, and snippets.

@jingmian
Last active May 7, 2020 09:10
Show Gist options
  • Save jingmian/fda42a292734ca567336874ba75de5f1 to your computer and use it in GitHub Desktop.
Save jingmian/fda42a292734ca567336874ba75de5f1 to your computer and use it in GitHub Desktop.
Centos操作命令
更新指定的 rpm 包,如更新 kernel 和 kernel source
# yum update kernel kernel-source
大规模的版本升级,与 yum update 不同的是,连旧的淘汰的包也升级
# yum upgrade
// yum 安装 gcc 编译环境,为编译 lnmp 做准备
yum install gcc automake autoconf libtool gcc-c++
//安装memcached后运行文件出现can't run as root without the -u switch
可以./memcached -u nobody
// 安装zlib提示已经安装了,但编译的时候依然提示没有安装,那么还需要下载对应软件的开发包
yum install zlib
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirror.as29550.net
* extras: mirror.as29550.net
* updates: mirrors.coreix.net
Package zlib-1.2.3-29.el6.x86_64 already installed and latest version
Nothing to do
yum install zlib-devel //对应开发包
********************************nginx*************************************
#./configure --prefix=/usr/loca
如果提示缺少 pcre库,
则从 http://www.pcre.org/
假设解压在/root/pcre-8.38
假设安装在/usr/local/pcre
4: 再次配置
1.6.X 版本,要求指定 pcre 的源码目录,即:
#./configure --prefix=/usr/local/nginx \
--with-pcre=/root/pcre-8.38/
之前的版本, 指定 pcre 的安装目录,即:
#./configure --prefix=/usr/local/nginx \
--with-pcre=/usr/local/pcre
//启用nginx 是在/usr/local/nginx/sbin目录下,如果还是无法访问,清除防火墙service iptables stop
./nginx
//停止nginx
./nginx -s stop
1.3 Nginx命令参数
如果不愿意用信号来控制, nginx程序也可以一些参数,达到效果
如:
nginx -t 测试配置是否正确
nginx -s reload , 作用:加载最新配置
nginx -s reopen 作用: 重新打开日志(通常是备份日志文件后,需要重新指定新的日志文件地址,文件名只是一个形式而已)
nginx -s stop 作用: 立即停止
nginx -s quit 作用: 优雅停止
//nginx日志文件清空后要需要执行下面命令
./sbin/nginx -s reopen
//配置虚拟主机
Vi ./sbin/nginx.conf
server {
listen 80;
server_name shop.phpvue.top;
access_log logs/shop.access.log main; #配置日志文件信息
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location / {
root /usr/local/www/shop; ----(最后不需要/结尾,$DOCUMENT_ROOT变量对应这个PHP文件路径地址)
index index.php index.html index.htm;
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ /.*\.php/ {
rewrite ^(.*?/?)(.*\.php)(.*)$ /$2?s=$3 last;
break;
}
location ~ \.php$ {
set $file $document_root$fastcgi_script_name;
root /usr/local/www/shop;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT$fastcgi_script_name;
include fastcgi_params;
}
}
============================================lnmp CI伪静态=========================================================
include enable-php-pathinfo.conf;
location / {
index index.php;
try_files $uri $uri/ /index.php?$uri&$args;
}
///如果引入enable-php-pathinfo.conf;则不需要下面配置
location ~ [^/]\.php(/|$)
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf; #请检查是否含有该文件
include pathinfo.conf;
}
===============================================
Free 显示内存状态
用法 free -m -s (-m 表示内存的状态用 M为单位来表示, -s 表示刷新的时间间隔,秒为单位)
示例: free -m -s 3
top (类似于 windows下面的资源管理器)
ps 列出进程
用法 ps -aux |grep php
管道操作
$xx|strtoupper ,竖线前面的内容,作为竖线后的命令的输入参数
80 端口已被 apache或其他 webserver 占
可以用 ps 命令来查找可以进程,然后杀掉.
Pkill -9 进程名
如 pkill -9 httpd
--------------------------------------PHP---------------------------------------------
1、安装libjpeg
wget http://www.ijg.org/files/jpegsrc.v9b.tar.gz
tar zxvf jpegsrc.v9b.tar.gz
cd jpeg-9b
./configure --prefix=/home/admin/app/jpeg --enable-shared --enable-static
make
make install
2、安装php
wget http://cn2.php.net/distributions/php-5.6.27.tar.bz2
tar jxvf php-5.6.27.tar.bz2
cd php-5.6.27
./configure --with-jpeg-dir=/home/admin/app/jpeg --with-gd
make
make install
14.5 编译安装 PHP,基础库使用yum 安装
#yum install gd zlib libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel -y
解压,cd 到 php-5.x
./configure --prefix=/usr/local/php \
--with-gd \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-mysql=mysqlnd \
--enable-mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-fpm \
--with-openssl \
--with-jpeg-dir=/usr/local/jpeg \
--with-xmlrpc \
--with-curl \
--enable-xml \ //可以添加curl
出现如下报错
checking for cURL in default path... not found
configure: error: Please reinstall the libcurl distribution -
easy.h should be in /include/curl/
其实就是curl的dev包没有安装, 解决方案:
yum -y install curl-devel
--enable-fpm \是让 PHP 作为独立的进程来运行(默认占据 9000端口)
解决 Cannot find OpenSSL's <evp.h>
提示openssl选项前提需要安装
yum install openssl openssl-devel
nginx进程和PHP是独立运行的,所以要单独开启php运行,在php文件夹里面
./sbin/php-fpm
--enable-fpm 是让 PHP 作为独立的进程来运行(默认占据 9000
如果是和 apache配合,PHP 一般是作为 apache的模块来使用
PHP 5.6启动nginx失败failed to open configuration file '/usr/local/php/etc/php-fpm.conf'
PHP编译安装完毕,启动失败,提示
1 [23-Jun-2014 12:27:02] ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)
2 [23-Jun-2014 12:27:02] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
3 [23-Jun-2014 12:27:02] ERROR: FPM initialization failed
原因:配置文件没有准备好
解决方法:
进入/usr/local/php/etc目录
cp php-fpm.conf.default php-fpm.conf
=====================================================防火墙====================================================================
1、开放端口
firewall-cmd --zone=public --add-port=5672/tcp --permanent
2、关闭5672端口
firewall-cmd --zone=public --remove-port=5672/tcp --permanent
3.配置立即生效
firewall-cmd --reload
4.查看防火墙所有开放的端口
firewall-cmd --zone=public --list-ports
5.关闭防火墙
systemctl stop firewalld.service
6、查看防火墙状态
firewall-cmd --state
7.查看监听的端口
netstat -lnpt
yum install -y net-tools
8.检查端口被哪个进程占用
netstat -lnpt |grep 5672
------------------apache
//启动apache
service httpd start
==================================--mysql------------------
//添加mysql组和Mysql用户
groupadd mysql
useradd -r -g mysql mysql #-g是让mysql用户属于mysql组
//把mysql文件夹赋予mysql组和mysql用户权限 (为了数据库初始化scripts/mysql_install_db --user=mysql
cd /usr/local/mysql5.5/
chown -R mysql .
chgrp -R mysql .
//mysql文件里面有个说明书INSTALL-BINARY,提示安装libaio
yum install libaio
//在mysql文件里面执行初始化
./scripts/mysql_install_db --user=mysql
//数据库初始化后,单独把文件夹权限归还给root用户,data文件再单独给mysql用户
chown -R root .
chown -R mysql data
//后台启动mysql
./bin/mysqld_safe --user=mysql &
#如果启动失败查看日志,记录在/var/log/mysqld.log
more /var/log/mysqld.log
通常是在/var/run写入一个mysqld文件夹失败,因为/var/run/目录下的对组外没有写的权利,如下
drwxr-xr-x. 13 root root 4096 Sep 1 09:59 run
#解决方法,可以单独在/var/run/新建一个mysqld文件夹,并赋予权限给mysql
mkdir /var/run/mysqld
chown mysql mysqld
chgrp mysql mysqld
//无法打开mysql客户端
can't connect to local mysql server through socket '/tmp.mysql,sock'
mysql会试图来到/tmp.mysql,sock找该文件,
通过ps aux|grep mysql 查看mysql真正的mysql.sock链接文件在哪里
--socket=/var/lib/mysql/mysql.sock
#解决办法,新建一个软链接指向
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
或者直接指定它的sock文件地址打开客户端
./bin/mysql -S /var/lib/mysql/mysql.sock -uroot -p
//如果连接PHP连接数据库出错, Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Permission denied' in
//是因为/var/lib/mysql/无权限读mysql.sock文件进行连接,相当于大门是关闭,可里面的文件是对外开放,这样不合理
#解决方法
chmod o+x /var/lib/mysql
//导入sql语句
source /var/www/shop/tp.sql
//修改root密码,登入mysql客户端选择use mysql库
select Host,User,Password from user;
delete from user where Host!='localhost';
//刷新内存表
flush privileges;
//开机后运行mysql
/usr/local/mysql/bin/mysqld_safe --user=mysql &
//开启Mysql客户端,提前确保运行Mysql服务端了
/usr/local/mysql/bin/mysql -uroot -p
//出现 #2002 - Connection refused &mdash; 服务器没有响应(或本地服务器的套接字没有正确设置)。mysqli_real_connect(): (HY000/2002): Connection refused
在etc/mysql/my.cnf 检查是否配置innodb选项,或者删除文件即可
///////////////////////////////////////////////////问题集合/////////////////////////////
环境:centos X64 最小化安装
php版本:php-5.4.3
安装前.先安装些软件和库文件
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
编译安装PHP
进入php的解压目录
./configure --prefix=/usr/local/php --enable-fpm --with-mcrypt=/usr/local/libmcrypt --with-zlib --enable-mbstring --with-openssl --with-mysql --with-mysqli --with-mysql-sock --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf --enable-pdo --with-pdo-mysql --with-gettext --with-curl --with-pdo-mysql --enable-sockets --enable-bcmath --enable-xml --with-bz2 --enable-zip --enable-freetype
运行之后遇到的问题:
error 1
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.
(看提示就明白 是一个lib库没装 先用 yum search 名字 看是否能搜到名字 ,找到名字后 把软件包 开发包装上)
解决办法
yum install libxml2-devel.x86_64
error 2
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>
这是ssl没装
解决办法
yum install openssl.x86_64 openssl-devel.x86_64 -y
error 3
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
这是bzip2软件包没有安装
解决办法
yum install bzip2-devel.x86_64 -y
error 4
configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
curl和curl库文件没有安装
解决办法
yum install libcurl.x86_64 libcurl-devel.x86_64 -y
error 5
checking whether to enable JIS-mapped Japanese font support in GD... no
checking for fabsf... yes
checking for floorf... yes
configure: error: jpeglib.h not found
GD库没有安装
解决办法
yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y
error 6
checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
libmcrypt库没有安装 ,要是不能用yun安装的话 就要去下载个gz包 自己编译安装
(编译安装 ./configure --piefix=/usr/local/libmcrypt make && make install)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
要是错误里面含有mysql的 那是mysql-devel 没有安装
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
出现
Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating main/php_config.h
config.status: executing default commands
表示安装成功
make && make install
make完成之后 到php的解压目录 找出php.ini-production 复制到 /usr/local/php/lib/ 下 文件名改成php.ini
cp php.ini-production /usr/local/php/lib/php.ini
完成..
==================================================lnmp的my.cnf========================================
可能比如你之前通过apt-get 或Yum安装了一些依赖库,导致/etc/myslq/my.cnf也有这个文件,用查看 dpkg -l|grep mysql 依赖了哪个包
mysql版本不同、机器配置不同的话配置文件参数也不一样
一下为mysq 5.5,开启innodb,数据库目录自行替换
######start########
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
datadir = 数据库目录
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 8
query_cache_size = 8M
tmp_table_size = 16M
log_error =/var/log/mysql/errormysql.log #记录mysql启动服务器的错误,需要放在[mysqld]下面
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
#自动删除了多余天数的日志
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_data_home_dir = 数据库目录
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = 数据库目录
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
==========================删除ib_logfile0和ib_logfile1启动失败==========================================
/etc/my.conf
innodb_force_recovery=6
启动mysql后备份数据,尝试修复表,再去掉innodb_force_recovery=6 重启看看能否正常
#用innodb引擎的话是存在ibdata1中,如果用的是myisam引擎的话是.MYD (数据都在ibdata1文件,不能删除)
======================================定时备份数据库============================================
yum install crontabs
说明:
/sbin/service crond start //启动服务
/sbin/service crond stop //关闭服务
/sbin/service crond restart //重启服务
/sbin/service crond reload //重新载入配置
加入开机自动启动:
chkconfig –level 35 crond on
crontab 格式:
基本格式 :
分钟 小时 日 月 星期 命令
* * * * * *
每五分钟执行 */5 * * * *
每五小时执行 0 */5 * * *
每天执行 0 0 * * *
每周执行 0 0 * * 0
每月执行 0 0 1 * *
每年执行 0 0 1 1 *
cd home/test
[root@win7 test]# touch test_database_backup.sh
[root@win7 test]# chmod 770 test_database_backup.sh
vim test_database_backup.sh #编辑脚本文件
#备份地址
backupdir=/home/test
#备份文件后缀时间
time=_` date +%Y_%m_%d_%H_%M_%S `
#需要备份的数据库名称
db_name=test
#mysql 用户名
#db_user=
#mysql 密码
#db_pass=
#mysqldump命令使用绝对路径
/usr/local/mysql/bin/mysqldump -hlocalhost -P3306 -uroot -proot $db_name > $backupdir/$db_name$time.sql
#删除7天之前的备份文件
#find $backupdir -name $db_name"*.sql.gz" -type f -mtime +7 -exec rm -rf {} \; > /dev/null 2>&1
#编辑定时任务
crontab -e
* * * * * /usr/bin/php -f /home/wwwroot/default/test.php >> /tmp/test.log #测试
* * * * * /home/test/test_database_backup.sh >> /home/test/test_database_backup.log
#比如我的登录账号是root。则会存在一个root文件。该文件的内容就是刚添加的crontab任务,删除即取消定时任务
#日志
cat /var/log/cron
-------------------------------------查看bin二进制文件-----------------------------
//1、查询时间段内日志的执行内容
mysqlbinlog --start-datetime='2018-01-08 02:01:00' --stop-datetime='2018-01-08 02:30:10' -d test /usr/local/mysql/var/mysql-bin.000170 -v
//2、查询时间段内日志中执行的删除语句
mysqlbinlog --start-datetime='2018-01-08 02:01:00' --stop-datetime='2018-01-08 02:30:10' -d test /usr/local/mysql/var/mysql-bin.000170 -v|grep DELETE -A 5
//3、统计时间段内日志中执行的删除语句
mysqlbinlog --start-datetime='2018-01-08 02:01:00' --stop-datetime='2018-01-08 02:30:10' -d test /usr/local/mysql/var/mysql-bin.000170 -v|grep DELETE |wc -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment