lnmp部署

Lnmp部署
安装mysql,我是用二进制安装mysql
[root@centos-2 ~]# tar -zxf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@centos-2 ~]# mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
[root@centos-2 ~]# mkdir /usr/local/mysql/data
[root@centos-2 ~]# groupadd -r mysql
[root@centos-2 ~]# useradd -r -g mysql -M -s /bin/false mysql
[root@centos-2 ~]# chown -R mysql:mysql /usr/local/mysql
[root@centos-2 ~]# rpm -e mariadb-libs --nodeps
[root@centos-2 ~]# cat> /etc/my.cnf <<EOF
> [client]
> socket=/usr/local/mysql/mysql.sock
> [mysqld]
> basedir=/usr/local/mysql
> datadir=/usr/local/mysql/data
> pid-file=/usr/local/mysql/data/mysql.pid
> socket=/usr/local/mysql/mysql.sock
> log-error=/usr/local/mysql/data/mysql.err
> EOF
[root@centos-2 ~]# ln -s /usr/local/mysql/bin/* /usr/local/bin/
[root@centos-2 ~]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
[root@centos-2 ~]# mv /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@centos-2 ~]# chkconfig --add mysqld
[root@centos-2 ~]# chkconfig mysqld
[root@centos-2 ~]# chkconfig mysqld on
[root@centos-2 ~]# systemctl start mysqld
[root@centos-2 ~]# mysqlpwd=` grep password /usr/local/mysql/data/mysql.err |awk -F 'root@localhost: ' '{print $2}'`
[root@centos-2 ~]# mysql -uroot -p${mysqlpwd} -e 'alter user root@localhost identified by"123"' --connect-expired-password
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@centos-2 ~]# firewall-cmd --permanent --add-port=3306/tcp
success
[root@centos-2 ~]# firewall-cmd --reload
success
[root@centos-2 ~]# ss -anpt | grep mysql
LISTEN     0      80          :::3306                    :::*                   users:(("mysqld",pid=1739,fd=20))
安装nginx
[root@centos-2 ~]# mount /dev/cdrom /media
[root@centos-2 ~]# cd /etc/yum.repos.d/
[root@centos-2 yum.repos.d]# mkdir bak
[root@centos-2 yum.repos.d]# mv * bak/
mv: 无法将目录"bak" 移动至自身的子目录"bak/bak" 下
[root@centos-2 yum.repos.d]# echo '[media]' >> media.repo
[root@centos-2 yum.repos.d]# echo 'name=media' >> media.repo
[root@centos-2 yum.repos.d]# echo 'baseurl=file:///media' >> media.repo
[root@centos-2 yum.repos.d]# echo 'enable=1' >> media.repo
[root@centos-2 yum.repos.d]# echo 'gpgcheck=0' >> media.repo
[root@centos-2 yum.repos.d]# yum -y install gcc gcc-c++ make libtool zlib zlib-devel pcre pcre-devel openssl openssl-devel
已加载插件:fastestmirror
Determining fastest mirrors
[root@centos-2 yum.repos.d]# cd
[root@centos-2 ~]# groupadd www
[root@centos-2 ~]# useradd -g www -s /sbin/nologin -M www
[root@centos-2 ~]# wget http://nginx.org/download/nginx-1.16.0.tar.gz
--2019-05-24 16:33:25--  http://nginx.org/download/nginx-1.16.0.tar.gz
正在解析主机 nginx.org (nginx.org)... 95.211.80.227, 62.210.92.35, 2001:1af8:4060:a004:21::e3
正在连接 nginx.org (nginx.org)|95.211.80.227|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1032345 (1008K) [application/octet-stream]
正在保存至: “nginx-1.16.0.tar.gz”

100%[===================================================================>] 1,032,345   32.9KB/s 用时 11s    

2019-05-24 16:33:46 (94.9 KB/s) - 已保存 “nginx-1.16.0.tar.gz” [1032345/1032345])
[root@centos-2 ~]# tar zxf nginx-1.16.0.tar.gz
[root@centos-2 ~]# cd nginx-1.16.0
[root@centos-2 nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre --with-http_ssl_module --with-http_gzip_static_module --user=www --group=www
[root@centos-2 nginx-1.16.0]# make -j 2 && make install
[root@centos-2 nginx-1.16.0]# cp /usr/local/nginx/sbin/* /usr/local/sbin/
[root@centos-2 nginx-1.16.0]# chmod +x //usr/local/sbin/*
[root@centos-2 nginx-1.16.0]# nginx
[root@centos-2 nginx-1.16.0]# ss -anpt | grep nginx
LISTEN     0      128          *:80                       *:*                   users:(("nginx",pid=4602,fd=6),("nginx",pid=4601,fd=6))
[root@centos-2 nginx-1.16.0]# firewall-cmd --permanent --add-port=80/tcp
success
[root@centos-2 nginx-1.16.0]# firewall-cmd --reload
Success
安装php
[root@centos-2 ~]# yum -y install libxml2-devel lzip2-devel libcurl-devel libmcrypt-devel openssl-devel bzip2-devel
[root@centos-2 ~]# tar zxf libmcrypt-2.5.7.tar.gz
[root@centos-2 ~]# cd libmcrypt-2.5.7/
[root@centos-2 libmcrypt-2.5.7]# ./configure --prefix=/usr/local/libmcrypt && make && make install
[root@centos-2 ~]# tar zxf php-5.6.27.tar.gz
[root@centos-2 php-5.6.27]# ./configure --prefix=/usr/local/php5.6 --with-mysql=mysqlnd \
> --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-fpm --enable-sockets \
> --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib \
> --with-libxml-dir=/usr  --enable-xml  --with-mhash  --with-mcrypt=/usr/local/libmcrypt \
> --with-config-file-path=/etc  --with-config-file-scan-dir=/etc/php.d \
> --with-bz2 --enable-maintainer-zts && make -j 2 && make install
[root@centos-2 php-5.6.27]# cp php.ini-production /etc/php.ini && cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm && chmod +x /etc/init.d/php-fpm && chkconfig --add php-fpm && chkconfig php-fpm on
[root@centos-2 php-5.6.27]# cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf
[root@centos-2 php-5.6.27]# sed -i 's/;pid = run/pid = run/g' /usr/local/php5.6/etc/php-fpm.conf
[root@centos-2 php-5.6.27]# sed -i 's/listen = 127.0.0.1:9000/listen = 192.168.1.102:9000/g' /usr/local/php5.6/etc/php-fpm.conf
[root@centos-2 php-5.6.27]# sed -i 's/pm.max_children = 5/pm.max_children = 50/g' /usr/local/php5.6/etc/php-fpm.conf
[root@centos-2 php-5.6.27]# sed -i 's/pm.start_servers = 2/pm.start_servers = 5/g' /usr/local/php5.6/etc/php-fpm.conf
[root@centos-2 php-5.6.27]# sed -i 's/pm.min_spare_servers = 1/pm.min_spare_servers = 5/g' /usr/local/php5.6/etc/php-fpm.conf
[root@centos-2 php-5.6.27]# sed -i 's/pm.max_spare_servers = 3/pm.max_spare_servers = 35/g' /usr/local/php5.6/etc/php-fpm.conf
[root@centos-2 php-5.6.27]# systemctl start php-fpm
[root@centos-2 php-5.6.27]# firewall-cmd --permanent --add-port=9000/tcp
success
[root@centos-2 php-5.6.27]# firewall-cmd --reload
Success
[root@centos-2 php-5.6.27]# ss -anpt | grep 9000
LISTEN     0      128    192.168.1.102:9000                     *:*                   users:(("php-fpm",pid=120461,fd=0),("php-fpm",pid=120460,fd=0),("php-fpm",pid=120459,fd=0),("php-fpm",pid=120458,fd=0),("php-fpm",pid=120457,fd=0),("php-fpm",pid=120456,fd=7))
修改nginx主配文件
[root@centos-2 html]# cat /usr/local/nginx/conf/nginx.conf
user www www;
worker_processes 2;
worker_cpu_affinity 01 10;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
	 use epoll;
	 worker_connections 65535;
	 multi_accept on;
}
http {
	 include mime.types;
	 default_type application/octet-stream;
	 #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
	 # '$status $body_bytes_sent "$http_referer" '
	 # '"$http_user_agent" "$http_x_forwarded_for"';
	 #access_log logs/access.log main;
	 sendfile on;
	 tcp_nopush on;
	 keepalive_timeout 65;
	 tcp_nodelay on;
	 client_header_buffer_size 4k;
	 open_file_cache max=102400 inactive=20s;
	 open_file_cache_valid 30s;
	 open_file_cache_min_uses 1;
	 client_header_timeout 15;
	 client_body_timeout 15;
	 reset_timedout_connection on;
	 send_timeout 15;
	 server_tokens off;
	 client_max_body_size 10m;
	 fastcgi_connect_timeout 600;
	 fastcgi_send_timeout 600;
	 fastcgi_read_timeout 600;
	 fastcgi_buffer_size 64k;
	 fastcgi_buffers 4 64k;
	 fastcgi_busy_buffers_size 128k;
	 fastcgi_temp_file_write_size 128k;
	 fastcgi_temp_path /usr/local/nginx/nginx_tmp;
	 fastcgi_intercept_errors on;
	 fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2
	keys_zone=cache_fastcgi:128m inactive=1d max_size=10g;
	 gzip on;
	 gzip_min_length 2k;
	 gzip_buffers 4 32k;
	 gzip_http_version 1.1;
	 gzip_comp_level 6;
	 gzip_types text/plain text/css text/javascript application/json application/javascript
	application/x-javascript application/xml;
	 gzip_vary on;
	 gzip_proxied any;
		 server {
			 listen 80;
			 server_name 192.168.1.102;
			 #charset koi8-r;
			 #access_log logs/host.access.log main;
			 location ~* ^.+\.(jpg|gif|png|swf|flv|wma|wmv|asf|mp3|mmf|zip|rar)$ {
				 valid_referers none blocked 192.168.1.102;
				 if ($invalid_referer) {
					 #return 302 http://www.benet.com/img/nolink.jpg;
					 return 404;
					 break;
				 }
				 access_log off;
		 }
		 location / {
			 root html;
			 index index.php index.html index.htm;
		 }
		 location ~* \.(ico|jpe?g|gif|png|bmp|swf|flv)$ {
			 expires 30d;
			 #log_not_found off;
			 access_log off;
		 }
		 location ~* \.(js|css)$ {
			 expires 7d;
			 log_not_found off;
			 access_log off;
		 }
		 location = /(favicon.ico|roboots.txt) {
			 access_log off;
			 log_not_found off;
		 }
		 location /status {
			 stub_status on;
		 }
		 location ~ .*\.(php|php5)?$ {
		 	 root html;
			 fastcgi_pass 192.168.1.102:9000;
			 fastcgi_index index.php;
			 include fastcgi.conf;
			 fastcgi_cache cache_fastcgi;
			 fastcgi_cache_valid 200 302 1h;
			 fastcgi_cache_valid 301 1d;
			 fastcgi_cache_valid any 1m;
			 fastcgi_cache_min_uses 1;
			 fastcgi_cache_use_stale error timeout invalid_header http_500;
			 fastcgi_cache_key http://$host$request_uri;
		 }
		 #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 html;
		 }
	 }
}
[root@centos-2 html]# 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
[root@centos-2 html]# nginx -s reload

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值