LNMP服务器环境部署

LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写。L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以指Perl或Python。
LNMP代表的就是:Linux系统下Nginx

这里写目录标题

    • 操作版本
    • 部署步骤
      • 安装SVN和rsync
      • MySQL安装配置
      • 更新Linux环境,此步骤在其他步骤之前执行可减少不必要的错误
      • 安装Nginx
      • 安装php7
      • 配置Nginx站点

操作版本

1.Linux: CentOS 7.3(64bit)
2. Nginx
3. php7
4. mysql5.7
5. redis

部署步骤

//环境检测
#lsb_release -a//查看CentOS 版本
#ping nginx.org//检测nginx  查看最新版本-->http://nginx.org/packages/centos/7/noarch/RPMS/		//下面还有nginx环境搭建
//如果ping不通,则要修改hosts
//#vim /etc/hosts
//206.251.255.63 nginx.org//将以下内容加到最后
#ps -ef|grep nginx//可查看yum 安装目录

安装SVN和rsync

//SVN//
#yum install subversion
#svn --version
//创建SVN版本
#mkdir svn  
#svnadmin create svn/LfErp
// (1)svnserve.conf:  svn服务综合配置文件。
anon-access = none  
auth-access = write  
password-db = passwd  
authz-db = authz  
   (2)passwd: 用户名口令文件。
[users]
ljw = 123456
ck = 123456
   (3)authz: 权限配置文件。
[groups]

our = ljw,ck
[/]
our = rw
* = rw

#svnserve -d -r /home/svn  //启动SVN服务 ---/home/svn ==>你的svn项目路径 116 : /usr/local/svn

//SVN开机启动
//1、编辑rc.local文件 
vi /etc/rc.d/rc.local
//2、加入如下启动命令 
/usr/bin/svnserve -d -r /home/svn
//

//rsync//
//配置服务器端rsync
#yum -y install rsync
#vi /etc/rsyncd.conf
//
uid = nobody //root  //这边可能会出现隐藏文件权限不足,所以使用root组
gid = nobody //root
use chroot = no
max connections = 2
pid file = /var/run/rsyncd.pd
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[test]
path = /html/LfErp/
hosts allow = 139.129.239.93
auth users = svn_usr
secrets file = /etc/rsyncd.secrets
read only = false
//
#vi /etc/rsyncd.secrets
//
svn_usr:123456
//
#chmod 600 /etc/rsyncd.secrets
#systemctl start rsyncd
#systemctl enable rsyncd 
#usermod -a -G root svn_usr//添加进用户组
//配置客户端rsync
#vi /etc/rsyncd.secrets
//
123456
//
#chmod 600 /etc/rsyncd.secrets
//同步更新并过滤svn文件
#rsync -vaztpH --password-file=/etc/rsyncd.secrets --exclude='.svn/' /var/www/test/LfErp/ [email protected]::test

//svn post-commit//
SVN=/usr/bin/svn
LOCALHOST=/var/www/test/LfErp
WEB=/html/LfErp/
WEBIP="121.43.191.88"
RSYNC=/usr/bin/rsync
LOG=/tmp/rsync_cqzn_server.log

export LANG=en_US.UTF-8 
if 
$SVN update $LOCALHOST --username ljw --password 123456
then
  echo ""    >> $LOG
  echo `date` >> $LOG
  echo "##############################" >> $LOG
  rsync -vaztpH --delete --password-file=/etc/rsyncd.secrets --exclude='.svn/' --timeout=900 $LOCALHOST/ [email protected]::test >>$LOG
fi  
/

MySQL安装配置

