Beispiel #1
0
        static string[] GetServiceIP() //서버의 ip를 가져온다.
        {
            TerminalCommand.Command($"sudo ifconfig > /etc/setting.txt ; exit");
            Thread.Sleep(500);
            string[] settingText = File.ReadAllLines(@"/etc/setting.txt");

            List <string> ipListTmp = new List <string>();

            for (int i = 0; i < settingText.Length; i++)
            {
                Console.Clear();
                if (settingText[i].Contains("inet") && settingText[i].Contains("netmask"))  //모든 ip를 잘라낸다.
                {
                    string ip = StrCut.StrChange(settingText[i], "inet", "netmask", true);
                    ipListTmp.Add(ip);
                }
            }

            string[] ipList = new string[ipListTmp.Count];
            for (short i = 0; i < ipListTmp.Count; i++)
            {
                ipList[i] = ipListTmp[i];
            }
            return(ipList); //모든 ip 반환
        }
Beispiel #2
0
        public void ELK()
        {
            string[] checkList = new string[] { "elasticsearch", "logstash", "filebeat", "kibana" };

            for (byte i = 0; i < checkList.Length; i++) //각 모든 설치파일을 동작시킨다.
            {
                bool breakFlag = true;
                TerminalCommand.Command($"sudo  service {checkList[i]} start && exit;");

                Thread.Sleep(5000); //실행후  대기 너무 빠르게 실행되면 문제가 될 가능성이있다.
                do
                {
                    TerminalCommand.Command($"sudo  service {checkList[i]} status > /etc/setting{checkList[i]}.txt ; exit");
                    string[] settingArr = File.ReadAllLines(@$ "/etc/setting{checkList[i]}.txt");


                    for (int ii = 0; ii < settingArr.Length; ii++)
                    {
                        if (settingArr[ii].Contains("Active: active (running)")) //실행중이라면 종료해라
                        {
                            Console.WriteLine($"{checkList[i]} 실행 확인!");
                            breakFlag = false;
                            break;
                        }
                        else if (settingArr[ii].Contains("Active:"))
                        {
                            breakFlag = true;
                            Console.WriteLine($"{checkList[i]} 실행 대기중...");
                            Thread.Sleep(5000); //실행후  대기
                            break;
                        }
                    }
                } while (breakFlag);
            }
        }
Beispiel #3
0
        private static void Setting_Elasticsearch_Xpack()
        {
            bool check = true; //세팅이 2번 동작하지않도록 확인 작업

            string[] elasticsearchOrigin = File.ReadAllLines(@"/etc/elasticsearch/elasticsearch.yml");
            for (int i = elasticsearchOrigin.Length - 10; i < elasticsearchOrigin.Length; i++)
            {
                if (elasticsearchOrigin[i].Equals("xpack.security.enabled: true") || elasticsearchOrigin[i].Equals("xpack.security.transport.ssl.enabled: true"))
                {
                    check = false; //세팅값이있다면 다시 세팅하지마라
                }
            }
            if (check) //세팅한적이없다면 세팅작업
            {
                using (StreamWriter outputFile = new StreamWriter(@"/etc/elasticsearch/elasticsearch.yml", true))
                {
                    outputFile.WriteLine("xpack.security.enabled: true\nxpack.security.transport.ssl.enabled: true");
                }
                flag = false;
                TerminalCommand.Command($"gnome-terminal -- bash -ic 'cd $HOME; " +
                                        $"service elasticsearch restart &&" +
                                        $"service kibana restart &&" +
                                        $"exit;" +
                                        $"bash'");
            }

            bool settingFlag = false;

            TerminalCommand.Command($"gnome-terminal -- bash -ic 'cd $HOME; " +
                                    $"echo 1 > /etc/setting.txt && chmod 777 /etc/setting.txt &&" +
                                    $"exit;bash'");

            do //패스워드 명령어는 ELK가 실행되고 어느정도 시간차가 필요하다. 무한루프로 게속 시도한다.
            {
                TerminalCommand.Command($"sudo /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive -N > /etc/setting.txt ; exit");
                Thread.Sleep(1000);
                string[] settingArr = File.ReadAllLines(@"/etc/setting.txt");
                Console.WriteLine(settingArr.Length);
                for (int i = 0; i < settingArr.Length; i++)
                {
                    Console.WriteLine(settingArr[i]);
                    if (settingArr[i].Contains("passwords for")) //패스워드 세팅이 나온상황이다. 아닌경우 elasticsearch running?
                    {
                        Console.WriteLine("ok");
                        settingFlag = true; //세팅값이있다면 다시 세팅하지마라
                        break;
                    }
                }
                Task.Delay(3000);
                Console.WriteLine("설정 재시도중");
            } while (settingFlag != true);

            if (settingFlag == true)
            {
                TerminalCommand.Command($"gnome-terminal -- bash -ic 'cd $HOME; " +
                                        $"sudo /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive;" +
                                        $"bash'");
            }
        }
Beispiel #4
0
        static void ELK_setup(string version)
        {
            string path = System.IO.Directory.GetCurrentDirectory();

            TerminalCommand.Command($"gnome-terminal -- bash -ic ' " +
                                    $"apt-get install -y openjdk-8-jdk &&" +
                                    $"sudo dpkg -i elasticsearch-{version}-amd64.deb && " +
                                    $"sudo dpkg -i logstash-{version}.deb &&" +
                                    $"sudo dpkg -i kibana-{version}-amd64.deb &&" +
                                    $"sudo dpkg -i filebeat-{version}-amd64.deb && exit;" +
                                    $"bash'");
        }