您的位置:首页 > 运维架构 > Tomcat

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

2017-04-16 18:51 1206 查看
今天,又一次弄我的个人云主机的环境。准备运营自己用Java写的个人官网等站点。
服务器环境:阿里云CentOS 6.4位包含以下脚本在内的绝大部分命令和脚本,都是我亲自运行过,靠谱的。

完整的“运营运维”经验,请參考我的CSDN博客-运营运维 分类:http://blog.csdn.net/FansUnion/article/category/1714547
1.mysql1.1 安装mysqlyum install mysql-server
1.2 启动mysql,服务名字是“mysqld”而不是“mysql”service mysqld startservice mysqld stop
參考:http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html
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无法登录。
參考:http://www.2cto.com/database/201205/130093.html
#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 。
參考:http://www.cnblogs.com/top5/archive/2011/11/14/2247991.html
---------------------------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 testdatabases and anonymous user created by default. This isstrongly 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.plcd /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_31export CLASSPATH=$JAVA_HOME/libexport 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 definedAt 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/。都是源代码包,没有二进制安装包 安装过程 wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm yum install nginx-release... yum install nginx 參考:http://blog.csdn.net/fansunion/article/details/40651257 配置Nginx:核心部分 server { listen 80; server_name fansunion.cn www.fansunion.cn; #将www.fansunon.cn永久重定向到fansunion.cn,在创业做ITFriend站点的过程中发现,带www和不带www的Cookie可能不是同一个 #不要www是为了简化输入,让url更短更easy输入和记忆 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处理动态的请求。 我这么做,是简化配置,方便维护。

http://www.nginx.cn/680.html 5.參考资料 Linux环境运维等很多其它相关资料,请參考我的CSDN博客
Ubuntu10.04下配置和使用JDK-Mysql-Tomcat-SVN http://blog.csdn.net/fansunion/article/details/8532104 Web系统自己主动化部署脚本 http://blog.csdn.net/fansunion/article/details/40617419 Ubuntu下SVN服务器安装和配置 http://blog.csdn.net/fansunion/article/details/16917259 Apache配置虚拟主机 http://blog.csdn.net/fansunion/article/details/9428895 立博客站点FansUnion.cn运营2年的经验和教训以及未来规划 http://blog.csdn.net/fansunion/article/details/40635731 我的个人官方站点( http://FansUnion.cn/ )正在逐步完好中,欢迎訪问,有建议和问题。咱们能够交流下~多谢
小雷FansUnion-博学的互联网技术工作者 2014年11月1日 湖北武汉
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: