lnmp开发环境配置及常用软件安装

一.nginx安装

0.准备工作

yum update
yum install -y gcc gcc-c++
yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel psmisc

1.添加专用分组和用户

1
2
3
4
5
6
7
groupadd www

useradd -g www www

vim /etc/passwd

然后找到有 www 那一行,把它修改为(后面由/bin/bash改为/sbin/nologin)

2.选择目录下载编译文件,解压,编译,安装

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
官网下载(http://nginx.org/en/download.html) 或 wget http://182.150.63.148:8090/LNMP/nginx-1.12.2.tar.gz

tar zxf  nginx-1.12.2.tar.gz

cd nginx-1.12.2

./configure --user=www --group=www --prefix=安装目录/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --sbin-path=安装目录/nginx/sbin/nginx

make

make install

3.配置nginx

mv 安装目录/nginx/conf/nginx.conf{,.bak}

wget http://182.150.63.148:8090/tars/config/nginx.conf  -P 安装目录/nginx/conf/

wget http://182.150.63.148:8090/tars/config/enable-php.conf -P 安装目录/nginx/conf/

mkdir -pv 安装目录/nginx/conf/vhosts

支持php,在启动php-fpm之后修改
######################################
location / {
    index  index.html index.htm index.php;
    #autoindex  on;
}
location ~ \.php(.*)$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_split_path_info  ^((?U.+\.php)(/?.+)$;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  PATH_INFO  $fastcgi_path_info;
    fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
    include        fastcgi_params;
}
######################################

4.手动启动服务

1
2
3
4
5
6
7
安装目录/nginx/sbin/nginx

安装目录/nginx/sbin/nginx -s reload

安装目录/nginx/sbin/nginx -t

安装目录/nginx/sbin/nginx -t -s reload

5.开机启动添加

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Centos 系统服务脚本目录:

用户(user)

用户登录后才能运行的程序,存在用户(user)

/usr/lib/systemd/

系统(system)

如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里

/lib/systemd/system/

服务以.service结尾。

vim /lib/systemd/system/nginx.service

####################内容 start####################

[Unit]

Description=nginx

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/nginx/sbin/nginx

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

ExecStop=/usr/local/nginx/sbin/nginx -s stop

PrivateTmp=true

[Install]

WantedBy=multi-user.target

######################内容 end#####################

设置开机启动

systemctl enable nginx.service

6.查看nginx版本,测试

1
2
3
安装目录/nginx/sbin/nginx -v

curl localhost

7.查看进程

1
ps -ef | grep nginx

8.开启对外端口(centos7以上)

1
2
3
4
5
6
7
开启端口:

firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)

重新载入

firewall-cmd --reload

9.配置虚拟域名,添加host

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
配置虚拟域名

#####################################################

