现在的位置: 首页 > 综合 > 正文

CentOS下安装和配置MySQL-JDK-Tomcat-Nginx(个人官网环境搭建手册)

2017年01月17日 ⁄ 综合 ⁄ 共 3898字 ⁄ 字号 评论关闭
今天,重新弄我的个人云主机的环境,准备运营自己用Java写的个人官网等网站。
服务器环境:阿里云CentOS 6.4位
包括以下脚本在内的绝大部分命令和脚本,都是我亲自执行过,靠谱的。
完整的“运营运维”经验,请参考我的CSDN博客-运营运维 分类:http://blog.csdn.net/FansUnion/article/category/1714547
1.mysql
1.1 安装mysql
yum install mysql-server
1.2 启动mysql,服务名字是“mysqld”而不是“mysql”
service mysqld start
service mysqld stop
1.3 设置密码,删除匿名用户,是否允许远程登录,删除test数据库,重新加载权限表以确保刚刚的设置生效
/usr/bin/mysql_secure_installation
1.4允许root用户远程连接数据库
 mysql -uroot -p;
 use mysql;
 select host,user,password from user;
 update user set host = '%' where user = 'root';
 
 #如果root用户已经有了"%",会提示下面的错误
 " Duplicate entry '%-root' for key 'PRIMARY'"
 
 
 grant all privileges  on *.* to root@'%' identified by "root";
 flush privileges; 
 
--执行上面的命令时,不知道到怎么把密码给改了,root无法登录。 
#1.5 MySQL 忘记口令的解决办法
如果 MySQL 正在运行,首先杀之: killall -TERM mysqld。 
启动 MySQL :/usr/bin/mysqld_safe --skip-grant-tables & 
就可以不需要密码就进入 MySQL 了。 
然后就是 
>use mysql
>update user set password=password("lw198962") where user="root";
>flush privileges;
重新杀 MySQL ,用正常方法启动 MySQL 。
---------------------------
1.6 安装mysql时,给的提示,非常有帮助
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
#设置密码
/usr/bin/mysqladmin -u root password 'lw198962'
/usr/bin/mysqladmin -u root -h AY1304131823374920ac password 'lw198962'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
2.java
2.1下载解压版JDK7,上传到服务器,然后解压
 untar -xvf jdk7.tar.gz
 unzip jdk7.zip
2.2配置环境变量
export JAVA_HOME=/home/fans/Fans/jdk1.6.0_31
export CLASSPATH=$JAVA_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH
2.3重新载入
source /etc/profile
3.tomcat
3.1下载解压版Tomcat7,上传到服务器,然后解压
参考 解压jdk7
3.2 增加可执行权限
chmod a+x *.sh
提示:不要给.bat文件增加x权限
执行tomcat命令的时候,只有x权限的文件,linux才能自动提示,比如输入 ./start 按Tab 系统自动提示到startup.sh,
如果startup.bat也有权限,需要更详细的输入。
3.3 JDK环境变量
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
可能是还没有配置环境变量,也可能是配置了,还没有生效。
记得执行 source /etc/profile
3.4 启动Tomcat失败怎么办
./startup.sh这种启动方式,错误提示不够明显。
通过 ps -ef|grep tomcat 查看Tomcat是否已经启动。
如果没有,通过 ./catalina.sh run 启动Tomcat,这种方式可以看到完整的启动信息。
Windows环境,也是这样。
这种启动方式不好的地方是,退出当前会话,Tomcat就停止了。
4.Nginx
  下载地址 http://nginx.org/download/,都是源码包,没有二进制安装包
 
 安装过程
 yum install nginx-release...
 yum install nginx
 
 
 配置Nginx:核心部分
 
  server {
        listen 80;
        server_name fansunion.cn www.fansunion.cn;
#将www.fansunon.cn永久重定向到fansunion.cn,在创业做ITFriend网站的过程中发现,带www和不带www的Cookie可能不是同一个
#不要www是为了简化输入,让url更短更容易输入和记忆
        if ($host !=  'fansunion.cn'){
           rewrite ^/(.*)$ http://fansunion.cn/$1 permanent;
        }
        charset utf-8;
        access_log off;
     
        ssi on;
        ssi_silent_errors on;
           
       location / {
           proxy_pass   http://localhost:8080;
       }
    }   
  后台Tomcat监听8080端口,把通过域名“fansunion.cn”过来的所有请求(html、js,静态和动态的)都转发到Tomcat解析。
  
  如果静态资源比较多的情况下,也可以让Nginx处理js、css、image,只让Tomcat处理动态的请求。
  我这么做,是简化配置,方便维护。
  
  
  
5.参考资料
  Linux环境运维等更多相关资料,请参考我的CSDN博客
  Ubuntu10.04下配置和使用JDK-Mysql-Tomcat-SVN http://blog.csdn.net/fansunion/article/details/8532104
  Ubuntu下SVN服务器安装和配置  http://blog.csdn.net/fansunion/article/details/16917259
  立博客网站FansUnion.cn运营2年的经验和教训以及未来规划 http://blog.csdn.net/fansunion/article/details/40635731
  
  
  我的个人官方网站( http://FansUnion.cn/ )正在逐步完善中,欢迎访问,有建议和问题,咱们可以交流下~多谢
  
  
  小雷FansUnion-博学的互联网技术工作者
  2014年11月1日
  湖北武汉

抱歉!评论已关闭.