Linux实战

 

  1. Linux基础与基本配置
    1. 常用指令

cd /etc:进入目录,ll:显示目录详细列表,ls:显示目录所有文件和子目录,pwd:显示当前目录路径,date:修改日期时间,top:看CPU情况,mkdir:创建目录,vi index.html创建/修改文件,cat index.html查看文件,tail –n 10 index.html:查看文件最后10行,yum –y install php:安装php, yum –y remove php:卸载PHP,find / -name index.html:名字查找文件,whereis php。

echo “” > filename

/usr/local/nginx/sbin/nginx -s reload

systemctl stop php-fpm.service

/etc/init.d/php-fpm restart

service firewalld stop //关闭Centos 7防火墙

          dstat -nt //查看网络

netstat -an |grep ^tcp.*:80|egrep -v 'LISTEN|127.0.0.1'|awk -F"[ ]+|[:]" '{print $6}'|sort|uniq -c|sort -rn|awk '{if ($1>20){print $2}}' 查服务器单IP并发

netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' 

查服务器并发

cat /proc/cpuinfo |grep "cores"|uniq     #查看CPU多少核

cat /proc/cpuinfo |grep MHz|uniq      #查看CPU频率

ps -ef | grep sersync2                  #查看进程

tail -n 20 /var/log/php-fpm/www-error.log #查看PHP报错

chmod -R  777 /trunk           #改权限

chown root root /trunk

cat /etc/redhat-release        #查看OS版本

arch                           #查看OS多少位

tar -zxvf nginx-1.8.0.tar.gz   #tar解压

du -h --max-depth=1 /alidata/cache   #查看文件夹大小

rpm -qa | grep -i mysql        #查看软件的版本

ab -c 1000 -n 100 http://test65.suofeiya.com.cn/index.php

ipconfig /flushdns               #刷新DNS

find /www -name "*.log" | xargs greg "卡券插件命中结束"

ps aux | grep rsync | grep -v grep | cut -c 9-15 | xargs kill -s 9                    杀死进程

date -s 12:49:00

如果YUM被锁住,可以使用rm -rf /var/run/yum.pid

zip -r mydata.zip mydataunzip wwwroot.zip

    1. 大部分用VMWare安装,度娘一堆教程。
    2. 安装时候,把FTP也一起装上。
    3. VMWare IP地址配置成可用的网段。
    4. 一定要设置setenforce 0      #不设置的话,会有各种杯具。
      1. 当出现setenforce: SELinux is disabled

vi /etc/selinux/config

把SELINUX=disabled改成SELINUX=enforcing

    1. 如果需要不重启SELINUX生效的方法:

/etc/init.d/network restart

    1. 如果是RedHat,配置YUM。
      1. 检查是否安装了YUM:

rpm-qa|grep yum

    1. 删除yum包

rpm -qa|grep yum|xargs rpm -e --nodeps

再次确认:rpm–qa|grep yum

    1. 下载新的yum包。使用Centos6.5的yum包

1) 查看版本号和系统类别:

cat /etc/redhat-release

arch

2)根据上一步,找到对应的yum包,然后下载。我的服务器对应的为:

wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm

wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-69.el6.centos.noarch.rpm

wgethttp://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-30.el6.noarch.rpm

    1. 安装

rpm -ivhyum-metadata-parser-1.1.2-16.el6.x86_64.rpm yum-3.2.29-69.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-30.el6.noarch.rpm

如果出错,证明

    1. 更换yum源,将原有源删除或备份到别的目下:

cd /etc/yum.repos.d/

wget  http://mirrors.163.com/.help/CentOS6-Base-163.repo

vi CentOS6-Base-163.repo

编辑文件,把文件里面的$releasever全部替换为版本号:6(注意,不是6.5!)最后保存!

    1. 清除原有缓存,重建缓存,更新系统:

clean all

yum makecache

yum update

  1. Nginx安装配置

systemctl enable httpd  ####开启apache

    1. 安装

cd /usr/src

#下载lnmp

wget http://nginx.org/download/nginx-1.8.0.tar.gz

chmod +x nginx-1.8.0.tar.gz

tar -zxvf nginx-1.8.0.tar.gz

#安装必备工具

rpm -qa | grep -i nginx

yum  -y install zlib-devel pcre-devel openssl-devel

#安装nginx

cd nginx-1.8.0

./configure --prefix=/usr/local/nginx --with-openssl=/usr/include/openssl --with-pcre --with-http_stub_status_module