server {

listen       80;

server_name  www.dy.cn dy.cn;

root   /data/website;

location / {

index  index.html index.htm index.php;

autoindex  on;

}

location ~ .php(.*)$ {

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_split_path_info  ^((?U.+.php)(/?.+)$;

fastcgi_param  SCRIPT_FILENAME  document_rootfastcgi_script_name;

fastcgi_param  PATH_INFO  $fastcgi_path_info;

fastcgi_param  PATH_TRANSLATED  document_rootfastcgi_path_info;

include        fastcgi_params;

}

}

#####################################################

添加host:vim /etc/hosts即可编辑

10.添加环境变量

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# vim /etc/profile

在最后,添加:

export PATH="/data/webserver/nginx/sbin:$PATH" #添加的路径

保存,退出,然后运行:

#source /etc/profile

不报错则成功。

11.nginx管理的几种方式

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 启动Nginx

/usr/local/nginx/sbin/nginx

# 从容停止Nginx:

kill -QUIT 主进程号 # 如上一步中的 ps 命令输出的 29151,就是 Nginx的主进程号

# 快速停止Nginx:

kill -TERM 主进程号

# 强制停止Nginx:

pkill -9 nginx

# 平滑重启nginx

/usr/nginx/sbin/nginx -s reload

二.php安装

0.准备工作

1
yum -y install composer libjpeg-devel libxml2-devel libpng-devel freetype-devel curl-devel libicu-devel epel-release libmcrypt-devel libxslt libxslt-devel autoconf git supervisor openssh-clients  lftp lrzsz lftp telnet

1.选择目录下载编译文件,解压,编译,安装

1
2
3
4
5
A.wget -c http://cn2.php.net/distributions/php-7.1.3.tar.gz 或 http://cn2.php.net/distributions/php-7.2.9.tar.gz
B.tar zxf php-7.2.9.tar.gz
C.cd php-7.2.9
D.  ./configure    --prefix=安装目录/php   --with-config-file-path=安装目录/php/etc   --with-config-file-scan-dir=安装目录/php/conf.d   --enable-fpm   --with-fpm-user=www   --with-fpm-group=www   --enable-mysqlnd   --with-mysqli=mysqlnd   --with-pdo-mysql=mysqlnd   --with-iconv-dir   --with-freetype-dir=安装目录/freetype   --with-jpeg-dir   --with-png-dir   --with-zlib   --with-libxml-dir=/usr   --enable-xml   --disable-rpath   --enable-bcmath   --enable-shmop   --enable-sysvsem   --enable-inline-optimization   --with-curl   --enable-mbregex   --enable-mbstring   --enable-intl   --with-mcrypt   --enable-ftp   --with-gd   --enable-gd-native-ttf   --with-openssl   --with-mhash   --enable-pcntl   --enable-sockets   --with-xmlrpc   --enable-zip   --enable-soap   --with-gettext   --disable-fileinfo   --enable-opcache   --with-xsl
E.make && make install

2.查看版本

1
/usr/local/php7/bin/php -v

3.查看,修改配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
查看配置
/usr/local/php7/bin/php -i | grep php.ini
从解压缩文件夹复制
cp 安装目录/php/etc/php-fpm.conf.default 安装目录/php/etc/php-fpm.conf
cp 安装目录/php/etc/php-fpm.d/www.conf.default 安装目录/php/etc/php-fpm.d/www.conf
sed -i 's/user = nobody group = nobody/user = www group = www/' 安装目录/php/etc/php-fpm.d/www.conf
sed -i 's/;pid = run/pid = run/' 安装目录/php/etc/php-fpm.conf
cp 解压文件夹/php-7.2.9/php.ini-production 安装目录/php/etc/php.ini
cp 解压文件夹/php-7.2.9/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
mv 安装目录/php/etc/php-fpm.conf{,.bak}
wget http://182.150.63.148:8090/tars/config/php-fpm.conf -P 安装目录/php/etc/
chmod 755 /etc/init.d/php-fpm
/etc/init.d/php-fpm start
rm -rf /usr/bin/php
cp 安装目录/php/bin/php /usr/bin/
安装目录/nginx/sbin/nginx -s reload
修改composer为国内源:composer config -g repo.packagist composer https://packagist.phpcomposer.com

nginx打开php文件报错:access denied解决
php.ini文件修改cgi.fix_pathinfo从0改为1(让php可以解析路径)

4.安装php-fpm,启动

1
2
3
4
chmod 755 /etc/init.d/php-fpm
/etc/init.d/php-fpm start
chkconfig --add php-fpm
chkconfig php-fpm on

5.查看进程

1
 ps -ef | grep php-fpm

6.php-fpm管理

1
2
3
/etc/init.d/php-fpm start
/etc/init.d/php-fpm restart
/etc/init.d/php-fpm stop

7.安装扩展

  • PECL

    1
    2
    3
    4
    5
    6
    7
    
    //php版本 > 7
    $ wget http://pear.php.net/go-pear.phar
    $ php go-pear.phar
    
    //php版本 < 7
    $ yum install php-pear
    //否则会报错PHP Parse error:  syntax error, unexpected //'new' (T_NEW) in /usr/share/pear/PEAR/Frontend.php on //line 91
    
  • redis

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    
    a.进入预定目录,下载,解压,进入文件夹
    wget https://pecl.php.net/get/redis-5.1.1.tgz
    tar zxf redis-5.1.1.tgz
    cd redis-5.1.1
    b.生成configure配置文件
    php安装目录/bin/phpize
    c.编译安装
    ./configure --with-php-config=php安装目录/bin/php-config(如果找不见php-config,则使用 find / -name 'php-config')
    make && make install
    d.配置php.ini
    配置php.ini
    在extension后添加
    extension=redis.so
    e.查看结果
    重启php:/etc/init.d/php-fpm restart
    检查:
    [root@test etc]# /usr/local/php-7.1/bin/php -m|grep redis
    redis
    或直接看phpinfo.php查找redis
    
  • libxls

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    
    wget http://182.150.63.148:8090/tars/libxlsxwriter.tar.gz -P 解压目录
    tar zxf 解压目录/libxlsxwriter.tar.gz -C 解压目录
    cd 解压目录/libxlsxwriter
    make && make install
    C.php-excel#
    wget http://182.150.63.148:8090/tars/php-ext-excel-export.tar.gz -P 解压目录
    tar zxf 解压目录/php-ext-excel-export.tar.gz -C 解压目录
    cd 解压目录/php-ext-excel-export
    php安装目录/php/bin/phpize
    ./configure --with-php-config=php安装目录/php/bin/php-config
    make && make install
    
  • php-fileinfo

    1
    2
    3
    4
    
    cd 解压目录/php-7.2.9/ext/fileinfo/
    php安装目录/php/bin/phpize
    ./configure --with-php-config=php安装目录/php/bin/php-config
    make && make install
    
  • mongo

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    
    wget https://pecl.php.net/get/mongodb-1.5.3.tgz -P 解压目录
    tar zxf 解压目录/mongodb-1.5.3.tgz  -C 解压目录
    cd 解压目录/mongodb-1.5.3.tgz
    php安装目录/php/bin/phpize
    ./configure --with-php-config=php安装目录/php/bin/php-config
    make && make install
    F.ImageMagick
    wget http://182.150.63.148:8090/tars/ImageMagick-7.0.7-21.tar.gz -P 解压目录
    tar zxf 解压目录/ImageMagick-7.0.7-21.tar.gz -C 解压目录
    cd 解压目录/ImageMagick-7.0.7-21
    ./configure --prefix=$APPDIR/imagemagick
    make && make install
    wget http://182.150.63.148:8090/tars/imagick-3.4.3.tgz -P 解压目录
    tar zxf 解压目录/imagick-3.4.3.tgz -C 解压目录
    cd 解压目录/imagick-3.4.3
    php安装目录/php/bin/phpize
    ./configure --with-php-config=php安装目录/php/bin/php-config --with-imagick=$APPDIR/imagemagick
    make && make install
    
  • swoole

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    
    A.方法一
    pecl install swoole 或 /data/webserver/php/bin/pecl install swoole
    B.方法二
    自行创建/data/tools目录
    cd /data/tools && \
    curl -o swoole.tar.gz https://codeload.github.com/swoole/swoole-src/tar.gz/v4.4.3 -L && \
    tar zxvf swoole.tar.gz && \
    mv swoole-src-* swoole-src && \
    cd swoole-src && \
    /data/webserver/php/bin/phpize && \
    ./configure \
    --with-php-config=/data/webserver/php/bin/php-config \
    --enable-openssl  \
    --enable-http2  \
    --enable-sockets \
    --enable-mysqlnd && \
    make clean && make && sudo make install
    C.添加扩展
    php.ini添加extension=swoole.so
    D.重启php-fpm
    /etc/init.d/php-fpm restart
    H.hiredis
    wget https://github.com/redis/hiredis/archive/v0.13.3.zip 或 wget -O hiredis-0.13.3 https://github.com/redis/hiredis/releases
    yum -y install unzip
    unzip v0.13.3.zip
    cd hiredis-0.13.3/
    make && make install
    ldconfig
    #加php-fpm环境变量
    vim /etc/profile
    #最后一行加入
    export PATH="$PATH:/data/webserver/php/sbin/:/data/webserver/php/bin/"
    #重新设置环境变量
    source /etc/profile
    #查看环境变量是否成功
    export
    #启动异步redis客户端
    重新编译安装swoole,在configure指令中加入--enable-async-redis
    #重新安装swoole可能遇到的问题
    php-m 发现swoole消失或者是通过php --ri swoole没有显示async redis client 或 redis client
    vi ~/.bash_profile
    在最后一行添加 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
    source ~/.bash_profile
    重新编译安装swoole即可
    /etc/init.d/php-fpm restart
    最好是重启一下服务器
    
    mv php安装目录/php/etc/php.ini{,.bak}
    wget http://182.150.63.148:8090/tars/config/php.ini -P  php安装目录/php/etc/
    /etc/init.d/php-fpm restart
    

三.mysql安装

0.准备工作

1
yum -y install sysstat cmake flex bison autoconf gcc-c++ automake bzip2-devel ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel gettext-devel pam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel libxml2-devel curl-devel libicu libicu-devel

1.添加专用分组和用户

1
2
groupadd mysql
/usr/sbin/useradd -r -g mysql -s /bin/false mysql

2.选择目录下载编译文件,解压,编译,安装

  • A.下载

    1
    2
    3
    4
    5
    
    官网下载(https://dev.mysql.com/downloads/mysql/5.7.html#downloads)(选择RedHat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package)
    或 wget http://182.150.63.148:8090/LNMP/mysql-5.7.20.tar.gz -P 解压缩文件夹
    或 wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
    或 wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-server-5.7.18-1.el7.x86_64.rpm
    wget http://182.150.63.148:8090/LNMP/boost_1_59_0.tar.gz -P 解压缩文件夹
    
  • B.解压

    1
    2
    3
    4
    5
    
    tar zxf mysql-5.7.20.tar.gz -C 解压缩文件夹
    
    tar zxf boost_1_59_0.tar.gz -C 解压缩文件夹
    
    mkdir -pv 安装目录/{mysql,tmp_db,database}
    
  • C.编译&安装

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    
    mkdir -pv /var/lib/mysql
    
    chown -R mysql:mysql /var/lib/mysql
    
    chown -R mysql:mysql 安装目录/
    
    cd 解压缩文件夹/mysql-5.7.20
    
    cmake -DCMAKE_INSTALL_PREFIX=安装目录/mysql  -DMYSQL_DATADIR=安装目录/database -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=0 -DWITH_BOOST=解压缩文件夹/boost_1_59_0 -DSYSTEMD_PID_DIR=/var/run/mysql.pid -DSYSCONFDIR=/etc/my.cnf
    
    make && make install
    
    chmod 750 安装目录/database
    

3.初始化

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
安装目录/mysql/bin/mysqld --initialize --user=mysql

注意此处或给出默认登陆密码

cp 安装目录/mysql/bin/mysql /usr/sbin/

cp 解压缩文件夹/mysql-5.7.20/support-files/mysql.server /etc/init.d/mysqld

chmod +x /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig mysqld on

4.修改配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
在安装目录下添加配置文件

###############################################

[mysql]

# 设置mysql客户端默认字符集

default-character-set=utf8

[mysqld]

#设置3306端口

port = 3306

# 设置mysql的安装目录

basedir=/data/LPDB/mysql/

# 设置mysql数据库的数据的存放目录

datadir=/data/LPDB/database/

# 允许最大连接数

max_connections=200

# 服务端使用的字符集默认为8比特编码的latin1字符集

character-set-server=utf8

# 创建新表时将使用的默认存储引擎

default-storage-engine=INNODB

###############################################

5.启动

1
/etc/init.d/mysqld start

6.查找当前配置路径

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# which mysqld

/usr/local/mysql/bin/mysqld

# /usr/local/mysql/bin/mysqld --verbose --help |grep -A 1 'Default options'

2016-06-02 16:49:39 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.25-log) starting as process 8253 ...

2016-06-02 16:49:41 8253 [Note] Plugin 'FEDERATED' is disabled.

Default options are read from the following files in the given order: 默认的选项是按照给定的顺序读取从以下文件:

/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf

7.设置默认密码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
在配置文件中添加配置项:skip-grant-tables(没有配置文件则在安装目录下创建my.cnf

###############################################

[mysql]

# 设置mysql客户端默认字符集

default-character-set=utf8

[mysqld]

#设置3306端口

port = 3306

# 设置mysql的安装目录

basedir=/data/LPDB/mysql/

# 设置mysql数据库的数据的存放目录

datadir=/data/LPDB/database/

# 允许最大连接数

max_connections=200

# 服务端使用的字符集默认为8比特编码的latin1字符集

character-set-server=utf8

# 创建新表时将使用的默认存储引擎

default-storage-engine=INNODB
skip-grant-tables
###############################################

update mysql.user set authentication_string=password('root') where User='root' and Host='localhost';
flush privileges;
去掉skip-grant-tables配置项

8.初始化密码报错

mac mysql error You must reset your password using ALTER USER statement before executing this statement.

1
2
3
4
5
step 1: SET PASSWORD = PASSWORD('your new password');

step 2: ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;

step 3: flush privileges;

9.开启远程登陆

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
1. 打开/etc/mysql/mysql.conf.d/mysqld.cnf, 注掉 "bind-address = 127.0.0.1",

2. 重启mysql service "/etc/init.d/mysql restart"

3. 执行: mysql> GRANT ALL PRIVILEGES ON . TO 'USERNAME'@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;

注意: 这里的USERNAME是你的数据库账户,PASSWORD是你的数据库密码

例如: mysql> GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

4. 执行: mysql> flush privileges;

5. 退出mysql命令行,执行: mysql -u root -h 192.168.0.1 -p

10.开启对外端口(centos7以上)

1
2
3
4
5
6
7
开启端口:

firewall-cmd --zone=public --add-port=3306/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)

重新载入

firewall-cmd --reload

11.mysql管理

1
2
3
4
5
/etc/init.d/mysqld start

/etc/init.d/mysqld restart

/etc/init.d/mysqld stop

12.报错

  • c++: internal compiler error: Killed (program cc1plus),Please submit a full bug report,原因是内存不足

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    
    #查看当前内存使用情况
    
    free -h
    
    #使用swap创建临时分区
    
    dd if=/dev/zero of=/var/swapfile bs=1024 count=2048k
    
    #count的大小就是增加的swap空间的大小,1024是块大小,所以空间大小是bs*count=2GB
    
    sudo mkswap /var/swapfile
    
    #把刚才空间格式化成swap格式
    
    chmod 0600 /var/swapfile
    
    #该目录权限,不改的话,在下一步启动时会报“swapon: /swapfile: insecure permissions 0644, 0600 suggested.”错误
    
    sudo swapon /var/swapfile
    
    #使用刚才创建的swap空间
    
    echo  "/var/swapfile   swap  swap  defaults  0  0" >>  /etc/fstab
    
    #修改 fstab 配置,设置开机自动挂载该分区
    
    swapoff /var/swapfile
    
    #停止正在使用swap分区
    
    rm -rf /var/swapfile
    
    #删除swap分区文件
    
    /var/swapfile swap swap defaults 0 0
    
    #删除或注释掉我们之前在fstab文件里追加的开机自动挂载配置内容
    

四.常用软件安装

1.安装svn

1
2
编译安装:http://www.iitshare.com/linux-svn-installation-and-configuration.html
yum安装:http://www.cnblogs.com/davidgu/archive/2013/02/01/2889457.html

1).查看是否安装了svn工具

1
命令:rpm -qa | grep subversion //如果服务器已经安装了则不需要进行安装,如果没有安装可以进行全新的安装

2).安装svn

1
yum -y install subversion

3).svn命令

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
>//path是服务器上的目录,http://www.jb51.net/os/RedHat/2461.html
>A.将文件checkout到本地目录
svn checkout path
svn co                            //简写
>B.将改动的文件commit到版本库
svn commit -m “LogMessage“ [-N] [--no-unlock] PATH
>//如果在提交的时候提示过期的话,是因为冲突,需要先update,修改文件,然后清除svn resolved,最后再提交commit)
svn ci                            //简写
>C.更update到某个版本
svn update -r m path
svn up                            //简写
svn update                        //如果后面没有目录,默认将当前目录以及子目录下的所有文件都更新到最新版本。
svn update -r 200 test.php        //将版本库中的文件test.php还原到版本200
svn update test.php               //更新,于版本库同步。
>D.解决冲突
svn resolved PATH                 //移除工作副本的目录或文件的“冲突”状态
>E.查看文件或目录的状态
svn status path                   //目录下的文件和子目录的状态,正常状态不显示
svn status -v path                //显示文件和子目录状态
>F.修改远程url地址
svn switch --relocate svn://101.201.49.72/repos/web  svn://svn.ruthout.com/repos/web
>G.查看svn信息
svn info
>4).版本库维护
>1.环境
>centos5.5

2).安装svn

1
yum -y install subversion

3).配置

1
2
3
4
建立版本库目录
mkdir /www/svndata

svnserve -d -r /www/svndata

4).建立版本库

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
创建一个新的Subversion项目
svnadmin create /www/svndata/oplinux

配置允许用户rsync访问
cd /www/svndata/oplinux/conf

vi svnserve.conf
anon-access=none
auth-access=write
password-db=passwd

注:修改的文件前面不能有空格,否则启动svn server出错

vi passwd
[users]
#<用户1> = <密码1>
#<用户2> = <密码2>
david=123456

5).客户端连接

1
2
3
4
svn co svn://ip/oplinux
用户名密码:123456

===============================================================

6).实现SVN与WEB同步

可以CO一个出来,也可以直接配在仓库中

  • 1)设置WEB服务器根目录为/www/webroot

  • 2)checkout一份SVN

1
2
3
4
5
svn co svn://localhost/oplinux /data/www/webroot

修改权限为WEB用户

chown -R apache:apache /www/webroot/oplinux
  • 3)建立同步脚本
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
cd /data/www/svndata/dykind/hooks/

cp post-commit.tmpl post-commit

编辑post-commit,在文件最后添加以下内容

export LANG=en_US.UTF-8
SVN=/usr/bin/svn
WEB=/www/webroot/
$SVN update $WEB –username rsync –password rsync
chown -R apache:apache $WEB

增加脚本执行权限

chmod +x post-commit

2.安装git

A.安装

1
yum git

B.常用命令

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
git init  #在本地新建一个repo,进入一个项目目录,执行git init,会初始化一个repo,并在当前文件夹下创建一个.git文件夹.

git clone url newname #clone下来的repo会以url最后一个斜线后面的名称命名,创建一个文件夹,如果想要指定特定的名称

git status: #查询repo的状态

git status -s: #-s表示short, -s的输出标记会有两列,第一列是对staging区域而言,第二列是对working目录而言.

git add#在提交之前,Git有一个暂存区(staging area),可以放入新添加的文件或者加入新的改动. commit时提交的改动是上一次加入到staging area中的改动,而不是我们disk上的改动.

git add .#会递归地添加当前工作目录中的所有文件.

git commit#提交已经被add进来的改动.

git commit -m #"the commit message"

git commit -a #会先把所有已经track的文件的改动add进来,然后提交(有点像svn的一次提交,不用先暂存). 对于没有track的文件,还是需要git add一下.

git commit --amend #增补提交. 会使用与当前提交节点相同的父节点进行一次新的提交,旧的提交将会被取消.

git push alias#将会把当前分支merge到alias上的[branch]分支.如果分支已经存在,将会更新,如果不存在,将会添加这个分支

