首页 > 系统相关 >centos7.9部署LNMP

centos7.9部署LNMP

时间:2023-05-15 18:55:05浏览次数:30  
标签:nginx 部署 LNMP centos7.9 usr mysql -- php local

系统设置

创建应用目录

mkdir -pv /data/apps

系统更新

yum -y update

limits.conf

cat >> /etc/security/limits.conf << EOF
root soft core unlimited
root hard core unlimited
root soft nproc 1000000
root hard nproc 1000000
root soft nofile 100000
root hard nofile 100000
root soft memlock 32000
root hard memlock 32000
root soft msgqueue 8192000
root hard msgqueue 8192000

* soft core unlimited
* hard core unlimited
* soft nproc 1000000
* hard nproc 1000000
* soft nofile 100000
* hard nofile 100000
* soft memlock 32000
* hard memlock 32000
* soft msgqueue 8192000
* hard msgqueue 8192000
EOF

sysctl.conf

cat >> /etc/sysctl.conf << EOF
net.core.netdev_max_backlog = 32768
net.core.rmem_default = 8388608
net.core.somaxconn = 32768
net.core.wmem_default = 8388608
net.ipv4.conf.all.arp_ignore = 0
net.ipv4.conf.lo.arp_announce = 0
net.ipv4.conf.lo.arp_ignore = 0
net.ipv4.ip_local_port_range = 5000 65000
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 65536
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_tw_reuse = 1
vm.max_map_count = 655360
vm.overcommit_memory = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
net.ipv6.conf.all.disable_ipv6 = 1
kernel.unknown_nmi_panic = 0
kernel.sysrq = 1
fs.file-max = 1000000
vm.swappiness = 10
fs.inotify.max_user_watches = 10000000
net.core.wmem_max = 327679
net.core.rmem_max = 327679
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
fs.inotify.max_queued_events = 327679
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.neigh.default.gc_thresh1 = 2048
net.ipv4.neigh.default.gc_thresh2 = 4096
net.ipv4.neigh.default.gc_thresh3 = 8192
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1
EOF

部署nginx

安装依赖

yum -y install gcc make  pcre-devel openssl-devel gd-devel geoip-devel git

创建用户

groupadd  -r nginx && useradd -M -N -g nginx -d /data/apps/nginx  -r  -s /bin/false -c "NGINX Server"  nginx

下载nginx

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

解压nginx

tar xf nginx-1.22.1.tar.gz

安装nginx

cd nginx-1.22.1
./configure  --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --with-poll_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --with-cc-opt=-Wno-error --with-ld-opt= --user=nginx --group=nginx --with-threads --with-file-aio --http-client-body-temp-path=/usr/local/nginx/client/ --http-proxy-temp-path=/usr/local/nginx/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/fcgi/ --http-uwsgi-temp-path=/usr/local/nginx/uwsgi --http-scgi-temp-path=/usr/local/nginx/scgi --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --pid-path=/usr/local/nginx/nginx.pid --lock-path=/usr/local/nginx/nginx.lock --with-pcre
make -j 4 && make install

nginx.conf

vim /usr/local/nginx/conf/nginx.conf 
user  nginx;
worker_processes  auto;

worker_rlimit_nofile 65535;
events {
    worker_connections  65535;
    use epoll;
    accept_mutex on;
}


http {
    include       mime.types;
    default_type  application/octet-stream;


    log_format json escape=json '{'
                        '"@timestamp":"$time_iso8601",'
                        '"@source":"$server_addr",'
                        '"@nginx_fields":{'
                            '"http_x_forwarded_for":"$http_x_forwarded_for",'
                            '"request":"$request",'
                            '"status":"$status",'
                            '"body_bytes_sent":"$body_bytes_sent",'
                            '"http_referer":"$http_referer",'
                            '"client":"$remote_addr",'
                            '"request_time":"$request_time",'
                            '"upstream_response_time":"$upstream_response_time",'
                            '"upstream_addr":"$upstream_addr",'
                            '"request_method":"$request_method",'
                            '"domain":"$host",'
                            '"url":"$uri",'
                            '"args":"$args",'
                            '"request_body":"$request_body",'
                            '"http_user_agent":"$http_user_agent",'
                            '"remote_addr":"$remote_addr",'
                            '"proxy_add_x_forwarded_for":"$proxy_add_x_forwarded_for"'
                        '}'
                    '}';


    access_log  logs/access.log  json;

    sendfile        on;
    tcp_nopush     on;
    types_hash_max_size 2048;
    keepalive_timeout  65;
    client_header_buffer_size 4k;
    client_max_body_size 512M;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    aio on;
    gzip  on;
    gzip_vary on;  
    gzip_proxied any;
    gzip_min_length 1k;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_comp_level 6;
    gzip_types  text/plain application/json application/javascript application/x-javascript application/css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif image/png image/x-ms-bmp;

 
    include /usr/local/nginx/conf/vhosts/*.conf;

    server {
        listen       80;
        server_name  localhost;


        location / {
            root   html;
            real_ip_header     X-Forwarded-For;
            index  index.html index.htm index.php;
        }

        location /basic_status {
           stub_status on;
        }


        location ~ ^/(pm_status|ping)$ {
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          include        fastcgi_params;
        }

        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
   }
}

nginx.service

cat >> /lib/systemd/system/nginx.service  << EOF
[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

运行nginx

systemctl enable nginx && systemctl start nginx

访问nginx

curl localhost

部署mysql

安装依赖

yum -y install libaio

创建用户

groupadd  -r mysql && useradd -M -N -g mysql  -r -d /data/apps/mysql -s /bin/false -c "MySQL Server"   mysql

下载mysql

wget  https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

设置mysql

tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
ln -sv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64/ /usr/local/mysql

创建数据目录

mkdir -pv /data/apps/mysql/{data,logs,tmp}

my.cnf

cat >> /data/apps/mysql/my.cnf << EOF
[client]
port=3306
default-character-set = utf8mb4
socket=/data/apps/mysql/mysql.sock

[mysqld]
port=3306
character-set-server=utf8mb4
datadir=/data/apps/mysql/data
pid_file=/data/apps/mysql/mysqld.pid
socket=/data/apps/mysql/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 256M
max_connections = 1000
#interactive_timeout = 120
wait_timeout = 3600
user=mysql
local_infile=OFF
#secure_file_priv=/data/apps/mysql/data
table_open_cache = 4
sort_buffer_size = 128K
read_buffer_size = 512K
read_rnd_buffer_size = 512K
net_buffer_length = 2K
thread_stack = 512K
skip-name-resolve=ON
innodb_file_per_table = ON
log-bin=/data/apps/mysql/logs/mysql-bin
binlog_format=row
server-id=1
sync_binlog=1
innodb_flush_log_at_trx_commit=2
innodb_support_xa=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

log_error = /data/apps/mysql/logs/error.log
slow_query_log = 1
slow_query_log_file = /data/apps/mysql/logs/slow.log
long_query_time = 2
#init_connect='SET  SQL_SAFE_UPDATES=1'
tmpdir=/data/apps/mysql/tmp
log_timestamps=SYSTEM

[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
EOF

设置权限

chmod 750 /data/apps/mysql/data
chmod 644 /data/apps/mysql/my.cnf
chown -R mysql.mysql /data/apps/mysql/

初始化mysql

/usr/local/mysql/bin/mysqld --defaults-file=/data/apps/mysql/my.cnf   --user=mysql  --datadir=/data/apps/mysql/data  --initialize

mysqld.service

cat >> /lib/systemd/system/mysqld.service  << EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(7)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql

Type=forking

PIDFile=/data/apps/mysql/data/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Start main service
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/apps/mysql/my.cnf --daemonize  --pid-file=/data/apps/mysql/data/mysqld.pid $MYSQLD_OPTS 

# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit
LimitNOFILE = 50000

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false
EOF

运行mysql

systemctl enable mysqld && systemctl start mysqld

获取初始密码

grep password /data/apps/mysql/logs/error.log

输出如下内容

2023-05-10T18:32:51.460130+08:00 1 [Note] A temporary password is generated for root@localhost: jr?+g5%9#ssK

连接mysql

/usr/local/mysql/bin/mysql -S /data/apps/mysql/mysql.sock -uroot -pjr?+g5%9#ssK

输出如下内容

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22-log

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

修改mysql密码

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('xxxxx');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>

验证新密码

/usr/local/mysql/bin/mysql -S /data/apps/mysql/mysql.sock -uroot -pxxxxxx

输出如下内容

mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.22-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

部署php

安装依赖

yum -y install atuoconf gcc libxml2-devel bzip2-devel libcurl-devel gdbm-devel db4-devel libwebp-devel gmp-devel openldap-devel readline-devel libsodium-devel libargon2-devel libxslt-devel  gcc-c++ 
ln -sv /usr/lib64/libldap* /usr/lib/

安装cmake

wget https://github.com/Kitware/CMake/releases/download/v3.22.5/cmake-3.22.5.tar.gz
tar xf cmake-3.22.5.tar.gz
cd cmake-3.22.5
./bootstrap --prefix=/usr/local/cmake-3.22.5
make -j 4
make install

安装libzip

wget https://libzip.org/download/libzip-1.8.0.tar.gz
tar xf libzip-1.8.0.tar.gz
cd libzip-1.8.0
mkdir build && cd build
/usr/local/cmake-3.22.5/bin/cmake ..
make -j 4
make install
ln -sv /usr/local/lib64/pkgconfig/libzip.pc /usr/lib64/pkgconfig/

ld.so.conf

cat >> /etc/ld.so.conf << EOF
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
EOF
ldconfig -v

下载软件包

wget https://www.php.net/distributions/php-7.2.8.tar.gz

解压包

tar xf php-7.2.8.tar.gz

安装php

cd php-7.2.8
./configure --prefix=/data/apps/php-7.2.8 --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-config-file-path=/data/apps/php-7.2.8/conf --disable-rpath --enable-option-checking=fatal --with-pic --enable-ftp --enable-soap  --with-xmlrpc --with-openssl --with-mhash  --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif  --with-openssl-dir   --with-zlib-dir   --with-gettext --with-gmp  --enable-mbstring  --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd  --with-readline --enable-shmop --enable-sockets --enable-sysvmsg   --with-xsl  --with-pear --enable-opcache   --enable-session --enable-xml   --with-gdbm  --with-ldap=shared  --with-sodium=shared --with-password-argon2 --with-gd  --with-webp-dir --with-jpeg-dir --with-xpm-dir --enable-gd-jis-conv --with-pcre-dir  --with-freetype-dir --with-libxml-dir --with-libzip --enable-zip
make -j 4 && make install

设置软链接

ln -sv /data/apps/php-7.2.8/ /usr/local/php

添加环境变量

echo 'export PATH=/usr/local/php/bin:$PATH' >> /etc/profile.d/php.sh
. /etc/profile

php.ini

mkdir /usr/local/php/conf
cp php.ini-production /usr/local/php/conf/php.ini
sed -i 's@;date.timezone = *@date.timezone = Asia/Shanghai@g' /usr/local/php/conf/php.ini

安装扩展

安装imagick

yum install ImageMagick ImageMagick-devel -y
/usr/local/php/bin/pecl  install imagick
echo "extension=imagick.so" >> /usr/local/php/conf/php.ini

安装memcached

yum -y install libmemcached-devel
/usr/local/php/bin/pecl  install memcached
echo "extension=memcached.so" >> /usr/local/php/conf/php.ini

安装psr

/usr/local/php/bin/pecl  install psr-1.0.1
echo "extension=psr.so" >> /usr/local/php/conf/php.ini

安装igbinary

/usr/local/php/bin/pecl  install igbinary
echo "extension=igbinary.so" >> /usr/local/php/conf/php.ini

安装mcrypt

yum -y install libmcrypt-devel
/usr/local/php/bin/pecl  install mcrypt
echo "extension=mcrypt.so" >> /usr/local/php/conf/php.ini

安装phalcon

/usr/local/php/bin/pecl install phalcon-4.0.2
echo "extension=phalcon.so" >> /usr/local/php/conf/php.ini

安装redis

/usr/local/php/bin/pecl  install redis
echo "extension=redis.so" >> /usr/local/php/conf/php.ini

配置php-fpm

php-fpm.conf

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

 www.conf

cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

php-fpm.service

cat >> /lib/systemd/system/php-fpm.service  << EOF
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target


[Service]

Type=forking

PIDFile=/usr/local/php/var/run/php-fpm.pid

ExecStart=/usr/local/php/sbin/php-fpm --daemonize --fpm-config /usr/local/php/etc/php-fpm.conf --pid /usr/local/php/var/run/php-fpm.pid

ExecReload=/bin/kill -USR2 $MAINPID

ExecStop=/bin/kill -SIGINT $MAINPID




[Install]

WantedBy=multi-user.target
EOF

运行php-fpm

systemctl enable php-fpm && systemctl start php-fpm

phpinfo

cat >> /usr/local/nginx/html/index.php << EOF
<?php
    phpinfo();
?>
EOF

访问php

curl localhost/index.php -I

输出如下内容

HTTP/1.1 200 OK
Server: nginx/1.22.1
Date: Fri, 12 May 2023 06:14:02 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/7.2.8

composer

wget -O /usr/local/sbin/composer https://getcomposer.org/download/2.5.5/composer.phar
chmod +x /usr/local/sbin/composer

部署node

下载node

wget https://nodejs.org/dist/v12.18.3/node-v12.18.3-linux-x64.tar.xz

解压node

tar xf node-v12.18.3-linux-x64.tar.xz -C /data/apps/

创建软连接

ln -sv /data/apps/node-v12.18.3-linux-x64/ /usr/local/node

设置环境变量

echo 'export PATH=/usr/local/node/bin:$PATH' >> /etc/profile.d/node.sh
. /etc/profile

查看node版本

node -v

输出如下内容

v12.18.3

标签:nginx,部署,LNMP,centos7.9,usr,mysql,--,php,local
From: https://www.cnblogs.com/wangguishe/p/17388807.html

相关文章

  • 一图看懂CodeArts Deploy 5大特性,带你玩转部署服务
    华为云持续部署服务CodeArtsDeploy,通过模块化自由编排部署流程,实现软件的自动化部署,基于其易入门、功能全、集成度高、自动化、可靠的部署能力,能够帮您快速实现业务上云,全面提升软件的交付效率,显著提升交付质量! 产品详情地址:部署CodeArtsDeploy_一键部署到云主机和容器_多种部署......
  • Linux下部署安装JDK
    系统:Centos7安装jdk版本:1.8.0_371安装方式:压缩包jdk官网下载 https://www.oracle.com/java/technologies/downloads/#java8 先用Java-version命令检测系统是否默认安装了jdk,如有可以使用rpm命令卸载!1、利用工具将下载的包放到/usr/local下并解压#切换到jdk目录下cd/u......
  • 这4款国产办公软件,支持私有化部署,安全又实用
    在当前信息时代,人们对于信息安全和保护的需求越来越高,越来越多的企业和职员开始使用私有化部署办公软件。下面介绍四款国产办公软件,它们都支持私有化部署,不仅安全还实用。 一、向日葵远程控制软件  向日葵是一款远程控制软件,相较于其他远程控制软件,它有着更加简洁易懂的......
  • 记录以下关于我家的网络ip部署如何将所有设备的ip部署在同一网段下
    先说下家里的网络大概是如何连接的:首先使用的是移动光纤,入户以后由猫分出4个LAN口,分别对应我家客厅,主卧,书房,次卧,其中主卧和次卧基本没有使用.主要客厅和书房在用.客厅连接的是无线路由器,新款的无线路由器可以设置'有线中继'功能,该功能保证了连接到无线路由器的所有设备......
  • 关于Kubernetes-v1.23.6-网络组件-calico的安装部署...
    当2个workernodes节点加入到 Kubernetes/k8s集群后,我们去master节点、执行kubectlgetnodes命令就可以看到worker节点了但是我们会看到无论是master节点、还是worker节点,STATUS都会是  NotReady,如下[root@k8s-masterqq-5201351]#kubectlgetnodesNAME......
  • Hbase集群部署
    1.基本配置echo"192.168.80.45hbase01">>/etc/hostsecho"192.168.80.46hbase02">>/etc/hostsecho"192.168.80.47hbase03">>/etc/hostshostnamectlhostnamehbase01hostnamectlhostnamehbase02hostnamectl......
  • openstack部署2
     检查服务,查看dashboard页面有哪些功能检查服务状态检查计算节点,控制节点服务是up状态 检查网络节点是True的状态。这里的每个计算节点,都是一个neutron的客户端。查看dashboard每个页面的情况             ......
  • Linux(centos7.9)搭建DNS服务器
    一.DNS是什么 后期更新,目前只介绍服务器的搭建 二.linux搭建DNS服务器(目前只支持正向解析)以下服务器信息为该文档安装DNS服务环境 服务器信息:CentOS7  内核版本:3.10.0-1160.el7.x86_64 2.1 使用yum进行安装yuminstall-ybindbind-utils2.2安装完成后,查看......
  • 使用vscode搭建 vue3 + vite 项目, 部署到服务器 js css文件路径访问不到的问题
    使用vscode搭建vue3+vite项目,本地没有问题,build后部署到服务器,默认访问的是域名下的jscss文件,导致相对路径无法访问到。在vite.config.js中添加 :base: "./" 后就可以了。原因:默认的是 "/",  而我部署的路径是:/其他路径/项目名/dist/ ,所以把base改为./后......
  • 2023/5/14 遇到关于mongodb部署的问题
    之前使用关于mongodb5的版本中,linux系统中tar解压mongodb文件夹后的bin目录中mongod是启动mongo服务,而里面默认自带一个连接mongodb的shell脚本mongo而这几天使用mongodb6的版本中发现mongo脚本没有了,去网上查看发现是mongodb发行了一个新的shell脚本工具mongosh,这个需要自己安装......