Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
6c599e01
Commit
6c599e01
authored
Feb 29, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #101 from jumpserver/bug_fix_yu
install.py安装兼容多个平台
parents
4f979870
50e82c5b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
18 deletions
+53
-18
install.py
install/install.py
+46
-12
next.py
install/next.py
+6
-5
ansible_api.py
jperm/ansible_api.py
+1
-1
No files found.
install/install.py
View file @
6c599e01
#!/usr/bin/python
# coding: utf-8
import
subprocess
import
time
import
os
import
sys
...
...
@@ -13,6 +12,7 @@ import string
import
re
import
platform
import
shlex
jms_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
)))
sys
.
path
.
append
(
jms_dir
)
...
...
@@ -23,7 +23,7 @@ def bash(cmd):
run a bash shell command
执行bash命令
"""
return
s
ubprocess
.
call
(
cmd
,
shell
=
True
)
return
s
hlex
.
os
.
system
(
cmd
)
def
valid_ip
(
ip
):
...
...
@@ -81,17 +81,33 @@ class PreSetup(object):
self
.
key
=
''
.
join
(
random
.
choice
(
string
.
ascii_lowercase
+
string
.
digits
)
\
for
_
in
range
(
16
))
self
.
dist
=
platform
.
dist
()[
0
]
.
lower
()
self
.
version
=
platform
.
dist
()[
1
]
@property
def
_is_redhat
(
self
):
if
self
.
dist
==
"centos"
or
self
.
dist
==
"redhat"
:
if
self
.
dist
==
"centos"
or
self
.
dist
==
"redhat"
or
self
.
dist
==
"fedora"
:
return
True
@property
def
_is_centos7
(
self
):
if
self
.
dist
==
"centos"
and
self
.
version
.
startswith
(
"7"
):
return
True
@property
def
_is_fedora_new
(
self
):
if
self
.
dist
==
"fedora"
and
int
(
self
.
version
)
>=
20
:
return
True
@property
def
_is_ubuntu
(
self
):
if
self
.
dist
==
"ubuntu"
:
if
self
.
dist
==
"ubuntu"
or
self
.
dist
==
"debian"
:
return
True
def
check_platform
(
self
):
if
not
(
self
.
_is_redhat
or
self
.
_is_ubuntu
):
print
(
u"支持的平台: CentOS, RedHat, Fedora, Debian, Ubuntu, 暂不支持其他平台安装."
)
exit
()
def
write_conf
(
self
,
conf_file
=
os
.
path
.
join
(
jms_dir
,
'jumpserver.conf'
)):
color_print
(
'开始写入配置文件'
,
'green'
)
conf
=
ConfigParser
.
ConfigParser
()
...
...
@@ -116,6 +132,11 @@ class PreSetup(object):
color_print
(
'开始安装设置mysql (请手动设置mysql安全)'
,
'green'
)
color_print
(
'默认用户名:
%
s 默认密码:
%
s'
%
(
self
.
db_user
,
self
.
db_pass
),
'green'
)
if
self
.
_is_redhat
:
if
self
.
_is_centos7
or
self
.
_is_fedora_new
:
bash
(
'yum -y install mariadb-server mariadb-devel'
)
bash
(
'systemctl enable mariadb.service'
)
bash
(
'systemctl start mariadb.service'
)
else
:
bash
(
'yum -y install mysql-server'
)
bash
(
'service mysqld start'
)
bash
(
'chkconfig mysqld on'
)
...
...
@@ -125,9 +146,11 @@ class PreSetup(object):
self
.
db_host
,
self
.
db_pass
))
if
self
.
_is_ubuntu
:
bash
(
'echo mysql-server mysql-server/root_password select '' | debconf-set-selections'
)
bash
(
'echo mysql-server mysql-server/root_password_again select '' | debconf-set-selections'
)
bash
(
'apt-get -y install mysql-server'
)
cmd1
=
"echo mysql-server mysql-server/root_password select '' | debconf-set-selections"
cmd2
=
"echo mysql-server mysql-server/root_password_again select '' | debconf-set-selections"
cmd3
=
"apt-get -y install mysql-server"
bash
(
'
%
s;
%
s;
%
s'
%
(
cmd1
,
cmd2
,
cmd3
))
bash
(
'service mysql start'
)
bash
(
'mysql -e "create database
%
s default charset=utf8"'
%
self
.
db
)
bash
(
'mysql -e "grant all on
%
s.* to
\'
%
s
\'
@
\'
%
s
\'
identified by
\'
%
s
\'
"'
%
(
self
.
db
,
self
.
db_user
,
...
...
@@ -137,12 +160,22 @@ class PreSetup(object):
def
_set_env
(
self
):
color_print
(
'开始关闭防火墙和selinux'
,
'green'
)
if
self
.
_is_redhat
:
os
.
system
(
"export LANG='en_US.UTF-8' && sed -i 's/LANG=.*/LANG=en_US.UTF-8/g' /etc/sysconfig/i18n"
)
os
.
system
(
"export LANG='en_US.UTF-8'"
)
if
self
.
_is_centos7
or
self
.
_is_fedora_new
:
cmd1
=
"systemctl status firewalld 2> /dev/null 1> /dev/null"
cmd2
=
"systemctl stop firewalld"
cmd3
=
"systemctl disable firewalld"
bash
(
'
%
s &&
%
s &&
%
s'
%
(
cmd1
,
cmd2
,
cmd3
))
bash
(
'localectl set-locale LANG=en_US.UTF-8'
)
bash
(
'which setenforce 2> /dev/null 1> /dev/null && setenforce 0'
)
else
:
bash
(
"sed -i 's/LANG=.*/LANG=en_US.UTF-8/g' /etc/sysconfig/i18n"
)
bash
(
'service iptables stop && chkconfig iptables off && setenforce 0'
)
if
self
.
_is_ubuntu
:
os
.
system
(
"export LANG='en_US.UTF-8'"
)
bash
(
"iptables -F"
)
bash
(
'which se
linux
&& setenforce 0'
)
bash
(
"
which iptables &&
iptables -F"
)
bash
(
'which se
tenforce
&& setenforce 0'
)
def
_test_db_conn
(
self
):
bash
(
"pip install mysql-python"
)
...
...
@@ -181,9 +214,9 @@ class PreSetup(object):
def
_depend_rpm
(
self
):
color_print
(
'开始安装依赖包'
,
'green'
)
if
self
.
_is_redhat
:
bash
(
'yum -y install git python-pip mysql-devel
gcc automake autoconf python-devel vim sshpass
'
)
bash
(
'yum -y install git python-pip mysql-devel
rpm-build gcc automake autoconf python-devel vim sshpass lrzsz readline-devel
'
)
if
self
.
_is_ubuntu
:
bash
(
"apt-get -y
install git python-pip gcc automake autoconf vim sshpass libmysqld-dev python-all
-dev"
)
bash
(
"apt-get -y
--force-yes install git python-pip gcc automake autoconf vim sshpass libmysqld-dev python-all-dev lrzsz libreadline
-dev"
)
@staticmethod
...
...
@@ -239,6 +272,7 @@ class PreSetup(object):
def
start
(
self
):
color_print
(
'请务必先查看wiki https://github.com/jumpserver/jumpserver/wiki'
)
time
.
sleep
(
3
)
self
.
check_platform
()
self
.
_rpm_repo
()
self
.
_depend_rpm
()
self
.
_require_pip
()
...
...
install/next.py
View file @
6c599e01
...
...
@@ -5,7 +5,7 @@ import sys
import
os
import
django
from
django.core.management
import
execute_from_command_line
import
sh
util
import
sh
lex
import
urllib
import
socket
import
subprocess
...
...
@@ -77,8 +77,8 @@ class Setup(object):
user
.
delete
()
db_add_user
(
username
=
self
.
admin_user
,
password
=
self
.
admin_pass
,
role
=
'SU'
,
name
=
'admin'
,
groups
=
''
,
admin_groups
=
''
,
email
=
'admin@jumpserver.org'
,
uuid
=
'MayBeYouAreTheFirstUser'
,
is_active
=
True
)
cmd
=
'
useradd
%
s'
%
self
.
admin_user
s
ubprocess
.
call
(
cmd
,
shell
=
True
)
cmd
=
'
id
%
s 2> /dev/null 1> /dev/null || useradd
%
s'
%
(
self
.
admin_user
,
self
.
admin_user
)
s
hlex
.
os
.
system
(
cmd
)
@staticmethod
def
_chmod_file
():
...
...
@@ -93,12 +93,13 @@ class Setup(object):
@staticmethod
def
_run_service
():
os
.
system
(
'sh
%
s start'
%
os
.
path
.
join
(
jms_dir
,
'service.sh'
))
cmd
=
'bash
%
s start'
%
os
.
path
.
join
(
jms_dir
,
'service.sh'
)
shlex
.
os
.
system
(
cmd
)
print
color_print
(
'安装成功,请访问web, 祝你使用愉快。
\n
请访问 https://github.com/jumpserver/jumpserver/wiki 查看文档'
,
'green'
)
def
start
(
self
):
print
"开始安装Jumpserver
, 要求环境为 CentOS 6.5 x86_64
"
print
"开始安装Jumpserver
...
"
self
.
_pull
()
self
.
_sync_db
()
self
.
_input_admin
()
...
...
jperm/ansible_api.py
View file @
6c599e01
...
...
@@ -125,7 +125,7 @@ class MyRunner(MyInventory):
self
.
results_raw
=
{}
def
run
(
self
,
module_name
=
'shell'
,
module_args
=
''
,
timeout
=
10
,
forks
=
10
,
pattern
=
'*'
,
become
=
False
,
become_method
=
'sudo'
,
become_user
=
'root'
,
become_pass
=
''
,
transport
=
'
smart
'
):
become
=
False
,
become_method
=
'sudo'
,
become_user
=
'root'
,
become_pass
=
''
,
transport
=
'
paramiko
'
):
"""
run module from andible ad-hoc.
module_name: ansible module_name
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment