分离部署lnmp
发布时间:2023-02-17 14:02:40 所属栏目:LNMP 来源:互联网
导读:环境 应用 IP 操作系统 Nginx 192.168.122.131 centos8 MysqL 192.168.122.132 centos8 PHP 192.168.122.133 centos8 准备工作 //关闭防火墙 # systemctl disable --Now firewalld # setenforce 0 # vim /etc/selinux/config SELINUX=disabled 安装Nginx //
环境 应用 IP 操作系统 Nginx 192.168.122.131 centos8 MysqL 192.168.122.132 centos8 PHP 192.168.122.133 centos8 准备工作 //关闭防火墙 # systemctl disable --Now firewalld # setenforce 0 # vim /etc/selinux/config SELINUX=disabled 安装Nginx //安装依赖环境 [root@Nginx ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make wget [root@Nginx ~]# yum -y groups mark install 'Development Tools' //下载Nginx包 [root@Nginx ~]# wget http://Nginx.org/download/Nginx-1.20.0.tar.gz //创建Nginx系统用户 [root@Nginx ~]# useradd -r -M -s /sbin/nologin Nginx //创建日志存放目录 [root@Nginx ~]# mkdir -p /var/log/Nginx [root@Nginx ~]# chown -R Nginx.Nginx /var/log/Nginx //编译安装Nginx [root@Nginx ~]# tar -xf Nginx-1.20.0.tar.gz [root@Nginx ~]# cd Nginx-1.20.0 [root@Nginx Nginx-1.20.0]# ./configure --prefix=/usr/local/Nginx --user=Nginx --group=Nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/Nginx/access.log --error-log-path=/var/log/Nginx/error.log [root@Nginx Nginx-1.20.0]# make && make install //配置环境变量 [root@Nginx Nginx-1.20.0]# echo 'export PATH=/usr/local/Nginx/sbin:$PATH' > /etc/profile.d/Nginx.sh [root@Nginx Nginx-1.20.0]# . /etc/profile.d/Nginx.sh //修改配置文件 [root@Nginx ~]# vim /usr/local/Nginx/conf/Nginx.conf location / { root html; //添加index.PHP index index.PHP index.html index.htm; } location ~ .PHP$ { // 设置监听端口 fastcgi_pass 192.168.122.133:9000; // 设置Nginx的默认首页文件 fastcgi_index index.PHP; // 设置脚本文件请求的路径 fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name; 将$scripts修改为PHP根网站目录 //引入fastcgi的配置文件 include fastcgi_params; } [root@Nginx ~]# Nginx -t Nginx: the configuration file /usr/local/Nginx/conf/Nginx.conf Syntax is ok Nginx: configuration file /usr/local/Nginx/conf/Nginx.conf test is successful //创建ndex.PHP [root@Nginx ~]# cat > /usr/local/Nginx/html/index.PHP <<EOF > <?PHP > PHPinfo(); > ?> > EOF //启动服务 [root@Nginx ~]# Nginx 安装配置MysqL //安装 wget https://downloads.MysqL.com/archives/get/p/23/file/MysqL-5.7.31-linux-glibc2.12-x86_64.tar.gz //安装依赖环境 [root@MysqL ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs //创建用户 [root@MysqL ~]# useradd -r -M -s /sbin/nologin MysqL //安装MysqL [root@MysqL ~]# tar -xf MysqL-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@MysqL ~]# ln -sv /usr/local/MysqL-5.7.31-linux-glibc2.12-x86_64/ /usr/local/MysqL [root@MysqL ~]# cd /usr/local/ [root@MysqL local]# chown -R MysqL.MysqL MysqL* //添加环境变量 [root@MysqL local]# echo 'export PATH=/usr/local/MysqL/bin:$PATH' > /etc/profile.d/myslq.sh [root@MysqL local]# source /etc/profile.d/myslq.sh [root@MysqL local]# ln -s /usr/local/MysqL/include/ /usr/include/MysqL [root@MysqL local]# echo '/usr/local/MysqL/lib' >/etc/ld.so.conf.d/MysqL.conf [root@MysqL local]# ldconfig //创建数据存放目录 [root@MysqL local]# mkdir /opt/mydata [root@MysqL local]# chown -R MysqL.MysqL /opt/mydata/ [root@MysqL local]# MysqLd --initialize-insecure --user=MysqL --datadir=/opt/mydata //生成配置文件 [root@MysqL local]# cat > /etc/my.cnf <<EOF [MysqLd] basedir=/usr/local/MysqL datadir=/opt/mydata socket=/tmp/MysqL.sock port=3306 pid-file=/opt/mydata/MysqL.pid user=MysqL skip-name-resolve EOF //配置服务启动脚本 [root@MysqL local]# cp /usr/local/MysqL/support-files/MysqL.server /etc/init.d/MysqLd [root@MysqL local]# sed -ri 's#^(basedir=).*#1/usr/local/MysqL#g' /etc/init.d/MysqLd [root@MysqL local]# sed -ri 's#^(datadir=).*#1/opt/mydata#g' /etc/init.d/MysqLd //启动MysqL [root@MysqL local]# service MysqLd start //设置密码 [root@MysqL local]# MysqL -e "set password = password('123456')" 安装PHP [root@localhost tmp]# yum -y install PHP* [root@localhost tmp]# vim /etc/PHP-fpm.d/www.conf ;listen = /run/PHP-fpm/www.sock //注释此行 listen = 0.0.0.0:9000 //添加监听端口 ; accepted from any ip address. ; Default Value: any listen.allowed_clients = 192.168.122.131 //Nginx主机的ip [root@localhost tmp]# cat /var/www/html/index.PHP <?PHP PHPinfo(); ?> [root@localhost tmp]# chown -R Nginx.Nginx /var/www/html/ [root@localhost tmp]# systemctl start PHP-fpm (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |