Centos云计算笔记1虚拟机上网、nginx安装、tomcat安装

虚拟机安装

https://blog.csdn.net/qq_35904625/article/details/79905720

修改网络地址:

1、设置网卡为nat模式

2、确保windows下的服务是否启动(dhcp,nat服务)

3、编辑文件

vi /etc/sysconfig/network-scripts/ifcfg-eth0

4、ONBOOT=yes

5、设置IP

BOOTPROTO=static        #原本后面是dhcp
IPADDR=192.168.204.122  #在虚拟机-编辑=虚拟网络编辑器,配置网段
NETMASK=255.255.255.0   #和子网掩码
GATEWAY=192.168.204.2   #一般是.2作为虚拟机网关

6、设置dns服务

$vi /etc/resolv.conf
nameserver 8.8.8.8

7、重启网络:service network restart

此时可以ping www.baidu.com


8、克隆之后遇到如下问题

Centos 配置eth0 提示Device does not seem to be present

删除70-persistent-net.rules

重启


 CentOS系统时间同网络时间同步


$yum -y install ntp ntpdate
$ntpdate cn.pool.ntp.org
$hwclock –systohc

tengine安装

1. 安装依赖 yum -y install gcc openssl-devel pcre-devel zlib-devel

2. 复制tengine压缩包到Linux

3.解压

$tar -zxvf tengine-2.1.0.tar.gz 

tar -xvf 出错

4.进入解压目录,编译

$./configure \
  --prefix=/usr/tengine-2.1/ \
  --error-log-path=/var/log/nginx/error.log \
  --http-log-path=/var/log/nginx/access.log \
  --pid-path=/var/run/nginx/nginx.pid  \
  --lock-path=/var/lock/nginx.lock \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_stub_status_module \
  --with-http_gzip_static_module \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
  --http-scgi-temp-path=/var/tmp/nginx/scgi \
  --with-pcre 
$make && make install


/etc/init.d下面建立nginx文件,粘贴内容,修改路径


#第一行操作错误会导致 /etc/init.d/nginx: line 1: #!/bin/bash: No such file or directory,虽然还能运行。最方便的是重新复制一个脚本过去。因为导致的原因蛮多的,排查显得有点浪费时间。

#第二行,从Win复制脚本过去会少第一二行,

#第三行是支持chkconfig的标志,错误的话导致不能加入chkconfig服务

这三行不能错

#!/bin/bash            
#
# chkconfig: - 85 15   
# description: nginx is a World Wide Web server. It is used to serve
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
nginx="/usr/tengine-2.1/sbin/nginx"
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/usr/tengine-2.1/conf/nginx.conf"
 
#[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
 
lockfile=/var/lock/subsys/nginx
 
#make_dirs() {
#   # make required directories
#   user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
#   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
#   for opt in $options; do
#       if [ `echo $opt | grep '.*-temp-path'` ]; then
#           value=`echo $opt | cut -d "=" -f 2`
#           if [ ! -d "$value" ]; then
#               # echo "creating" $value
#               mkdir -p $value && chown -R $user $value
#           fi
#       fi
#   done
#}
 
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
#    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
 
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
#  -HUP是nginx平滑重启参数  
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
 
force_reload() {
    restart
}
 
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
 
rh_status() {
    status $prog
}
 
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac


修改nginx文件的执行权限

$chmod a+x nginx

添加该文件到系统服务中去

$chkconfig --add nginx

查看是否添加成功

$chkconfig --list nginx

启动,停止,重新装载

$service nginx start|stop|reload


若nginx没有反应 修改路径

修改路径



浏览器访问ip

连接失败,则关闭虚拟机防火墙

$service iptables stop

能访问虚拟机内部正在运行的nginx服务器了


这一步准备克隆

不过我直接再创建多台虚拟机,毕竟克隆之后需要修改的东西怕一马虎就忘记了哪一项。对于初学者来说,重新创建反而是更快的方式。


Tomcat安装

在有安装java jdk 并且配置了环境变量的虚拟机中,解压tomcat,在bin中运行启动脚本即可。

安装jdk

1、下载rpm包

2、使用xshell移动到虚拟机

3、rpm ivh jdk-xxxx-linux-x64.rpm安装

4、vi /etc/profile 配置变量


比如我的jdk版本是jdk-8u161-linux-x64.rpm

写入

export JAVA_HOME=/usr/java/jdk1.8.0_161           在安装了java之后,/usr/java会自动生成jdk1.xxx 填写自动生成的路径

export PATH=$PATH:$JAVA_HOME/bin



5、拷贝tomcat 压缩包

同样的tab补全压缩包全称

tar xzvf apache-tomcat-7.0.61.tar.gz

6、进入解压后的apache的bin目录下面运行./startup.sh 看到最后一行tomcat started并且在虚拟机外部浏览器输入ip地址:8080能访问就是成功了,记得关防火墙。

还遇到了java路径没有配置对,却能./startup.sh Tomcat started.的情况,这时的./shutdown.sh会出现找不到文件的情况。

Using CATALINA_BASE:   /home/apache-tomcat-7.0.61
Using CATALINA_HOME:   /home/apache-tomcat-7.0.61
Using CATALINA_TMPDIR: /home/apache-tomcat-7.0.61/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /home/apache-tomcat-7.0.61/bin/bootstrap.jar:/home/apache-tomcat-7.0.61/bin/tomcat-juli.jar
Tomcat started.



ip记错则会

An error occurred.

Sorry, the page you are looking for is currently unavailable.
Please try again later.

If you are the system administrator of this resource then you should check the error log for details.

nginx


7.vi /etc/hosts输入虚拟机ip


猜你喜欢

转载自blog.csdn.net/qq_35904625/article/details/80304257