Nginx/1.14.2编译安装使用Jemalloc
服务器信息:
[root@centos8 ~]# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)
[root@centos8 ~]#
[root@centos8 ~]# uname -r
4.18.0-193.el8.x86_64
Jemalloc是内存分配器,可以提升Nginx的性能。
安装Jemalloc:
dnf -y install bzip2 gcc-c++ make lsof
tar -jxvf jemalloc-5.2.1.tar.bz2
cd jemalloc-5.2.1
./configure
make && make install
ldconfig
ln -sf /usr/local/lib/libjemalloc* /usr/lib/
安装Nginx:(编译的时候使用Jemalloc)
dnf -y install pcre-devel openssl-devel zlib-devel gcc-c++ make psmisc
useradd -M -s /sbin/nologin nginx
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-ld-opt='-ljemalloc' && make && make install
ln -sf /usr/local/nginx/sbin/nginx /usr/sbin/
### 开机自动运行Nginx
[root@centos8 ~]# vi /etc/init.d/nginx
#!/bin/bash
#chkconfig: 35 99 20
#description:Nginx Service Control Script
case "$1" in
start)
/usr/local/nginx/sbin/nginx
;;
stop)
/usr/bin/killall -s QUIT nginx
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage:$0 {start|stop|restart}"
exit 1
esac
exit 0
[root@centos8 ~]# chmod a+x /etc/init.d/nginx
[root@centos8 ~]# chkconfig --add nginx
启动Nginx:
[root@centos8 ~]# systemctl start nginx
开机自动启动Nginx:
[root@centos8 ~]# systemctl enable nginx
nginx.service is not a native service, redirecting to systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable nginx
确认开机自动启动Nginx:
[root@centos8 ~]# systemctl is-enabled nginx
nginx.service is not a native service, redirecting to systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install is-enabled nginx
enabled
查看Nginx的进程:
[root@centos8 ~]# ps aux |grep nginx |grep -v grep
root 988 0.0 0.3 64860 6828 ? Ss 10:04 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 989 0.0 0.5 93752 10384 ? S 10:04 0:00 nginx: worker process
查看Nginx的版本和编译参数:
[root@centos8 ~]# nginx -V
nginx version: nginx/1.14.2
built by gcc 8.3.1 20191121 (Red Hat 8.3.1-5) (GCC)
built with OpenSSL 1.1.1c FIPS 28 May 2019
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-ld-opt=-ljemalloc
验证Nginx是否使用了Jemalloc:
[root@centos8 ~]# lsof -n |grep jemalloc
nginx 988 root mem REG 253,0 6123808 201710032 /usr/local/lib/libjemalloc.so.2
nginx 989 nginx mem REG 253,0 6123808 201710032 /usr/local/lib/libjemalloc.so.2
相关文章:
Nginx/1.14.2重新编译安装使用Jemalloc
MySQL8.0使用Jemalloc
CentOS8_lnmp1.7_LNMPA_安装Cacti |