当前位置:   article > 正文

linux 服务器环境搭建_linux服务器环境部署

linux服务器环境部署

一:安装java

查看是否安装了java rpm -qa | grep java

1、卸载默认的jdk  yum -y remove java-1.8.0-openjdk
2、查看jdk列表     yum -y list java*
 
 
 
3. 安装   yum -y install java-1.8.0-openjdk-devel.x86_64   一定要安装devel版本
 
 
4、添加jdk7.0到系统环境变量

修改/etc/profile并且source /etc/profile

JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export JRE_HOME
export PATH
export CLASSPATH

 
 

二:安装tomcate

1、下载tomcate: 
 
2、安装tomcate
mkdir -p /usr/local/tomcat
tar zxvf apache-tomcat-7.0.70.tar.gz -C /usr/local/tomcat/
 
 

3、编译安装tomcat daemon服务守候程序:

cd /usr/local/tomcat/apache-tomcat-7.0.70/bin
tar xvzf commons-daemon-native.tar.gz
 
3.1 解压后会生成一个commons-daemon-1.0.15-native-src目录,cd到这个目录的Linux子目录:
cd commons-daemon-1.0.10-native-src/unix
3.2 注释:安装gcc(默认Mini版本没有安装gcc)
yum -y install gcc
3.3 执行编译配置
  1. ./configure #(注意:需要先安装好make,gcc等编译工具)
  2. ./configure --with-java=/opt/jdk 如果提示没有jdk,使用这个命令。主要是java目录未写入系
3.4 运行完成后会提示如下信息说明操作成功:
  1. ...
  2. *** All done ***
  3. Now you can issue "make"
3.5 执行make:
make
3.6 执行make后会生成一个jsvc的文件,将其复制到tomcat的bin目录。
cp jsvc /opt/tomcat/bin/
3.7 在tomcat/bin目录里面有一个daemon.sh 这个文件就是启动和关闭tomcat的服务守候程序。

注意:之前的一些tomcat版本,例如tomcat 6.0.x, 可能没有这个文件, 其实这个文件就是放在commons-daemon-x.x.x-native-src/unix/samples/Tomcat7.sh这儿的(此目录还有一个Tomcat5.sh),只不过新版本的tomcat把它移动到了bin目录下,并取名为daemon.sh了。所以,如果您使用的是tomcat 6,那就把这个Tomcat7.sh文件复制到bin目录下,并取名为daemon.sh即可。

3.8 修改daemon环境变量 :

用文本编辑器(vi或emacs等)编辑它,找到类似下面这样配置段:

 

  1. test ".$TOMCAT_USER" = . && TOMCAT_USER=tomcat
  2. # Set JAVA_HOME to working JDK or JRE
  3. # JAVA_HOME=/opt/jdk-1.6.0.22

3.9、修改TOMCAT_USER=tomcat为您要指定身份运行的linux账号用户名,此处指定用户名为tomcat。

并把JAVA_HOME=...前面的注释(即“#”号)去掉,并设置为jdk的安装目录路径,最后,修改好后的配置段变成如下:

  1. test ".$TOMCAT_USER" = . && TOMCAT_USER=tomcat
  2. # Set JAVA_HOME to working JDK or JRE
  3. JAVA_HOME=/opt/jdk

3.10、现在修改/opt/tomcat目录的所有者为tomcat(即您要指定身份运行的linux帐号):

  1. useradd -M tomcat #创建没有主目录的tomcat用户
  2. chsh tomcat -s /sbin/nologin #禁止tomcat登陆操作,类似于windows的系统账户
  3. chown -R tomcat /usr/local/tomcat/#将/usr/local/tomcat/下的所有档案与子目录进行相同的拥有者变更为tomcat用户

 

 

3.11、为tomcat/bin/目录下的*.sh添加相应的x权限位:

chmod +x /opt/tomcat/bin/*.sh

3.12、现在,可以测试一下daemon是否可以启动运行,启动方式如下:

  1. /opt/tomcat/bin/daemon.sh start
  2. curl http://localhost:8080 #测试一下是否启动

3.13、这时本机可以访问tomcat了,远程机器访问不了,是防火墙的问题,在 /etc/sysconfig/iptables添加

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT   #8080是tomcat的访问端口

重启iptable

service iptables restart

 

这样就可以访问了。

3.14、停止tomcat, 对应的命令为:

/opt/tomcat/bin/daemon.sh  stop

3.15、添加tomcat为Linux的服务,这时就简单了,只需要创建一个软链到/etc/init.d/目录中即可

ln  -s  /opt/tomcat/bin/daemon.sh  /etc/init.d/tomcat

3.16、现在就可以用它启动/关闭tomcat了:

  1. /etc/init.d/tomcat start #启动tomcat
  2. service tomcat start #启动tomcat
  3. /etc/init.d/tomcat stop #关闭tomcat
  4. service tomcat stop #关闭tomcat

3.17、设置tomcat服务开机启动,需要在daemon.sh中增加以下的语句:

  1. #!/bin/sh #这句是原文件里有的,下面的2句是要添加的
  2. # chkconfig: 2345 90 15
  3. # description: Tomcat-en Manager

3.18、再运行 chkconfig命令增加tomcat服务,而达到自启动:

chkconfig --add  tomcat

 重启机器,测试一下。

 

添加tomcat为Linux的服务,这时就简单了,只需要创建一个软链到/etc/init.d/目录中即可
ln -s /usr/local/tomcat/apache-tomcat-7.0.70/bin/daemon.sh /etc/init.d/tomcat
 
 

三:安装maven

1、下载maven:
 
2、安装maven
mkdir -p /usr/local/maven
1、解压: tar zxvf  apache-maven-3.0.4-bin.tar.gz -C /usr/local/maven/

2、解压后会生成apache-maven-3.0. 4目录,删除apache-maven-3.0.4-bin.tar.gz压缩包文件

3、执行 ln -s apache-maven-3.0.4 apache-maven(为Maven做一个软链接,方便以后升级)

4、执行 vi /etc/profile 文件,插入如下内容

         export M2_HOME=/usr/local/apache-maven

         export PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin

 

         export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE ...

 

5、保存并退出VI编辑器,执行 source /etc/profile 命令使改动生效

6、执行 mvn -v 命令,如出现如下内容表示安装配置成功

 

四、安装Nginx

 

什么是Nginx?

Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器,在高连接并发的情况下Nginx 是 Apache 服务器不错的替代品.其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好.目前中国大陆使用nginx网站用户有:新浪、网易、 腾讯,另外知名的微网志Plurk也使用nginx。 

Nginx 作为 负载均衡 服务器: 

Nginx 既可以在内部直接支持 Rails 和 PHP 程序对外进行服务,也可以支持作为 HTTP 代理服务器对外进行服务。 Nginx 采用 C 进行编写, 不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好很多。作为邮件代理服务器: 

Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器), Last.fm 描述了成功并且美妙的使用经验。Nginx 是一个安装非常简单,配置文件非常简洁(还能够支持perl语法), Bugs非常少的服务器: Nginx 启动特别容易,并且几乎可以做到 7*24 不间断运行,即使运行数个月也不需要重新启动。 你还能够不间断服务的情况下进行软件版本的升级。

 

Nginx的安装

模块依赖性Nginx需要依赖下面3个包

1. gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ )

2. rewrite 模块需要 pcre 库 ( 下载: http://www.pcre.org/ )

3. ssl 功能需要 openssl 库 ( 下载: http://www.openssl.org/ )

 

Nginx包下载: http://nginx.org/en/download.html

 

依赖包安装顺序依次为:openssl、zlib、pcre, 然后安装Nginx包.

 

图解教程

第一步: 下载安装所需包

openssl-fips-2.0.2.tar.gz

zlib-1.2.7.tar.gz

pcre-8.21.tar.gz

nginx-1.2.6.tar.gz

第二步:依次安装openssl-fips-2.0.2.tar.gz, zlib-1.2.7.tar.gz, pcre-8.21.tar.gz, nginx-1.2.6.tar.gz

1.安装openssl-fips-2.0.2.tar.gz

  1. [root@localhost mrms]# tar -zxvf openssl-fips-2.0.2.tar.gz
  2. [root@localhost mrms]# cd openssl-fips-2.0.2
  3. [root@localhost openssl-fips-2.0.2]# ./config
  4. [root@localhost openssl-fips-2.0.2]# make
  5. [root@localhost openssl-fips-2.0.2]# makeinstall

2.安装zlib-1.2.7.tar.gz

  1. [root@localhost mrms]# tar -zxvf zlib-1.2.7.tar.gz
  2. [root@localhost mrms]# cd zlib-1.2.7
  3. [root@localhost zlib-1.2.7]# ./configure
  4. [root@localhost zlib-1.2.7]# make
  5. [root@localhost zlib-1.2.7]# makeinstall

3.安装pcre-8.21.tar.gz

  1. [root@localhost mrms]# tar -zxvf pcre-8.21.tar.gz
  2. [root@localhost mrms]# cd pcre-8.21
  3. [root@localhost pcre-8.21]# ./configure
  4. [root@localhost pcre-8.21]# make
  5. [root@localhost pcre-8.21]# makeinstall

 4.安装 nginx-1.2.6.tar.gz

  1. [root@localhost mrms]# tar -zxvf nginx-1.2.6.tar.gz
  2. [root@localhost mrms]# cd nginx-1.2.6
  3. [root@localhost nginx-1.2.6]# ./configure --with-pcre=../pcre-8.21 --with-zlib=../zlib-1.2.7 --with-openssl=../openssl-fips-2.0.2
  4. [root@localhost nginx-1.2.6]# make
  5. [root@localhost nginx-1.2.6]# makeinstall

至此Nginx的安装完成!

第三步:检测是否安装成功

  1. [root@localhost nginx-1.2.6]# cd /usr/local/nginx/sbin
  2. [root@localhost sbin]# ./nginx -t

出现如下所示提示,表示安装成功

 uploading.4e448015.gif转存失败重新上传取消

启动nginx

[root@localhost sbin]# ./nginx

查看端口

[root@localhost sbin]# netstat -ntlp

结果如下

uploading.4e448015.gif转存失败重新上传取消

 

vim /etc/init.d/nginx       将下面的代码复制进去保存!

#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx'
 
### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO
 
# Author:   licess
# website:   http://lnmp.org
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginx
NGINX_BIN=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
 
case "$1" in
    start)
        echo -n "Starting $NAME... "
 
        if netstat -tnpl | grep -q nginx;then
            echo "$NAME (pid `pidof $NAME`) already running."
            exit 1
        fi
 
        $NGINX_BIN -c $CONFIGFILE
 
        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
        ;;
 
    stop)
        echo -n "Stoping $NAME... "
 
        if ! netstat -tnpl | grep -q nginx; then
            echo "$NAME is not running."
            exit 1
        fi
 
        $NGINX_BIN -s stop
 
        if [ "$?" != 0 ] ; then
            echo " failed. Use force-quit"
            exit 1
        else
            echo " done"
        fi
        ;;
 
    status)
        if netstat -tnpl | grep -q nginx; then
            PID=`pidof nginx`
            echo "$NAME (pid $PID) is running..."
        else
            echo "$NAME is stopped"
            exit 0
        fi
        ;;
 
    force-quit)
        echo -n "Terminating $NAME... "
 
        if ! netstat -tnpl | grep -q nginx; then
            echo "$NAME is not running."
            exit 1
        fi
 
        kill `pidof $NAME`
 
        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
        ;;
 
    restart)
        $0 stop
        sleep 1
        $0 start
        ;;
 
    reload)
        echo -n "Reload service $NAME... "
 
        if netstat -tnpl | grep -q nginx; then
            $NGINX_BIN -s reload
            echo " done"
        else
            echo "$NAME is not running, can't reload."
            exit 1
        fi
        ;;
 
    configtest)
        echo -n "Test $NAME configure files... "
 
        $NGINX_BIN -t
        ;;
 
    *)
        echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
        exit 1
        ;;
 
esac
 
 
 
 
 
保持文件后

 [root@localhost /]# cd /etc/rc.d/init.d

 [root@localhost init.d]#  chmod +x nginx

 [root@localhost init.d]# /sbin/chkconfig --level 345 nginx on

任何位置都能运行   service nginx start           可选  start | stop | restart | reload | status |  help

 
 

五、装MYSQL

1.下载和解压mysql数据库
 
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.9-linux-glibc2.5-x86_64.tar.gzs
 
tar -xvf mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz -C /usr/local/mysql-5.7.9
 
2.建立软链接
ln -s mysql-5.7.9 mysql
 
 
3.创建mysql用户和修改软件的权限
 
   useradd -r -M -s /sbin/nologin mysql
 
   chown -R mysql.mysql  /usr/local/mysql-5.7.9
   chown -R mysql.mysql /usr/local/mysql
 
   chgrp -R mysql /usr/local/mysql-5.7.9
 
4.安装和初始化数据库
 
   cd /usr/local/mysql-5.7.9/
 
   bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.7.9/ --datadir=/usr/local/mysql-5.7.9/data/            --必须在mysql根目录安装mysql,否则出错
 
   cp -a ./support-files/my-default.cnf  /etc/my.cnf
 
   cp -a ./support-files/mysql.server  /etc/init.d/mysqld
 
   #cd bin/
   #./mysqld_safe --user=mysql & 
 
   [root@db2 scripts]# /etc/init.d/mysqld restart
   Shutting down MySQL..                                      [  OK  ]
   Starting MySQL...                                          [  OK  ]
 
  #开机启动
  chkconfig --level 35 mysqld on
 
5.初始化密码
 
mysql5.7会生成一个初始化密码,而在之前的版本首次登陆不需要登录。
 
shell> cat /root/.mysql_secret 
 
mysql -uroot -p 
 
SET PASSWORD = PASSWORD('123456');
flush privileges
6.添加PATH环境变量:
# vim /etc/profile
在最后,添加:
export PATH="/usr/local/webserver/mysql/bin:$PATH"
保存,退出,然后运行:
#source /etc/profile
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/206841
推荐阅读
相关标签
  

闽ICP备14008679号