-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhadoop.py
More file actions
89 lines (70 loc) · 2.43 KB
/
hadoop.py
File metadata and controls
89 lines (70 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
a = input("Configure Namenode or Datanode: ")
print(a)
if a == "Namenode":
ip = os.system("ifconfig enp0s3")
print("IP of namenode : {}".format(ip))
os.system("rm /etc/hadoop/hdfs-site.xml;rm /etc/hadoop/core-site.xml")
dir = input("Enter directory name with path: ")
os.system("mkdir {}".format(dir))
NN_IP = input("Enter Namenode IP : ")
datafile=open("/etc/hadoop/hdfs-site.xml", 'w')
datafile.write(f'''<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file.-->
<configuration>
<property>
<name>dfs.name.dir</name>
<value>{dir}</value>
</property>
</configuration>''')
datafile1=open("/etc/hadoop/core-site.xml", 'w')
datafile1.write(f'''<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file.-->
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://{NN_IP}:9001</value>
</property>
</configuration>''')
os.system("systemctl stop firewalld")
os.system("systemctl disable firewalld")
os.system("hadoop namenode -format")
os.system("hadoop-daemon.sh start namenode;jps")
os.system("tput setaf 6")
print("\n\n--------Namenode Started---------")
os.system("tput setaf 3")
elif a == "Datanode":
NN_IP = input("Enter Namenode IP")
os.system("rm /etc/hadoop/hdfs-site.xml;rm /etc/hadoop/core-site.xml")
datadir = input("Enter directory name with path: ")
os.system("mkdir {}".format(datadir))
datafile=open("/etc/hadoop/hdfs-site.xml", 'w')
datafile.write(f'''<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file.-->
<configuration>
<property>
<name>dfs.data.dir</name>
<value>{datadir}</value>
</property>
</configuration>''')
datafile1=open("/etc/hadoop/core-site.xml", 'w')
datafile1.write(f'''<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file.-->
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://{NN_IP}:9001</value>
</property>
</configuration>''')
os.system("systemctl stop firewalld")
os.system("systemctl disable firewalld")
os.system("rm -rf {}".format(datadir))
os.system("mkdir {}".format(datadir))
os.system("hadoop-daemon.sh start datanode;jps")
print("\n\n--------Datanode Started---------")
else:
print("Tata Bye Bye")