1.NGINX

首先安装的是nginx,nginx编译时需要依赖gcc,http模块需要用到pcre,gzip需要用到zlib,https需要用到OpenSSL

先通过yum安装这几个家伙。

yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

接下来需要到nginx的官网,下载nginx的源代码,解压进入文件夹。先做编译前配置:

./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--with-http_stub_status_module \
--with-http_ssl_module

配置没有问题了,就开始编译和安装了

make & make install

跑完之后,可以运行以下命令来启动nginx服务

/usr/local/nginx/sbin/nginx

如果报错:[emerg] mkdir() “/var/temp/nginx/client” failed (2: No such file or directory),则需要手动mkdir文件夹出来。

执行命令不出意外的话,直接访问ip,将会看到Welcome to nginx的欢迎页。

接下来就需要加入的服务和开机启动了。

vi /etc/init.d/nginx
#!/bin/sh
# Comments to support chkconfig on centos Linux
# chkconfig: 2345 65 37
# description: zixuwang nginx

set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME

# If the daemon file is not found, terminate the script.
test -x $DAEMON || exit 0

d_test() {
    $DAEMON -t
}
d_start() {
    $DAEMON || echo -n " already running"
}
d_stop() {
    $DAEMON -s quit || echo -n " not running"
}
d_reload() {
    $DAEMON -s reload || echo -n " could not reload"
}

case "$1" in
    test)
      d_test
      echo "."
      ;;
    start)
      echo -n "Starting $DESC: $NAME"
      d_start
      echo "."
      ;;
    stop)
      echo -n "Stopping $DESC: $NAME"
      d_stop
      echo "."
      ;;
    reload)
      echo -n "Reloading $DESC configuration..."
      d_reload
      echo "reloaded."
      ;;
    restart)
      echo -n "Restarting $DESC: $NAME"
      d_stop
      # Sleep for two seconds before starting again, this should give the
      # Nginx daemon some time to perform a graceful stop.
      sleep 2
      d_start
      echo "."
      ;;
    *)
      echo "Usage: $SCRIPTNAME {test|start|stop|restart|reload}" >&2
      exit 3
      ;;
esac

exit $?

注册服务:

chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig --level 2345 nginx on

服务命令:

# 检测 nginx 配置
service nginx test
# 启动
service nginx start
# 关闭
service nginx stop
# 重启
service nginx restart
# 重载配置
service nginx reload

2.JDK

直接下载jdk的压缩包,创建目录/usr/local/java/jdk10.0.1,解压后放进去。

cp -r jdk-10.0.1/* /usr/local/java/jdk10.0.1

加入环境变量

vi /etc/profile

在profile最后加入

JAVA_HOME=/usr/local/java/jdk10.0.1
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME CLASS_PATH PATH

使环境reload

source /etc/profile

环境变量配置无误,jdk配置成功。

3.TOMCAT

tomcat官网下载源文件,创建目录 /usr/local/java/tomcat9.0.8,解压后放进去。

cp -r apache-tomcat-9.0.8/* /usr/local/java/tomcat9.0.8

加入环境变量,和jdk方法类似

vi /etc/profile
CATALINA_BASE=/usr/local/java/tomcat9.0.8
PATH=$CATALINA_BASE/bin:$PATH
export PATH CATALINA_BASE

如果tomcat启动慢,可以参考https://blog.csdn.net/u013939884/article/details/72860358的解决方案。

加入服务和开机启动

vi /etc/rc.d/init.d/tomcat
#!/bin/bash  
# /etc/rc.d/init.d/tomcat  
# init script for tomcat precesses  
# processname: tomcat  
# description: tomcat is a j2se server  
# chkconfig: 2345 86 16  
# description: Start up the Tomcat servlet engine.  


if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
echo -e "\atomcat: unable to locate functions lib. Cannot continue."
exit -1
fi
RETVAL=$?
CATALINA_HOME="/usr/local/java/tomcat9.0.8"
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac
exit $RETVAL
chmod 755 /etc/rc.d/init.d/tomcat
chkconfig --add /etc/rc.d/init.d/tomcat

加入开机自启

为了防tomcat开机时,jdk的环境变量还没有生效,在tomcat中的catalina.sh文件中的大概99行出在“OS specific support”前面加上

export JAVA_HOME=/usr/local/java/jdk10.0.1
export CATALINA_HOME=/usr/local/java/tomcat9.0.8
export CATALINA_BASE=/usr/local/java/tomcat9.0.8
export CATALINA_TMPDIR=/usr/local/java/tomcat9.0.8/temp

在服务的时候自启好像一直有问题,所以还是采取简单粗暴的方法,让他开机自启。

vi /etc/rc.d/rc.local
export JAVA_HOME=/usr/local/java/jdk10.0.1
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar  
export PATH=$PATH:$JAVA_HOME/bin  
export CATALINA_HOME=/usr/local/java/tomcat9.0.8
/usr/local/tomcat/bin/startup.sh

使环境reload

source /etc/profile

4.MYSQL

这里使用rpm的安装方式,因为舒服,啪啪两下就安装好了。

先下载yum源的rpm安装包

wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
yum localinstall mysql57-community-release-el7-8.noarch.rpm

修改/etc/yum.repos.d/mysql-community.repo源,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0

yum install mysql-community-server

安装好后启动服务

systemctl start mysqld

开机启动

systemctl enable mysqld
systemctl daemon-reload

修改mysql的root密码,安装完之后会在log有初始密码。

grep 'temporary password' /var/log/mysqld.log

登录上mysql

mysql -u root -p

mysql56以上版本,含密码规则插件,弱密码会提示Your password does not satisfy the current policy requirements,这时候修改validate_password_policy参数的值即可

set global validate_password_policy=0;

密码满足安全策略可以忽略该步骤

set password for 'root'@'localhost'=password('你的密码');

5.REDIS

redis安装是最简单的,下载代码,编译,修改配置,加入自启脚本。

http://download.redis.io/releases/ 找到想安装的版本

下载,解压,放到 /usr/local/redis 目录下

wget http://download.redis.io/releases/redis-4.0.9.tar.gz
tar xzvf redis-4.0.9.tar.gz
mkdir /usr/local/redis
cp -r redis-4.0.9/* /usr/local/redis

跑编译

cd /usr/local/redis
make && make install

改配置

vi redis.conf

找到daemonize,改成yes,以守护模式启动。如果需要配置密码,把requirepass的注释去掉,后面加上密码。

保存,启动命令:

/usr/local/redis/src/redis-server /usr/local/redis/redis.conf

后面的redis.conf必须加上,意思使用这个配置文件。

加入开机脚本

vi /etc/rc.d/rc.local

在最后加上

/usr/local/redis/src/redis-server /usr/local/redis/redis.conf

END