安装包准备:
上传安装包到linux系统
一、进入gcc目录,执行以下命令
rpm -Uvh *.rpm --nodeps --force
gcc -v查看版本
二、 进入gcc-c++目录,执行命令
rpm -Uvh *.rpm --nodeps --force
g++ -v查看版本
三、安装PCRE
解压: tar -zxvf pcre-8.35.tar.gz
进入解压后的目录 cd pcre-8.35
依次执行以下命令
./configure
make
make install
四、安装libtool
解压: tar -zxvf libtool-2.4.2.tar.gz
进入解压后的目录 cd libtool-2.4.2
依次执行以下命令
./configure
make
make install
五、安装nginx
1、解压: tar -zxvf nginx-1.22.1.tar.gz
进入解压后的目录 cd nginx-1.22.1
依次执行以下命令
./configure
make
make install
nginx安装好的默认目录为/usr/local/nginx
2、启动nginx
cd /usr/local/nginx/sbin
./nginx
默认端口为80,浏览器直接访问ip即可
3、修改端口为8080
配置文件路径:
vim /usr/local/nginx/conf/nginx.conf
重新加载配置文件:
/usr/local/nginx/sbin/nginx -s reload
4、制作成服务,设置开机自启
vim /etc/init.d/nginx
内容:
#!/bin/bash
# chkconfig: 2345 85 15
# description: nginx Startup script for the Nginx HTTP Server
# processname: nginxnginxd=/usr/local/nginx/sbin/nginxnginx_config=/usr/local/nginx/conf/nginx.confnginx_pid=/var/run/nginx.pidRETVAL=0prog="nginx"# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ ${NETWORKING} = "no" ] && exit 0[ -x $nginxd ] || exit 0# Start nginx daemons functions.start() {if [ -e $nginx_pid ];thenecho "nginx already running...."exit 1fiecho -n $"Starting $prog: "daemon $nginxd -c ${nginx_config}RETVAL=$?echo[ $RETVAL = 0 ] && touch /var/lock/subsys/nginxreturn $RETVAL}# Stop nginx daemons functions.stop() {echo -n $"Stopping $prog: "killproc $nginxdRETVAL=$?echo[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid}# reload nginx service functions.reload() {echo -n $"Reloading $prog: "#kill -HUP `cat ${nginx_pid}`killproc $nginxd -HUPRETVAL=$?echo}# See how we were called.case "$1" instart) start;;stop)stop;;reload)reload;;restart)stopstart;;status)status $progRETVAL=$? ;;*)echo $"Usage: $prog {start|stop|restart|reload|status|help}"exit 1esacexit $RETVAL
添加可执行权限,
chmod +x /etc/init.d/nginx
测试:
[root@fault121 conf]# cd /etc/init.d/
[root@fault121 init.d]# ls
functions netconsole network nginx README
[root@fault121 init.d]# ./nginx reload
./nginx: line 26: [: =: unary operator expected
Reloading nginx: [ OK ]
[root@fault121 init.d]# ./nginx stop
./nginx: line 26: [: =: unary operator expected
Stopping nginx: [ OK ]
[root@fault121 init.d]# ./nginx start
./nginx: line 26: [: =: unary operator expected
Starting nginx: [ OK ]
[root@fault121 init.d]#
开机自启动:
cd /etc/init.d
chkconfig nginx on
[root@fault122 init.d]# chkconfig nginx on
[root@fault122 init.d]# service nginx start
Starting nginx (via systemctl): [ OK ]
[root@fault122 init.d]# service nginx stop
Stopping nginx (via systemctl): [ OK ]
[root@fault122 init.d]# chkconfig --listNote: This output shows SysV services only and does not include nativesystemd services. SysV configuration data might be overridden by nativesystemd configuration.If you want to list systemd services use 'systemctl list-unit-files'.To see services enabled on particular target use'systemctl list-dependencies [target]'.netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
redis 0:off 1:off 2:on 3:on 4:on 5:on 6:off