Linux编译安装LNMP+redis+mongodb

Linux部署LNMP环境

安装Nginx

#安装nginx依赖
yum -y install pcre pcre-devel
yum -y install openssl openssl-devel

cd /data/nginx
#官网下载nginx安装包    http://nginx.org/en/download.html
#解压安装包
tar -zxvf nginx-1.20.1.tar.gz

#编译安装
./configure --prefix=/data/nginx
make
make install

## 报错:./configure: error: the HTTP rewrite module requires the PCRE library.    执行yum -y install pcre pcre-devel
## 报错:./configure: error: the HTTP cache module requires md5 functionsfrom OpenSSL library.   You can either disable the module by using--without-http-cache option, or install the OpenSSL library into the system,or build the OpenSSL library statically from the source with nginx by using--with-http_ssl_module --with-openssl=<path> options.    执行yum -y install openssl openssl-devel

#创建并设置nginx运行账号
groupadd nginx
useradd -M -g nginx -s /sbin/nologin nginx
cd /data/nginx/conf
vim nginx.conf
#设置user
user root;
/data/nginx/sbin/nginx -t

#启动nginx
/data/nginx/sbin/nginx
#停止
nginx -s stop
#重启
nginx -s reload

#建立软连接
ln -s /data/nginx/sbin/nginx /usr/local/sbin

安装Mysql

#下载mysql安装包
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

#权限设置
chown mysql:mysql -R /var/lib/mysql

#初始化 MySQL
mysqld --initialize

#启动 MySQL
service mysqld start
#关闭 Mysql
service mysql stop

#查看 MySQL 运行状态
service mysqld status

#修改root账户密码
mysqladmin -u root password “123456”
#或者
set password for root@localhost=password("123456");

#设置root所有sql权限
grant all privileges on *.* to root@"%" identified by "你的密码";
flush privileges;#强制刷新

安装PHP

#安装php依赖
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel

#下载PHP源码包
wget https://www.php.net/distributions/php-7.0.33.tar.gz

#解压
tar --zxvf php-7.0.33.tar.gz

cd /data/php

#编译安装
./configure --prefix=/data/php --disable-fileinfo --enable-fpm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib --with-curl --enable-ftp --with-gd --with-xmlrpc --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-mbstring --with-mcrypt=/usr/local/libmcrypt --enable-zip --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=/data/mysql/mysql.sock --without-pear --enable-bcmath

make

make install

#软连接
ln -s /data/php/bin/php /usr/bin/php

#启动
systemctl start php-fpm.service
#停止
systemctl stop php-fpm.service
#重启
systemctl restart php-fpm.service

nginx配置php(支持tp运行)

server {
    listen       80;
    listen  [::]:80;
    server_name  www.lttljk.top;#绑定域名

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        #运行目录
        root   /data/www/;
        index  index.html index.htm index.php;

        if (!-e $request_filename){
            rewrite ^/(.*)$ /index.php?s=/$1 last;
            break;
        }
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php(.*)$ {
        root            /data/www/tp5.1/public;
        fastcgi_pass    172.17.0.3:9000;
        fastcgi_index   index.php;
        #支持phpinfo /m/c/f
        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;
    }
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

安装redis

#下载
wget http://download.redis.io/releases/redis-4.0.8.tar.gz
#解压
tar xzf redis-4.0.8.tar.gz
#重命名
mv redis-4.0.8 redis
#进入目录 cd redis
#安装redis
sudo make && sudo make install
#修改配置
vim redis.conf
daemonize=no改为daemonize=yes
#启动
src/redis-server ./redis.conf

安装phpredis扩展

#在redis官网下载安装包
#解压到服务器上
#进入安装目录  执行phpize
/data/php/bin/phpize
#若报错
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
#解决办法
yum install autoconf

#指定php配置路径
./configure --with-php-config=/data/php/bin/php-config
#编译安装
sudo make && sudo make install

#将扩展加入php.ini中
find / -name php.init
vim /etc/php.ini
extension=/data/php/lib/php/extensions/no-debug-non-zts-20151012/redis.so
#重启php
ps -ef|grep php-fpm
kill -quit 进程号
/data/php/sbin/php-fpm

安装mongodb

#在mongodb官网下载系统版本对应的包
https://www.mongodb.com/try/download/enterprise
#解压重命名...
#进入安装目录,创建数据库文件夹、日志文件夹、配置文件夹
mkdir data
mkdir logs    ->   touch mongodb.log
mkdir etc     ->   vim mongodb.conf

#配置文件中写入
dbpath=/data/mongo/mongo/data
logpath=/data/mongo/mongo/logs/mongodb.log
port=27017
fork=true
journal=false
#启动mongo
cd /data/mongo/mongo/bin
./mongod --config /data/mongo/mongo/etc/mongodb.conf

#添加管理员
./mongo
use admin
db.createUser({user:"root",pwd:"123456",roles:[{role:"userAdminAnyDatabase",db:"admin"}]});

#关闭mongoDB不要使用kill   使用db.shutdownServer();
#使用权限打开mongoDB,给配置中添加auth=true

#将mongod路径添加到系统路径中,方便随处执行mongod命令
vim /etc/profile
PATH=$PATH:/usr/local/mongoDB/mongodbserver/bin
source /etc/profile

#将mongo路径软链到/usr/bin路径下,方便随处执行mongo命令
ln -s /data/mongo/mongo/bin/mongo  /usr/bin/mongo
cd /
mongo
#关闭mongod服务,执行db.shutdownServer()会出错
#解决方法
db.updateUser("root",{roles : [{"role" : "userAdminAnyDatabase","db" : "admin"},{"role" : "dbOwner","db" : "admin"},{"role" : "clusterAdmin", "db": "admin"}]})
db.shutdownServer()

#MongoDB设置为系统服务并且设置开机启动
vim /etc/rc.d/init.d/mongod
start() {  
/data/mongo/mongo/bin/mongod  --config /data/mongo/mongo/etc/mongodb.conf 
}  
  
stop() {  
/data/mongo/mongo/bin/mongod --config /data/mongo/mongo/etc/mongodb.conf --shutdown  
}  
case "$1" in  
  start)  
 start  
 ;;  
  
stop)  
 stop  
 ;;  
  
restart)  
 stop  
 start  
 ;;  
  *)  
 echo  
$"Usage: $0 {start|stop|restart}"  
 exit 1  
esac

#添加权限
chmod 755 /etc/rc.d/init.d/mongod
#启动mongo
service mongod start
#关闭mongo
service mongod stop

#mongodb远程连接配置
vim /data/mongo/mongo/etc/mongodb.conf
bind_ip=0.0.0.0

#防火墙开放27017端口
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT

#重启mongodb
service mongod restart

安装phpmongodb

参照phpredis安装即可

安装ftp

yum -y install vsftpd

#开启vsftp服务
service vsftpd start

#设置为开机启动
systemctl enable vsftp

#添加ftp帐号和目录
useradd -d /data/www -s /sbin/nologin pwftp

#修改用户密码
passwd pwftp

#修改指定目录的权限
chown -R pwftp.pwftp /alidata/www/wwwroot

#修改配置文件
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

#创建chroot_list
pwftp

#修改shell配置
vim /etc/shells
/usr/sbin/nologin
/sbin/nologin

#启动服务
service vsftpd start

后续持续改进...

上一篇:Python基础总结之初步认识---class类(下)。第十四天开始(新手可相互督促)


下一篇:pyqt5 QWebEngineView 隐藏滚动条