欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Centos初始化java环境

程序员文章站 2022-07-14 10:49:36
...
1.上传
jdk jdk-7u65-linux-x64.tar
mysql mysql-5.5.15.tar
tomcat apache-tomcat-7.0.54.tar
nginx nginx-1.6.0.tar
tar包 到 /usr/local/src
2.安装jdk
cd /usr/local/src
tar xzf jdk-7u65-linux-x64.tar.gz -C /usr/local/
ln -s /usr/local/jdk1.7.0_65/ /usr/local/jdk
#set jdk
cat >> /etc/profile << EOF
export JAVA_HOME=/usr/local/jdk
export JRE_HOME=\${JAVA_HOME}/jre
export CLASSPATH=.:\${JAVA_HOME}/lib:\${JRE_HOME}/lib
export PATH=\${JAVA_HOME}/bin:\$PATH
EOF
#
ln -s /usr/local/jdk/bin/java /usr/bin/

source /etc/profile
java -version

3.安装tomcat

cd /usr/local/src
tar xzf apache-tomcat-7.0.54.tar.gz -C /usr/local/
ln -s /usr/local/apache-tomcat-7.0.54/ /usr/local/tomcat

cd tomcat/bin
vim catalina.sh
CATALINA_HOME=/usr/local/tomcat/

配置 manager 登录用户
cd ./conf
vi tomcat-user.xml

<role rolename="tomcat"/>
<user username="test" password="test" roles="tomcat"/>



配置远程debug

cd ./bin
vi catalina.sh

CATALINA_OPTS="-Xdebug  -Xrunjdwp:transport=dt_socket,address=7070,server=y,suspend=n"(不要换行,要在同一行)

./startup.sh && tail -f ../logs/catalina.out

4.安装ngixn
yum -y install gcc automake autoconf libtool make
yum install gcc gcc-c++

cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.20.tar.gz
tar -zxvf pcre-8.20.tar.gz
cd pcre-8.20
./configure
make
make install

cd /usr/local/src

wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make install

cd /usr/local/src
wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz
tar -zxvf openssl-1.0.1g.tar.gz

cd /usr/local/src
wget http://nginx.org/download/nginx-1.6.0.tar.gz
tar -zxvf nginx-1.6.0tar.gz
cd nginx-1.6.0

./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.20 \
--with-zlib=/usr/local/src/zlib-1.2.8 \
--with-openssl=/usr/local/src/openssl-1.0.1g

##[install_docs] Error 1  http://mauersu.iteye.com/admin/blogs/2237300

make
make install

##nginx.conf
>>>>>>>


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
#gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
#gzip_vary off;
gzip_disable "MSIE [1-6]\.";

    server {
        listen       80;
        server_name  localhost;

location / {
index index.php;
proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}


location ~ .*\.(js|css)?$
{
#proxy_pass http://webserver;
proxy_pass http://localhost:8080;
access_log  off;
expires      24h;
}


location ~ .*\.(gif|jpg|jpeg|png|bmp|flv|ico|swf)$
{
proxy_pass http://localhost:8080;
#if (!-f $request_filename) {
#proxy_pass http://webserver;
#}
access_log off;
expires      24h;
}

location ~ \.php$ {
index index.php;
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}

# redirect server error pages to the static page /50x.html
error_page   500 502 503 504  /50x.html;
error_page   404              /404.html;

    }

}
>>>>>>

5.安装mysql

yum install gcc gcc-c++
yum install ncurses-devel

mkdir -p /tmp
cd /tmp
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.15.tar.gz
wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz
wget http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz

cd /tmp
tar zxvf cmake-2.8.4.tar.gz
cd cmake-2.8.4
./bootstrap
make
make install

cd /tmp
tar zxvf bison-2.5.tar.gz
cd bison-2.5
./configure
make

#./stdio.h:1012:1: error: 'gets' undeclared here (not in a function)
#解决:sed -i '/gets is a security hole/d' lib/stdio.in.h
make install

/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
cd /tmp
tar xvf mysql-5.5.15.tar.gz
cd mysql-5.5.15/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/var/mysql/data \
-DMYSQL_USER=mysql
make
make install

chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
ln -s /usr/local/mysql/lib/libmysqlclient.so.16 /usr/lib/libmysqlclient.so.16
mkdir -p /var/mysql/
mkdir -p /var/mysql/data/
mkdir -p /var/mysql/log/
chown -R mysql:mysql /var/mysql/
cd support-files/
cp my-large.cnf /etc/my.cnf
cp mysql.server /etc/rc.d/init.d/mysqld


/usr/local/mysql/scripts/mysql_install_db \
--defaults-file=/etc/my.cnf  \
--basedir=/usr/local/mysql \
--datadir=/var/mysql/data \
--user=mysql

   chmod +x /etc/init.d/mysqld

vi /etc/init.d/mysqld(编辑此文件,查找并修改以下变量内容:)
basedir=/usr/local/mysql
datadir=/var/mysql/data

chkconfig --add mysqld
chkconfig --level 345 mysqld on

启动服务:
chkconfig --add mysqld
chkconfig --level 345 mysqld on

启动服务:
service mysqld start
设置密码:
/usr/local/mysql/bin/mysqladmin password [new-password]

#新安装mysql 第三方工具连接不上问题

#报的错误为
#ERROR 1130: Host ’192.168.5.3’ is not allowed to connect to this MySQL server

#登上服务器
mysql -h localhost -u root -p
Enter password: ***
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.43-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
www.2cto.com 
mysql> grant all privileges on *.* to root@'%' identified by '123' with grant
-> option;

mysql>FLUSH PRIVILEGES;