Skip to content

Commit d15d2c4

Browse files
committed
✄ 添加[写给java开发的运维笔记]中级篇
1 parent 6b6e308 commit d15d2c4

5 files changed

Lines changed: 297 additions & 6 deletions

File tree

learn_server/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33

44
对于Java开发人员,掌握基本的运维技能是必须的,如果你还不熟悉Linux环境,可以看[这个](https://github.com/judasn/Linux-Tutorial)教程。
55

6+
## 初级篇
7+
68
1. [在虚拟机里安装centos6](virtual-machine-install-centos6.md)
79
2. [初始化操作系统](init-os.md)
810
3. [安装jdk环境](install-jdk.md)
911
4. [安装tomcat](install-tomcat.md)
1012
5. [安装mysql及配置](install-mysql.md)
1113
6. [安装nginx](install-nginx.md)
12-
7. [配置tomcat+nginx反向代理](config-nginx-proxy.md)
13-
8. [优化nginx配置](optimization-nginx.md)
14+
15+
## 中级篇
16+
17+
1. [配置tomcat+nginx反向代理](config-nginx-proxy.md)
18+
2. [优化tomcat配置](optimization-tomcat.md)
19+
3. [配置多个tomcat](config-more-tomcat.md)
20+
4. [优化nginx配置](optimization-nginx.md)
21+
5. [优化mysql配置](optimization-mysql.md)

learn_server/init-os.md

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,122 @@
1-
# 初始化操作系统
1+
# 初始化操作系统
2+
3+
Ok,我们安装好了CentOS系统,可以使用SSH工具连接上去进行尝试了,我推荐使用 [XShell] 这款工具,支持中文,还有一些主题使用。
4+
5+
现在我们还不知道CentOS的IP是无法连接的,所以先在虚拟机中启动CentOS。
6+
7+
![](https://ooo.0o0.ooo/2016/09/09/57d225f429a16.png)
8+
9+
这里账户输入 `root` 密码是你在安装的时候设置的。
10+
11+
## 网络配置
12+
13+
这时候我们键入 `ifconfig` 查看ip
14+
15+
```bash
16+
[root@localhost ~]# ifconfig
17+
18+
lo Link encap:Local Loopback
19+
inet addr:127.0.0.1 Mask:255.0.0.0
20+
inet6 addr: ::1/128 Scope:Host
21+
UP LOOPBACK RUNNING MTU:65536 Metric:1
22+
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
23+
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
24+
collisions:0 txqueuelen:0
25+
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
26+
```
27+
28+
发现还没有,我们需要设置一下网卡配置。
29+
30+
```bash
31+
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
32+
```
33+
34+
使用 `vi` 命令编辑第一块网卡的配置
35+
36+
```bash
37+
DEVICE=eth0
38+
HWADDR=00:0C:29:50:58:BE
39+
TYPE=Ethernet
40+
UUID=58f93b51-314d-49bb-9db2-036bf91161fb
41+
ONBOOT=no
42+
NM_CONTROLLED=yes
43+
BOOTPROTO=dhcp
44+
```
45+
46+
只需要将 `ONBOOT` 修改为 `yes` ,然后保存。
47+
48+
```bash
49+
[root@localhost ~]# service network restart
50+
Shutting down interface eth0: [ OK ]
51+
Shutting down loopback interface: [ OK ]
52+
Bringing up loopback interface: [ OK ]
53+
Bringing up interface eth0:
54+
Determining IP information for eth0... done.
55+
[ OK ]
56+
```
57+
58+
这时候我们再查看一下ip
59+
60+
```bash
61+
[root@localhost ~]# ifconfig
62+
eth0 Link encap:Ethernet HWaddr 00:0C:29:50:58:BE
63+
inet addr:192.168.100.128 Bcast:192.168.100.255 Mask:255.255.255.0
64+
inet6 addr: fe80::20c:29ff:fe50:58be/64 Scope:Link
65+
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
66+
RX packets:302 errors:0 dropped:0 overruns:0 frame:0
67+
TX packets:189 errors:0 dropped:0 overruns:0 carrier:0
68+
collisions:0 txqueuelen:1000
69+
RX bytes:33591 (32.8 KiB) TX bytes:29591 (28.8 KiB)
70+
71+
lo Link encap:Local Loopback
72+
inet addr:127.0.0.1 Mask:255.0.0.0
73+
inet6 addr: ::1/128 Scope:Host
74+
UP LOOPBACK RUNNING MTU:65536 Metric:1
75+
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
76+
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
77+
collisions:0 txqueuelen:0
78+
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
79+
```
80+
81+
网卡的配置已经被应用到了,我们CentOS的IP是 `192.168.100.128` 你的可能和我不一样,那这个192.168.100开头的网段是在哪里设置的呢?
82+
83+
![](https://ooo.0o0.ooo/2016/09/09/57d2293d28fe5.png)
84+
85+
点击虚拟网络编辑器
86+
87+
![](https://ooo.0o0.ooo/2016/09/09/57d229a2311f4.png)
88+
89+
如果你在执行 `service network restart` 的时候失败可以在这里修改一个网段试试。
90+
91+
此时你已经可以使用SSH工具连接到你的CenOS主机了。
92+
93+
关于更详细的网络设置大家可以参考这2篇文章:
94+
95+
- [虚拟机下CentOS 6.5配置IP地址的三种方法](http://www.centoscn.com/CentOS/config/2014/1112/4112.html)
96+
- [Vmware安装Centos NAT方式设置静态IP](http://www.centoscn.com/CentosBug/osbug/2015/1224/6568.html)
97+
98+
99+
## yum源设置
100+
101+
先安装 `wget` 工具,我们安装的操作系统mini版的,默认没有wget命令,执行以下命令:
102+
103+
```bash
104+
yum install -y wget
105+
```
106+
107+
然后设置yum源,我选择的是网易的源,你也可以设置阿里的或者其他。
108+
109+
```bash
110+
cd /etc/yum.repos.d
111+
mv CentOS-Base.repo bak-CentOS-Base.repo
112+
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
113+
yum clean all
114+
yum makecache
115+
```
116+
117+
安全性的配置在这里先不讲解,我们先用 `root`账户来操作。
118+
119+
## links
120+
* [目录](<README.md>)
121+
* 上一节: [在虚拟机里安装centos6](<virtual-machine-install-centos6.md>)
122+
* 下一节: [安装jdk环境](<install-jdk.md>)

learn_server/install-jdk.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,67 @@
1-
# 安装jdk环境
1+
# 安装jdk环境
2+
3+
服务器上如果不需要编码实际应该不安装JDK只安装JRE,我们考虑到以后可能安装其他软件就直接装JDK了。
4+
5+
## 下载JDK
6+
7+
[下载jdk](http://stackoverflow.com/questions/10268583/downloading-java-jdk-on-linux-via-wget-is-shown-license-page-instead)
8+
9+
上面的连接是stackoverflow有开发者写的不使用cookie下载jdk和jre的命令。
10+
11+
```bash
12+
[root@localhost ~]# wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u102-b14/jdk-8u102-linux-x64.tar.gz
13+
--2016-09-09 19:57:01-- http://download.oracle.com/otn-pub/java/jdk/8u102-b14/jdk-8u102-linux-x64.tar.gz
14+
Resolving download.oracle.com... 23.4.240.57, 23.4.240.59
15+
Connecting to download.oracle.com|23.4.240.57|:80... connected.
16+
HTTP request sent, awaiting response... 302 Found
17+
Location: http://120.52.72.24:80/download.oracle.com/c3pr90ntc0td/otn-pub/java/jdk/8u102-b14/jdk-8u102-linux-x64.tar.gz [following]
18+
--2016-09-09 19:57:01-- http://120.52.72.24/download.oracle.com/c3pr90ntc0td/otn-pub/java/jdk/8u102-b14/jdk-8u102-linux-x64.tar.gz
19+
Connecting to 120.52.72.24:80... connected.
20+
HTTP request sent, awaiting response... 200 OK
21+
Length: 181435897 (173M) [application/x-gzip]
22+
Saving to: “jdk-8u102-linux-x64.tar.gz”
23+
24+
100%[==================================================================================================================================>] 181,435,897 2.07M/s in 85s
25+
26+
2016-09-09 19:58:26 (2.04 MB/s) - “jdk-8u102-linux-x64.tar.gz” saved [181435897/181435897]
27+
```
28+
29+
## 解压
30+
31+
```bash
32+
[root@localhost ~]# tar -zxvf jdk-8u102-linux-x64.tar.gz
33+
[root@localhost ~]# mkdir /usr/local/java
34+
[root@localhost ~]# mv jdk1.8.0_102/ /usr/local/java/
35+
```
36+
37+
## 配置环境变量
38+
39+
```bash
40+
[root@localhost ~]# vim /etc/profile
41+
```
42+
43+
在最后一行添加
44+
45+
```bash
46+
# java
47+
export JAVA_HOME=/usr/local/java/jdk1.8.0_102
48+
export JRE_HOME=/usr/local/java/jdk1.8.0_102/jre
49+
export CLASSPATH=.:$JRE_HOME/lib/dt.jar:$JRE_HOME/lib/tools.jar
50+
export PATH=$JRE_HOME/bin:$JRE_HOME/bin:$PATH
51+
```
52+
53+
## 生效
54+
55+
```bash
56+
[root@localhost ~]# source /etc/profile
57+
[root@localhost ~]# java -version
58+
java version "1.8.0_102"
59+
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
60+
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
61+
```
62+
这里我安装的是最新版的JDK。
63+
64+
## links
65+
* [目录](<README.md>)
66+
* 上一节: [初始化操作系统](<init-os.md>)
67+
* 下一节: [安装tomcat](<install-tomcat.md>)

learn_server/install-tomcat.md

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,92 @@
1-
# 安装tomcat
1+
# 安装tomcat
2+
3+
上一章节我们安装了JDK的环境,Tomcat运行的前提是要有JDK环境。
4+
5+
## 下载Tomcat
6+
7+
```bash
8+
[root@localhost ~]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.5/bin/apache-tomcat-8.5.5.tar.gz
9+
[root@localhost ~]# tar -zxvf apache-tomcat-8.5.5.tar.gz
10+
[root@localhost ~]# mv apache-tomcat-8.5.5 /usr/local/tomcat8
11+
```
12+
13+
## 启动tomcat
14+
15+
```bash
16+
[root@localhost ~]# cd /usr/local/tomcat8/bin/
17+
[root@localhost bin]# ./startup.sh
18+
Using CATALINA_BASE: /usr/local/tomcat8
19+
Using CATALINA_HOME: /usr/local/tomcat8
20+
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
21+
Using JRE_HOME: /usr/local/java/jdk1.8.0_102/jre
22+
Using CLASSPATH: /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
23+
Tomcat started.
24+
```
25+
26+
现在打开 [http://192.168.100.128:8080](http://192.168.100.128:8080) 应该就可以看到Tomcat的汤姆猫页面。
27+
而事实是你看到这个:
28+
29+
![](https://ooo.0o0.ooo/2016/09/09/57d23ea8c353e.png)
30+
31+
哦草。。。为什么,机智的同学已经想到了,防火墙啊。对我们没有对防火墙进行任何配置,实际上8080端口是不对外开放的,
32+
那么如何解决呢?
33+
34+
- 关闭防火墙
35+
- 开放8080端口
36+
37+
## 配置防火墙
38+
39+
在CentOS上关闭防火墙是非常简单的
40+
41+
```bash
42+
[root@localhost bin]# service iptables stop
43+
iptables: Setting chains to policy ACCEPT: filter [ OK ]
44+
iptables: Flushing firewall rules: [ OK ]
45+
iptables: Unloading modules: [ OK ]
46+
```
47+
48+
这时候你再访问 [http://192.168.100.128:8080](http://192.168.100.128:8080) 就可以看到
49+
50+
![](https://ooo.0o0.ooo/2016/09/09/57d23f752bfce.png)
51+
52+
当然这种方式是简单粗暴的,我们在真实服务器上不可能这么做,怎么做呢?
53+
54+
```bash
55+
[root@localhost bin]# vim /etc/sysconfig/iptables
56+
```
57+
58+
我们看到 `iptables` 的默认配置是这样的:
59+
60+
```bash
61+
# Firewall configuration written by system-config-firewall
62+
# Manual customization of this file is not recommended.
63+
*filter
64+
:INPUT ACCEPT [0:0]
65+
:FORWARD ACCEPT [0:0]
66+
:OUTPUT ACCEPT [0:0]
67+
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
68+
-A INPUT -p icmp -j ACCEPT
69+
-A INPUT -i lo -j ACCEPT
70+
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
71+
-A INPUT -j REJECT --reject-with icmp-host-prohibited
72+
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
73+
COMMIT
74+
```
75+
76+
只需要添加一行和 `22` 端口一样的配置:
77+
78+
```bash
79+
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
80+
```
81+
82+
这样既把8080的TCP端口对外开放了,然后重启防火墙
83+
84+
```bash
85+
[root@localhost bin]# service iptables restart
86+
iptables: Setting chains to policy ACCEPT: filter [ OK ]
87+
iptables: Flushing firewall rules: [ OK ]
88+
iptables: Unloading modules: [ OK ]
89+
iptables: Applying firewall rules: [ OK ]
90+
```
91+
92+
可以达到同样的效果。

learn_server/virtual-machine-install-centos6.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,9 @@
104104

105105
![](https://ooo.0o0.ooo/2016/09/09/57d21e687d0de.png)
106106

107-
看到这个界面你的CentOS就安装完成了,可以进行下一关了,上车!
107+
看到这个界面你的CentOS就安装完成了,点击REBOOT即重启机器。
108+
可以进行下一关了,上车!
109+
110+
## links
111+
* [目录](<README.md>)
112+
* 下一节: [初始化操作系统](<init-os.md>)

0 commit comments

Comments
 (0)