//mysql//
//查看最新版本mysql --> http://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html
#rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
#yum install mysql-community-server --nogpgcheck//不会造成某些包安装失败
#systemctl status mysqld  //查看mysql状态 ,默认已经开机启动了
#systemctl start mysqld
#grep 'temporary password' /var/log/mysqld.log  //获取初始密码
//
//修改初始密码
#mysql -u root -p  
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'XXXXX';#XXX处填要修改的密码
mysql>use mysql;
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'XXXX' WITH GRANT OPTION;
mysql>flush privileges;
//
mysql>GRANT ALL ON *.* TO 'root'@'localhost' IDENTIFIED BY 'xxxxx' WITH GRANT OPTION;
mysql>flush privileges;
//
//如果有防火墙另行打开3306端口
#firewall-cmd --list-all-zones //查看zone信息
#firewall-cmd --add-port=3306/tcp --permanent //永久打开3306
##########mysql5.7 重启配置###################
sql_mode //NO_ZERO_IN_DATE,NO_ZERO_DATE,ONLY_FULL_GROUP_BY
msqyl>set @@global.sql_mode ='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
mysql>select @@global.sql_mode;
mysql>set global event_scheduler=on;//开启计划事件
mysql> set global slow_query_log_file='/var/lib/mysql/new-slow.log'; //修改日志文件
mysql> set global slow_query_log=1; //开启慢日志
mysql> set global max_connections = 200; //最大连接数
mysql> set global expire_logs_days=30; //mysql.bin 保存30天  触发机制->binlog大小超过max_binlog_size;手动执行flush logs;重新启动时(MySQL将会new一个新文件用于记录binlog);
mysql> flush logs;

更新Linux环境,此步骤在其他步骤之前执行可减少不必要的错误

//Linux环境搭建
#yum update
#rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
#rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
#yum install glibc-headers -y
#yum install gcc gcc-c++ gcc-g77 -y
#yum install libxml2 libxml2-devel openssl openssl-devel -y
#yum install autoconf -y
#yum install libsqlite3x.x86_64 libsqlite3x-devel.x86_64 -y
#yum install oniguruma -y
#yum install oniguruma-devel -y

安装Nginx

#rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
#yum install nginx  //nginx -v //查看安装版本
#systemctl enable nginx.service //设置开机启动nginx -->#systemctl status nginx.service//重启查看是否生效

安装php7

#cd /usr/local/src //统一下载目录
#wget -c http://cn2.php.net/distributions/php-7.1.3.tar.gz//20170402最新版PHP -->http://cn2.php.net/downloads.php  这里查看PHP当前版本	//7.4.30 有许多yum要提前安装
#tar -zxvf php-7.1.3.tar.gz //解压目录
#cd php-7.1.3
#yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel//安装一些基础PHP扩展项
#./configure --prefix=/usr/local/php7 --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo -enable-tokenizer --enable-zip  //安装目录/usr/local/php7
#make//继续安装
#make install//继续安装
#cp php.ini-development /usr/local/php7/lib/php.ini  //PHP配置文档
#vim /usr/local/php7/lib/php.ini 
//
本机需配置查找 /mysqli.default_socket
mysqli.default_socket = /var/lib/mysql/mysql.sock
date.timezone = PRC //时区修改
//

#/usr/local/php7/bin/php -v //查看PHP版本验证是否安装成功
#/usr/local/php7/bin/php -m //查看PHP安装模块


#cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf  //配置 php-fpm
#cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf  //配置 php-fpm
#cp /usr/local/src/php-7.1.3/sapi/fpm/php-fpm.service /usr/lib/systemd/system/ //配置PHP-FPM启动服务脚本
#vim /usr/lib/systemd/system/php-fpm.service //修改prefix
//
PIDFile=/usr/local/php7/var/run/php-fpm.pid
ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf
//

#systemctl daemon-reload //重载systemd
#systemctl enable php-fpm //设置php-fpm开机启动 #systemctl status php-fpm//重启查看是否生效

//设置PHP环境变量
#vi /etc/profile
//根据实际填写/usr/local/php7/bin
PATH=$PATH:/usr/local/webserver/php/bin:/usr/local/webserver/mysql/bin    
export PATH
//
#source /etc/profile
#echo $PATH

配置Nginx站点

#mkdir -p /html/test/
//写个PHPINFO做测试 这里省略一万字

#cd /etc/nginx/conf.d/ //为测试写个nginx  配置
#vim test.conf
//
server {
    listen       80;
    server_name  localhost; #自己的域名 --localhost
    root         /www/lnmp/web; #目录
    location / {
        index  index.php index.html index.htm;
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000; #与php-fpm相同
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

//防火墙开放80端口
添加

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

添加端口外部访问权限(这样外部才能访问)
firewall-cmd --add-port=XXX/tcp

#查看开放了哪些服务端口
firewall-cmd --list-all

重新载入,添加端口后重新载入才能起作用

firewall-cmd --reload
#systemctl reload nginx //重载nginx
环境搭建成功

你可能感兴趣的:(运维,服务器,运维,linux)