git pull origin 分支#会首先执行git fetch,然后执行git merge,把取来的分支的head merge到当前分支.这个merge操作会产生一个新的commit

git log#show commit history of a branch

git diff#此命令比较的是工作目录中当前文件和暂存区域快照之间的差异,也就是修改之后还没有暂存起来的变化内容.

C.生成ssh-key

1
2
3
4
5
6
7
8
9
ssh-keygen -t rsa -C "wdyxzkq@163.com" -b 4096

回车知道看到图案

vim /root/.ssh/id_rsa.pub

复制公钥添加至账户sshkey

使用Tortoisegit生成key,查看地址:https://blog.csdn.net/m0_37727560/article/details/79408251

3.安装redis

0)链接

https://blog.csdn.net/yjqyyjw/article/details/73293455

1)下载安装

1
2
3
4
5
6
$.wget http://download.redis.io/releases/redis-4.0.6.tar.gz 或 wget http://182.150.63.148:8090/redis/redis-stable.tar.gz
$.tar -zxvf redis-4.0.6.tar.gz
$.cd redis-4.0.6
$.make
$.cd src
$.make install PREFIX=/usr/local/redis

2)配置

A.复制配置
1
$.cp redis.conf /usr/local/redis/etc/redis.conf
B.启动服务
1
2
3
$./usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
第一个是启动redis服务器
第二个是启动服务器所需的配置
C.修改配置
1
2
3
4
5
$.vim /usr/local/redis/etc/redis.conf
将daemonize的值改为yes
pidfile默认值是pidfile /var/run/redis_6379.pid
添加密码
requirepass dy123456
D.复制服务启动脚本
1
2
3
4
5
6
7
8
9
复制服务启动脚本
$.cp redis_init_script /etc/init.d/redis
#### 3)服务(centos7以下)
A.开机启动
$.vim /etc/rc.local 加入 usr/local/redis/bin/redis-server /usr/local/redis/etc/redis-conf
B.停止服务
$./usr/local/redis/bin/redis-cli shutdown或者pkill redis-server
C.客户端连接
/usr/local/redis/bin/redis-cli