make

make install

cd /usr/local/nginx/                  #安装成功

sbin/nginx -c /usr/local/nginx/conf/nginx.conf  #设置配置文件路径

/usr/local/nginx/sbin/nginx -s reload            #启动nginx

netstat -ntlp                     #看看nginx是否已经用上80

    1. 分发配置

vi nginx.conf

#user  nobody;

worker_processes  4;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

    worker_connections  10240;

}

http {

include       mime.types;

    default_type  application/octet-stream;

    #access_log  logs/access.log  main;

sendfile        on;

    #tcp_nopush     on;

    #keepalive_timeout  0;

    keepalive_timeout  65;

gzip  on;

gzip_disable     "MSIE [1-6]\.";

gzip_proxied any;

    gzip_comp_level 5;

    gzip_buffers 16 8k;

gzip_min_length    1k;

gzip_vary on;

gzip_types text/plain text/css image/gif image/jpeg image/png application/json application/x-javascript text/xml application

/xml application/xml+rss text/javascript;

fastcgi_connect_timeout 300s;

fastcgi_send_timeout 300s;

fastcgi_read_timeout 300s;

fastcgi_buffer_size 128k;

fastcgi_buffers 8 128k;#8 128

fastcgi_busy_buffers_size 256k;

fastcgi_temp_file_write_size 256k;

fastcgi_intercept_errors on;

client_max_body_size 20M;

upstream backend {

                  ip_hash;

server 10.10.10.210:80;

server 10.10.10.211:80;

        }

include conf.d/*.conf;

}

           编辑conf.d/ wx.suofeiya.com.cn.conf;

server {

listen       80;

        server_name  wx.suofeiya.com.cn;

location / {

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_buffering off;

            proxy_pass http://backend;

        }

}

编辑conf.d/tb.suofeiya.com.cn.conf;

upstream tb_site {

server 192.168.2.123;

        }

server {

listen       80;

        server_name  tb.suofeiya.com.cn;

location / {

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_buffering off;

            proxy_pass http://tb_site;

        }

}

    1. 节点配置

server {

listen       80;

        server_name  wx.suofeiya.com.cn;

location / {

root   /www/wechat/app/www;

index  index.php index.html index.htm;

        }

        error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

        }

location ~ \.php$ {

            #root           html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /www/wechat/app/www$fastcgi_script_name;

include        fastcgi_params;

        }

}

    1. 启动

# /usr/local/nginx/sbin/nginx -s reload

# vi /etc/rc.local

/usr/local/nginx/sbin/nginx

    1. 防火墙

yum install -y iptables

yum install iptables-services

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

-A INPUT -s 10.10.10.0/24 -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT

要封停一个IP,使用下面这条命令:

    iptables -I INPUT -s ***.***.***.*** -j DROP

要解封一个IP,使用下面这条命令:

iptables -D INPUT -s ***.***.***.*** -j DROP

    1. 伪静态

location / {

root   /www;

index  index.php index.html index.htm;

rewrite "^/index\.html" /index.php last;

rewrite "^/search\.html$"    /search.php last;

rewrite "^/channel_space\.html$"    /channel_space.php last;

rewrite "^/channel_style\.html$"    /channel_style.php last;

rewrite "^/channel_action\.html$"   /channel_action.php last;

rewrite "^/wiki_channel\.html$"     /wiki_channel.php last;

rewrite "^/dealer\.html$"          /dealer.php last;

rewrite "^/bespoke\.html$"         /bespoke.php last;

rewrite "^/budget\.html$"           /budget.php last;

rewrite "^/baoming\.html$"         /baoming.php last;

    1. 缓存
      1. 缓存插件安装

当安装完nginx,缺忘记安装Ngx_cache怎么办呢?

Cd /usr/src

wgethttp://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz

tar–zxvfngx_cache_purge-2.3.tar.gz

chmod–R 777 ngx_cache_purge-2.3

cdnginx-1.8.0

./configure --add-module=../ngx_cache_purge-2.3 --prefix=/usr/local/nginx --with-openssl=/usr/include/openssl --with-pcre --with-http_stub_status_module

Make

备份/usr/local/nginx/sbin/nginx

把objs/nginx复制过去

重启nginx

/usr/local/nginx/sbin/nginx –V

    1. 缓存配置

use epoll;

worker_connections  30720;

gzip_disable     "MSIE [1-6]\.";

gzip_proxied any;

        gzip_comp_level 5;

        gzip_buffers 16 8k;

gzip_min_length    1k;

gzip_vary on;

gzip_types text/plain text/css image/gif image/jpeg image/png application/json application/x-javascript text/xml application

/xml application/xml+rss text/javascript;

        proxy_connect_timeout 5;

        proxy_read_timeout 60;

        proxy_send_timeout 5;

proxy_buffer_size 16k;

        proxy_buffers 4 64k;

proxy_busy_buffers_size 128k;

proxy_temp_file_write_size 128k;

        proxy_temp_path /usr/local/cache/img_temp;

        proxy_cache_path /dev/shm/tmp levels=1:2 keys_zone=pic_cache:500m inactive=1d max_size=10g;

include conf.d/*.conf;

server {

listen       8082;

        server_name  localhost;

        access_log  logs/pic.log;

location / {

                proxy_cache pic_cache;

                proxy_cache_valid 200 304 2h;

                proxy_cache_key $host$uri$is_args$args;

proxy_set_header Host  $host;

proxy_set_header X-Forwarded-For  $remote_addr;

                proxy_pass http://127.0.0.1:8083;

expires      1d;

        }

location ~ /purge(/.*) {

allow       127.0.0.1;

deny    all;

                proxy_cache_purge    pic_cache   $host$1$is_args$args;

        }

        error_page   500 502 503 504  /50x.html;

    }

server {

listen 8083;

server_name localhost;

root /usr/local/cache/img_s;

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ {

expires      1d;

access_log logs/8083pic.log;

        }

}

#mkdir /dev/shm/tmp

#chmod 1777 /dev/shm/tmp

#mount --bind /dev/shm/tmp /alidata/cache/img_cache

  1. 安装PHP
    1. 增加额外资源库

默认情况下,CentOS的官方资源是没有php-fpm的, 但我们可以从Remi的RPM资源中获得,它依赖于EPEL资源。

# yum install yum-priorities -y

# rpm -Uvh http://baseurl.opencas.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm

# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

yum -y remove mysql-libs*

rpm -qa | grep –i php

    1. 安装 PHP-FPM

# yum --enablerepo=remi install php php-fpm

#chkconfig --level 345 php-fpm on       #开机自动启动

    1. 安装PHP插件

# yum --enablerepo=remi install php-gd php-mysql php-mbstring php-xml php-mcrypt  php-redis php-soap

    1. 启动PHP

# /etc/init.d/php-fpm restart 

#systemctl stop php-fpm.service

# setsebool httpd_can_network_connect 1

# vi /etc/rc.local #把/etc/init.d/php-fpm restart加进去

修改PHP.INI的配置,可以参考图库项目的配置

  1. Redis
    1. 安装

wget http://download.redis.io/releases/redis-3.0.4.tar.gz

ls

tar -zxvf redis-3.0.4.tar.gz

cd redis-3.0.4

ls

make

make install

redis-server &#开启

       #关连接,重新登录服务器

redis-cli

set xx 123

get xx

    1. 配置

防火墙:-A INPUT -s 10.10.10.0/24 -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT

开机启动

# Vi /etc/rc.local

redis-server&

  1. Rsync服务端
    1. rsync 启动

#vi /etc/xinetd.d/rsync

  把原来的YES改成NO

service rsync

{

disable = no

        socket_type     = stream

wait            = no

user            = root

server          = /usr/bin/rsync

        server_args     = --daemon

        log_on_failure  += USERID

}

随系统启动RSYNC

     #chkconfig rsync on

    1. Rsync配置

# vi /etc/rsyncd.conf

# Minimal configuration file for rsync daemon

# See rsync(1) and rsyncd.conf(5) man pages for help

# This line is required by the /etc/init.d/rsyncd script

pid file = /var/run/rsyncd.pid

port = 873

address = 10.10.10.211 #本机IP

uid = root

gid = root

use chroot = yes

read only = yes

#limit access to private LANs

hosts allow=192.168.5.0/255.255.255.0(如果是指定几台机器,用逗号分开,或者*)

hosts deny=*

max connections = 50

#motd file = /etc/rsyncd/rsyncd.motd

#This will give you a separate log file #log file = /var/log/rsync.log

#This will log every file transferred - up to 85,000+ per user, per sync

#transfer logging = yes

log format = %t %a %m %f %b

syslog facility = local3

timeout = 300

[website]

path = /usr/website/

list=yes

read only = no

ignore errors

auth users = nobody

secrets file = /etc/rsync/rsyncd.secrets

comment = linuxsir home

#exclude =   beinan/  samba/

    1. 密码文件

# vi /etc/rsync/rsyncd.secrets

nobody:002285kss

    1. 启动xinetd

# service xinetd restart

启动rsync

# sudo /usr/bin/rsync --daemon --config=/etc/rsync/rsyncd.conf

建立快捷方式:

# ln -s /etc/rsync/rsyncd.conf /etc/rsyncd.conf

# service xinetd reload

#vi /etc/rc.local

/usr/bin/rsync –daemon --config=/etc/rsync/rsyncd.conf

#netstat -a | grep rsync

tcp   0      0 0.0.0.0:873     0.0.0.0:*    LISTEN

  1. Rsync客户端
    1. 安装

# mkdir /etc/rsync

# vi /etc/rsync/rsyncd.secrets

002285kss

# chown root.root rsyncd.secrets

# chmod 700 rsyncd.secrets

# /usr/bin/rsync -artuz --progress --delete nobody@10.10.10.210::website /usr/local/nginx/html --password-file=/etc/rsync/rsyncd.secrets

# vi /etc/rsync/time.sh

#!/bin/bash

/usr/bin/rsync -artuz --progress --delete nobody@10.10.10.210::website /www --password-file=/etc/rsync/rsyncd.secrets

# chmod +x /etc/rsync/time.sh

# crontab -e

3 * * * * /etc/rsync/time.sh

    1. 测试

# rsync --list-only nobody@10.10.10.210::

下载文件:

# /usr/bin/rsync -artuz --progress --delete nobody@10.10.10.210::website /usr/local/nginx/html --password-file=/etc/rsync/rsyncd.secrets

上传文件:

# /usr/bin/rsync -artuz --progress --exclude='.svn/'--password-file=/usr/local/sersync/rsyncd.passwd  /alidata/www/www.suofeiya.com.cn/ nobody@120.26.85.64::website

  1. Sersync
    1. 安装

sersync2.5_64bit_binary_stable_final.tar.gz,解压到/usr/local/sersync/

# cd/usr/local/sersync/

建立密码文件/usr/local/sersync/rsyncd.passwd 写入与服务器A上rsync配置的用户一样的密码。

# vi confxml.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<head version="2.5">

<host hostip="localhost" port="8008"></host>

<debug start="false"/>

<fileSystem xfs="false"/>

<filter start="false">  /*过滤不需要同步的文件或目录*/

<exclude expression="(.*)\.svn"></exclude>

<exclude expression="(.*)\.gz"></exclude>

<exclude expression="^info/*"></exclude>

<exclude expression="^static/*"></exclude>

</filter>

<inotify>

<delete start="true"/>

<createFolder start="true"/>

<createFile start="false"/>

<closeWrite start="true"/>

<moveFrom start="true"/>

<moveTo start="true"/>

<attrib start="false"/>

<modify start="false"/>

</inotify>

<sersync>

<localpath watch="/usr/website/">/*本地监视目录*/

<remote ip="192.168.5.168" name="website"/>/*远程IP*/

<!--<remote ip="192.168.8.39" name="tongbu"/>-->

<!--<remote ip="192.168.8.40" name="tongbu"/>-->

</localpath>

<rsync>

<commonParams params="-artuz"/>/*rsync命令*/

<auth start="true" users="nobody" passwordfile="/usr/task/shell/rsyncd.passwd"/>/*密码文件*/

<userDefinedPort start="false" port="874"/><!-- port=874 -->

<timeout start="false" time="100"/><!-- timeout=100 -->

<ssh start="false"/>

</rsync>

<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->

<crontab start="false" schedule="600"><!--600mins-->

<crontabfilter start="false">

<exclude expression="*.php"></exclude>

<exclude expression="info/*"></exclude>

</crontabfilter>

</crontab>

<plugin start="false" name="command"/>

</sersync>

<plugin name="command">

<param prefix="/bin/sh" suffix="" ignoreError="true"/><!--prefix /opt/tongbu/mmm.sh suffix-->

<filter start="false">

<include expression="(.*)\.php"/>

<include expression="(.*)\.sh"/>

</filter>

</plugin>

<plugin name="socket">

<localpath watch="/opt/tongbu">

<deshost ip="192.168.138.20" port="8009"/>

</localpath>

</plugin>

<plugin name="refreshCDN">

<localpath watch="/data0/htdocs/cms.xoyo.com/site/">

<cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>

<sendurl base="http://pic.xoyo.com/cms"/>

<regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>

</localpath>

</plugin>

</head>

    1. 启动sersync

# /usr/local/sersync/sersync2 -r -d -o /usr/local/sersync/confxml.xml

查看进程

# psaux | grep sersync2

杀死进程

# kill -9 11374

查看进程状态

# ps aux |grep 'sersync2'

    1. 开机启动

# vi /etc/rc.local

/usr/local/sersync/sersync2 -r -d -o /usr/local/sersync/confxml.xml

    1. 监视

# vi /var/script/check_sersync.sh

#!/bin/bash

#Purpose: Check sersync whether it is alive

#Author: Carl Zhang

SERSYNC="/usr/local/sersync/sersync2"

CONF_FILE="/usr/local/sersync/confxml.xml"

STATUS=$(ps aux |grep 'sersync2'|grep -v 'grep'|wc -l)

if [ $STATUS -eq 0 ];

then

        $SERSYNC -d -r -o $CONF_FILE &

else

exit 0;

fi

# crontab -e

*/5 * * * * /var/script/check_sersync.sh > /dev/null 2>&1

  1. Mysql

http://blog.csdn.net/liumm0000/article/details/18841197

    1. 安装

wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz

ls

tar zxvf mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz

cp mysql-5.6.28-linux-glibc2.5-x86_64 /usr/local/mysql -r

cd /usr/local/mysql/

ls

ll

########groupadd mysql     //创建mysql组

########useradd -g mysql mysql //创建mysql用户添加到mysql组

chown -R mysql:mysql ./

ls

ll

./scripts/mysql_install_db --user=mysql

chown -R root:root ./

chown -R mysql:mysql data

cp support-files/mysql.server /etc/init.d/mysql

service mysql start

mysql

ps -ef|grep mysql

ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

    1. 配置

# vi /etc/my.cnf

[client]

port            = 3306

socket          = /var/lib/mysql/mysql.sock

[mysqld]

port            = 3306

socket          = /var/lib/mysql/mysql.sock

skip-external-locking

key_buffer_size = 500M

max_allowed_packet = 32M

table_open_cache = 512

sort_buffer_size = 4M

net_buffer_length = 8K

read_buffer_size = 4M

read_rnd_buffer_size = 512K

myisam_sort_buffer_size = 64M

query_cache_size = 1024M

query_cache_type= 1

tmp_table_size = 256M

max_connections = 1000

max_connect_errors = 10000000

wait_timeout = 10

max_binlog_size=1G

log-bin=mysql-bin

binlog_format=mixed

server-id       = 1

#skip-grant-tables

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

    1. 密码修改,防火墙,开机运行

http://blog.csdn.net/liumm0000/article/details/18841197

SET GLOBAL general_log = 'ON';

SET GLOBAL slow_query_log = 'ON';

set global expire_logs_days = 3;

show global variables;

-- 打开sql 执行记录功能

set global log_output='TABLE'; -- 输出到表

set global log=ON; -- 打开所有命令

执行记录功能general_log, 所有语句: 成功和未成功的.

set global log_slow_queries=ON; -- 打开慢查询 sql 记录

slow_log, 执行成功的: 慢查询语句和未使用索引的语句

set global long_query_time=0.1; -- 慢查询时间限制(秒)

set global log_queries_not_using_indexes=ON; -- 记录未使用索引的sql 语句

-- 查询sql 执行记录

select * from mysql.slow_log order by 1; -- 执行成功的:慢查询语句,和未

使用索引的语句

select * from mysql.general_log order by 1; -- 所有语句:成功和未成功的.-- 关闭sql 执行记录

    1. 主从

vi /etc/my.cnf

[mysqld]的下面加入下面代码:

log-bin=mysql-bin

server-id=1

    innodb_flush_log_at_trx_commit=1

    sync_binlog=1

    #binlog-do-db=wordpress

#binlog_ignore_db=mysql

$ service mysqld restart

mysql> GRANT REPLICATION SLAVE ON *.* TO 'root'@'10.10.10.213' IDENTIFIED BY '密码';

#防止数据库写入

//mysql>FLUSH TABLES WITH READ LOCK;

#解锁数据表。

//mysql>UNLOCK TABLES;

SHOW MASTER STATUS;

请记下显示的信息,配置从服务器会用到。

+------------------+----------+--------------+------------------+-------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000001 |      329 | test         | mysql            |                   |

+------------------+----------+--------------+------------------+-------------------+

vi /etc/my.cnf

server-id=2

slave-skip-errors=all

service mysqld restart

mysql>STOP SLAVE;

mysql>

CHANGE MASTER TO MASTER_HOST='10.10.10.212', MASTER_USER='root', MASTER_PASSWORD='Sogal5911*', MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=329, MASTER_CONNECT_RETRY=10;

mysql>START SLAVE;

show slave status;

    1. 日常维护

--------------备份

/usr/local/mysql/bin/mysqldump -u root -h 127.0.0.1 -p test>/usr/src/bak.sql

/usr/local/mysql/bin/mysqldump -uroot-p suofeiya>/alidata/bak.sql (0a4a25d2eb)

-------------还原

mysql -u root -p sfybbs2015</usr/src/151106091551.sql

mysql -u root -p suofeiya</usr/src/suofeiya.sql

检查锁表 : show processlist

数据库引擎:show engines;

打开my.cnf,在[mysqld]最后添加为上default-storage-engine=InnoDB

show variables;

               set global slow_query_log=1;

               set global long_query_time=4;

http://www.cnblogs.com/Richardzhu/p/3230221.html

  1. 硬盘挂载

fdisk -l 看看硬盘情况

fdisk /dev/vxdb ---------把硬盘分区

Commond n----------加分区

mkfs.ext4 /dev/xvdb1 ---格式化xvdb1 是ext4文件类型

mount -t ext4  /dev/xvdb1 /alidata    把xvdb1挂上去/alidata

df -lh    #查看分区挂载情况

mount -t nfs 192.168.55.233:/opt/nfs /nfs

       启动自动挂载 /etc/fstab

  1. SVN

svn checkout https://192.168.2.218:2009/svn/Sogal_EPortal/trunk/www /trunk

svn update

  1. PHP 扩展单独安装(redis)

Mkdir /usr/local/php/ext

Cd /usr/local/php/ext

Wget  https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz

ls

ll phpredis/

cd phpredis/

/alidata/server/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make && make install

vim /usr/local/php/lib/php.ini

extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/redis.so

  1. Centos 7安装PHP

systemctl enable httpd  ####开启apache

yum -y remove mysql-libs*

yum -y install epel-release

#yum -y install php php-fpm

yum -y install php-gd php-mysql php-mbstring php-xml php-mcrypt  php-redis php-soap

#/usr/sbin/php-fpm&

查看php-fpm

ps aux | grep php-fpm

php-fpm 关闭:

kill -INT `cat /var/run/php-fpm/php-fpm.pid`

php-fpm 重启:

kill -USR2 `cat /var/run/php-fpm/php-fpm.pid`

修改/etc/php-fpm.conf 的daemonize = yes,让php-fpm可以后台执行

CentOS 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载

# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

# rpm -ivh mysql-community-release-el7-5.noarch.rpm

# yum install mysql-community-server

成功安装之后重启mysql服务

# service mysqld restart

初次安装mysql是root账户是没有密码的

设置密码的方法

# mysql -uroot

mysql> set password for ‘root’@‘localhost’ = password('mypasswd');

mysql> exit

搞定!

  1. 远程监控

nc -w2 10.10.10.210 9000 && echo ok ||echo no

  1. 如何把一个shell脚本添加为系统服务,并跟随系统启动

可以看到“/etc/rc.d/init.d”下有很多的文件,每个文件都是可以看到内容的,其实都是一些shell脚本。

系统服务的启动就是通过“/etc/rc.d/init.d”中的脚本文件实现的。我们也可以写一个自己的脚本放在这里。

脚本文件的内容也很简单,类似于这个样子(例如起个名字叫做“hahad”):

. /etc/init.d/functions

start() {

        echo "Starting my process "

        cd /opt

        ./haha.sh

}

stop() {

        killall haha.sh

        echo "Stoped"

}

写了脚本文件之后事情还没有完,继续完成以下几个步骤:

chmod +x hahad                    #增加执行权限

chkconfig --add hahad             #把hahad添加到系统服务列表

chkconfig hahad on                 #设定hahad的开关(on/off)

chkconfig --list hahad               #就可以看到已经注册了hahad的服务

date +"%Y-%m-%d %H:%M:%S" #查看时间

posted @ 2019-11-21 16:04  远方V3  阅读(301)  评论(0编辑  收藏  举报