4)服务(centos7以上)

A.添加服务,开机启动
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
vim /etc/init.d/redis #查看脚本内容(注意添加密码授权)
#################编辑内容 start############################
#!/bin/bash
# chkconfig:   2345 90 10

# description:  Redis is a persistent key-value database
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
RESDISPASSWORD=dy123456
REDIS_CLI=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/usr/local/redis/etc/redis.conf"
case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
            echo "$PIDFILE exists, process is already running or crashed"
        else
            echo "Starting Redis server..."
            $EXEC $CONF
        fi
        if [ "$?"="0" ]
        then
            echo "Redis is running..."
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
            echo "$PIDFILE does not exist, process is not running"
        else
            PID=$(cat $PIDFILE)
            echo "Stopping ..."
            $REDIS_CLI -a $RESDISPASSWORD  -p $REDISPORT shutdown
            while [ -x ${PIDFILE} ]
            do
            echo "Waiting for Redis to shutdown ..."
            sleep 1
            done
            echo "Redis stopped"
        fi
        ;;
    restart|force-reload)
        ${0} stop
        ${0} start
        ;;
    *)
        echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
        exit 1
esac
#################编辑内容 end  ############################
chmod a+x /etc/init.d/redis
chkconfig --add redis
chkconfig redis on
B.操作
1
2
3
/etc/init.d/redis start
/etc/init.d/redis restart
/etc/init.d/redis stop

4.安装memcached

详细文章:http://blog.sina.com.cn/s/blog_4829b9400101piil.html

1).下载最新版memcached

1
wget http://memcached.org/files/memcached-1.4.20.tar.gz

2).下载libevent

1
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

3).安装libevent

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
rpm -qa|grep libevent//查看系统是否带有该安装软件,如果有执行命令:

rpm -e libevent-1.4.13-4.el6.x86_64 --nodeps//(由于系统自带的版本旧,忽略依赖删除)

tar zxvf libevent-2.0.21-stable.tar.gz

cd libevent-2.0.21-stable

./configure --prefix=/usr/local/libevent

make && make install

4).安装memcached

1
2
3
4
5
6
7
tar zxvf memcached-1.4.2.tar.gz

cd memcached-memcached-1.4.2

./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/

make && make install

5).启动&配置memcache

1
2
3
/usr/local/memcached/bin/memcached -d -m 256 -u root -l 127.0.0.1 -p 11211 -c 1024 –P /tmp/memcached.pid

kill cat /tmp/memcached.pid //停止服务

6).将memchace添加到启动项中

1
2
3
在/etc/rc.d/rc.local中加入一行

/usr/local/memcached/bin/memcached -d -m 256 -u apache -l 127.0.0.1 -p 11211 -c 1024

7).php扩展安装

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
wget http://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz  //编译安装需下载

//安装依赖软件

wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz

tar -zvxf m4-1.4.9.tar.gz

cd m4-1.4.9/

./configure && make && make install

cd ../

wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz

tar -zvxf autoconf-2.62.tar.gz

cd autoconf-2.62/

./configure && make && make install

//使用php自带pecl安装扩展

/usr/local/servers/php5/bin/pecl install memcache

//在php.ini中添加extension=memcache.so,重启apache #/usr/local/http2/bin/apachectl restart

五.参考文档

nginx11+php5.6+mysql5.6 https://blog.csdn.net/sturdygrass/article/details/51750108

nginx12+php7.2+mysql5.7 https://blog.csdn.net/linyunping/article/details/79738324

init.sh